Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 2D36B1337B8A for ; Mon, 31 Jan 2011 12:39:45 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 08178-04 for ; Mon, 31 Jan 2011 16:39:37 +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 1027E1337B84 for ; Mon, 31 Jan 2011 12:39:36 -0400 (AST) 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 p0VGdWts029732; Mon, 31 Jan 2011 11:39:32 -0500 Message-ID: <4D46E5C4.8070208@encs.concordia.ca> Date: Mon, 31 Jan 2011 11:39:32 -0500 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: Thomas Kellerer CC: pgsql-sql@postgresql.org Subject: Re: how to get row number in select query References: <4D4047C1.5030208@encs.concordia.ca> <4D4181E9.2000305@encs.concordia.ca> <090BC28FACC442EAA5D46B58F55480AE@marktestcr.marktest.pt> <4D418D62.4010906@techbaza.pl> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.58 on oldperseverance.encs.concordia.ca at 2011/01/31 11:39:32 EST 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: 201101/125 X-Sequence-Number: 35072 Ok, before 8.4, there I can use row_number(). For 8.3 + display tag + order by integer + paging based on pageBean ArrayList alist; In Bean.java, added: private int rec_num; in main .action java: for(int i=0 ; i Piotr Czekalski, 27.01.2011 16:21: >> Gentelmen, >> >> I follow this thread and I don't exactly get an idea of yours, but >> isn't is as simple as (example: table "web.files" contains one column >> named "fileurl" ): >> >> select row_number() over(), X.fileurl from (select fileurl from >> web.files order by fileurl) X >> >> The only disadvantage is that if you do want to order resultset you >> have to use "select from select" as numbers are added before order >> which may cause some performance troubles. >> > > You can get the row_number() without using the sub-select and without > ordering the whole result as you can specify the order in the over() > clause: > > select fileurl > row_number() over (order by fileurl) > from web.files > > Regards > Thomas > > -- Emi Lu, ENCS, Concordia University, Montreal H3G 1M8 emilu@encs.concordia.ca +1 514 848-2424 x5884