Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id DCBBB1337BBA for ; Tue, 3 May 2011 11:53:30 -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 67588-01 for ; Tue, 3 May 2011 14:53:12 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from oldperseverance.encs.concordia.ca (oldperseverance.encs.concordia.ca [132.205.96.94]) by mail.postgresql.org (Postfix) with ESMTP id EB54D1337B9C for ; Tue, 3 May 2011 11:53:11 -0300 (ADT) Received: from cacao.encs.concordia.ca (emilu@cacao.encs.concordia.ca [132.205.47.225]) by oldperseverance.encs.concordia.ca (envelope-from emilu@encs.concordia.ca) (8.13.7/8.13.7) with ESMTP id p43Er8mp000362; Tue, 3 May 2011 10:53:08 -0400 Message-ID: <4DC016D4.9090608@encs.concordia.ca> Date: Tue, 03 May 2011 10:53:08 -0400 From: Emi Lu Reply-To: emilu@encs.concordia.ca User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20101125 Lightning/1.0b1 Thunderbird/3.0.11 MIME-Version: 1.0 To: pgsql-sql@postgresql.org CC: "Oliveiros d'Azevedo Cristina" Subject: Re: How to realize ROW_NUMBER() in 8.3? References: <4DAEFF97.9020608@encs.concordia.ca> <0E2AEE255CB846CAA0017E7BB54D501C@marktestcr.marktest.pt> In-Reply-To: <0E2AEE255CB846CAA0017E7BB54D501C@marktestcr.marktest.pt> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.58 on oldperseverance.encs.concordia.ca at 2011/05/03 10:53:09 EDT X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201105/16 X-Sequence-Number: 35300 Thank you for the info. I found a simple way: ========================== [1] create SEQUENCE tmp start 7820; [2] insert into desti_table_name select nextval('tmp'), c1, c2... ... cN from t1 left join t2... ... tn where ... ... Just for people using 8.3, this is mimic row_number. Emi > 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 > -- Emi Lu, ENCS, Concordia University, Montreal H3G 1M8 emilu@encs.concordia.ca +1 514 848-2424 x5884