Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id E09B09FB200 for ; Sun, 6 May 2007 16:01:45 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 74919-08 for ; Sun, 6 May 2007 16:01:30 -0300 (ADT) X-Greylist: delayed 00:20:05.398592 by SQLgrey-1.7.5 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 448F79FB292 for ; Sun, 6 May 2007 16:01:39 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from 208091.vserver.de (nirs.de [62.75.208.91]) by svr4.postgresql.org (Postfix) with ESMTP id BD8A05AF882 for ; Sun, 6 May 2007 18:41:31 +0000 (GMT) Received: from becker.local (p54AD0C82.dip0.t-ipconnect.de [84.173.12.130]) (authenticated bits=0) by 208091.vserver.de (8.12.8/8.12.8) with ESMTP id l46IfVXc030625 for ; Sun, 6 May 2007 20:41:32 +0200 From: Stefan Becker To: pgsql-sql@postgresql.org Subject: Re: ROW_NUMBER alias Date: Sun, 6 May 2007 20:41:30 +0200 User-Agent: KMail/1.6.2 References: <36af4bed0705060901s36fed269ye5a8588eaffbd750@mail.gmail.com> In-Reply-To: <36af4bed0705060901s36fed269ye5a8588eaffbd750@mail.gmail.com> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <200705062041.31192.pgsql@yukonho.de> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.186 tagged_above=0 required=5 tests=AWL=0.050, BAYES_50=0.001, FORGED_RCVD_HELO=0.135 X-Spam-Level: X-Archive-Number: 200705/36 X-Sequence-Number: 28317 I might be told off by some better SQL-User here on the list - still here is my 2 Cents worth.... > I needed ROW_NUMBER() in PostGresql and I did find the 'temporary sequence' > method as a workaround and i think it at least gets the job done relatively you use: > CREATE TEMP SEQUENCE rownum; > SELECT nextval('rownum') AS row_number , t.a, t.b, t.c > FROM ( > SELECT a, b, c > FROM table > WHERE table_id = 973 > ORDER BY record_date > ) t; Doesn't this just return the 973th single record for the current sequence order in your table? I believe: SELECT a, b, c FROM table offset 973 limit 1 will accomplish the same result. Stefan -- email: stefan@yukonho.de tel : +49 (0)6232-497631 http://www.yukonho.de