Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 6CF861337BF7 for ; Wed, 20 Apr 2011 13:12:26 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 87044-06 for ; Wed, 20 Apr 2011 16:12:08 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from jupiter.marktest.pt (delta.marktest.pt [80.251.174.116]) by mail.postgresql.org (Postfix) with ESMTP id AED7E1337BC8 for ; Wed, 20 Apr 2011 13:12:07 -0300 (ADT) Received: from Proteu (proteu.marktest.pt [10.61.90.54]) by jupiter.marktest.pt with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id H7VWCJ7F; Wed, 20 Apr 2011 17:12:05 +0100 Message-ID: <0E2AEE255CB846CAA0017E7BB54D501C@marktestcr.marktest.pt> From: "Oliveiros d'Azevedo Cristina" To: , References: <4DAEFF97.9020608@encs.concordia.ca> Subject: Re: How to realize ROW_NUMBER() in 8.3? Date: Wed, 20 Apr 2011 17:12:05 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5512 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.79 tagged_above=-5 required=5 tests=BAYES_50=0.8, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201104/30 X-Sequence-Number: 35277 If your table is not terribly big, you can try something like SELECT a.col1,a.col2, COUNT(*) as row_number FROM yourTable a,yourTable b WHERE a.col1 >= b.col1 -- I'm assuming col1 is primary key GROUP BY a.col1,a.col2 ORDER BY row_number This is pure SQL, should work in every version... Best, Oliveiros ----- Original Message ----- From: "Emi Lu" To: Sent: Wednesday, April 20, 2011 4:45 PM Subject: [SQL] How to realize ROW_NUMBER() in 8.3? > Hello, > > ROW_NUMBER() is only ready in 8.4. For 8.3, is there a simple way to get > row_number > > select row_number(), col1, col2... > FROM tableName > > Thanks a lot! > > Ding Ye > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql