X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id A7ECF474E4F for ; Fri, 14 Feb 2003 05:10:17 -0500 (EST) Received: from anchor-post-39.mail.demon.net (anchor-post-39.mail.demon.net [194.217.242.80]) by postgresql.org (Postfix) with ESMTP id 1DCE7474E42 for ; Fri, 14 Feb 2003 05:10:17 -0500 (EST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-39.mail.demon.net with esmtp (Exim 3.36 #2) id 18jcnS-0006Pq-0d; Fri, 14 Feb 2003 10:10:18 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id E81FB169B8; Fri, 14 Feb 2003 10:10:16 +0000 (GMT) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id 53487169B3; Fri, 14 Feb 2003 10:10:16 +0000 (GMT) Content-Type: text/plain; charset="utf-8" From: Richard Huxton Organization: Archonet Ltd To: Tom Lane , Josh Berkus Subject: Re: rownum Date: Fri, 14 Feb 2003 10:10:15 +0000 User-Agent: KMail/1.4.3 Cc: chester c young , pgsql-sql@postgresql.org References: <20030214043800.99417.qmail@web12707.mail.yahoo.com> <200302132056.20122.josh@agliodbs.com> <4353.1045200034@sss.pgh.pa.us> In-Reply-To: <4353.1045200034@sss.pgh.pa.us> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200302141010.15271.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/327 X-Sequence-Number: 11725 On Friday 14 Feb 2003 5:20 am, Tom Lane wrote: > > select nextval('rownum'), * from (select ... order by ...) sub; > > The overhead of using a sequence for this is pretty annoying. It would > be a simple matter to write a C function that emits sequential values > without any database access (see pg_stat_get_backend_idset() for some > inspiration). But you'd still need the subselect to avoid getting > re-sorted. AFAICS any rownum() function that doesn't behave like that > is a flat violation of the SQL standard... Could you not build a wrapper function something like: SELECT with_rownum('SELECT ...'); Where the function returns SETOF RECORD or similar - just fetch rows from t= he=20 select and prepend a pg_rownum column? --=20 Richard Huxton