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 645829FA279 for ; Fri, 26 May 2006 07:50:45 -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 81534-02 for ; Fri, 26 May 2006 07:50:39 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from r1.mycybernet.net (r1.mycybernet.net [209.5.206.8]) by postgresql.org (Postfix) with ESMTP id 2E4B09F9B01 for ; Fri, 26 May 2006 07:50:38 -0300 (ADT) Received: from 227-54-222-209.mycybernet.net ([209.222.54.227]:37710 helo=phlogiston.dydns.org) by r1.mycybernet.net with esmtp (Exim 4.50 (FreeBSD)) id 1FjZtt-000KX0-FI for pgsql-sql@postgresql.org; Fri, 26 May 2006 06:50:37 -0400 Received: by phlogiston.dydns.org (Postfix, from userid 1000) id 0F9393FAF; Fri, 26 May 2006 06:50:37 -0400 (EDT) Date: Fri, 26 May 2006 06:50:37 -0400 From: Andrew Sullivan To: pgsql-sql@postgresql.org Subject: Re: PLEASE help ME , HOW TO GENERATE PRIMARY Keys on the fly Message-ID: <20060526105037.GB5492@phlogiston.dyndns.org> References: <20060526101207.5C4B35B0B83@svr4.postgresql.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060526101207.5C4B35B0B83@svr4.postgresql.org> User-Agent: Mutt/1.5.9i X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/190 X-Sequence-Number: 25221 On Fri, May 26, 2006 at 05:11:26PM +0700, andi wrote: > select rank() over(order by testeridpk ) as rank , * from tester; > > I get the result is like this, > > > RANK TESTERIDPK TESTER_NAME > > 1 10 TESSS > > 2 90 NAMAAA > > 3 100 UUUUUUUU > > > How in postgres sql I get the same result , please help me, because iam > really frustating with this duty. There's no built in for that that I know of. You could use a temporary sequence to do it: BEGIN; CREATE SEQUENCE tempseq; SELECT nextval('tempseq') as rank, testeridpk, tester_name FROM testers ORDER BY testeridpk; ROLLBACK; which, I _think_, will get you what you want (i.e. that's not tested). The ROLLBACK is just there to clean up the sequence. A -- Andrew Sullivan | ajs@crankycanuck.ca "The year's penultimate month" is not in truth a good way of saying November. --H.W. Fowler