X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 536D49F9F8F for ; Wed, 24 May 2006 12:03:44 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 89294-07 for ; Wed, 24 May 2006 12:03:34 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from pih-relay05.plus.net (pih-relay05.plus.net [212.159.14.132]) by postgresql.org (Postfix) with ESMTP id 0E9849FA2DB for ; Wed, 24 May 2006 12:03:33 -0300 (ADT) Received: from [213.162.97.75] (helo=mail.metronet.co.uk) by pih-relay05.plus.net with esmtp (Exim) id 1FiutX-0004IH-HC; Wed, 24 May 2006 16:03:31 +0100 Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 23DC873657; Wed, 24 May 2006 16:03:27 +0100 (BST) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id C77C115EA6; Wed, 24 May 2006 16:03:26 +0100 (BST) Message-ID: <447475BE.8050200@archonet.com> Date: Wed, 24 May 2006 16:03:26 +0100 From: Richard Huxton User-Agent: Thunderbird 1.5.0.2 (X11/20060420) MIME-Version: 1.0 To: andi Cc: pgsql-sql@postgresql.org Subject: Re: PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly References: <20060524103549.1E41C5AF071@svr4.postgresql.org> In-Reply-To: <20060524103549.1E41C5AF071@svr4.postgresql.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/185 X-Sequence-Number: 25216 andi wrote: > Dear friends, > > I have table > > MD_CUSTOMER > > MD_CUSTOMERIDPK integer primary key > NAME varchar OK - two columns. > But my primary key is not in correct order like > > MD_CUSTOMER > > MD_CUSTOMERIDPK NAME > > 10 > ANDI > > 33 > TESTER > > 100 KKK Not sure what you mean. What does it mean for your primary key to be in the "correct order"? I assume you know how to select rows in a specific order using the "ORDER BY" clause? > , so I want to make other primary key to generate sequences 1, 2, 3, . and How can you have *another* primary key? By definition there can only be one primary key. > in MS SQL SERVER 2005 > > I can with Rank() function , but in Postgres how ? If all you want to do is generate a series of numbers you might look at generate_series(), or if you'd like a "row number" then something like: CREATE TEMPORARY SEQUENCE myseq; SELECT *,nextval('myseq') FROM mytable; I have to say though, I'm not sure what you're trying to do. I do get the feeling I'd think it was a bad idea once I found out though. -- Richard Huxton Archonet Ltd