X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1D76E329D7F; Fri, 24 Sep 2004 21:35:13 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 10915-08; Fri, 24 Sep 2004 20:35:02 +0000 (GMT) Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) by svr1.postgresql.org (Postfix) with ESMTP id EDCBB329D3E; Fri, 24 Sep 2004 21:35:02 +0100 (BST) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1CAwmG-0004d8-00; Fri, 24 Sep 2004 16:34:48 -0400 To: Tom Lane Cc: Karsten Hilbert , pgsql-general@postgresql.org, pgsql-sql@postgresql.org Subject: Re: [SQL] need ``row number`` References: <20040924092117.A1195@hermes.hilbert.loc> <21339.1096035613@sss.pgh.pa.us> In-Reply-To: <21339.1096035613@sss.pgh.pa.us> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 24 Sep 2004 16:34:47 -0400 Message-ID: <87ekkr9ziw.fsf@stark.xeocode.com> Lines: 22 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/1062 X-Sequence-Number: 66268 Tom Lane writes: > Karsten Hilbert writes: > > I am not convinced I'll need a SRF. I am not trying to > > calculate something that isn't there yet. I am just trying to > > join two views appropriately. I might have to employ some > > variant of Celko's integer helper table but I'm not sure how > > to proceed. > > A fairly common hack for this is to use a sequence: > > create temp sequence tseq; > select nextval('tseq'), * from (select .... order by ...) ss; But I thought she wanted to get the row number within a group. Not the row number for the entire result set. A sequence can't do that. Or at least, I suppose it could but it would be mighty strange to see setval() in a SELECT query. And I can't think of how to detect the level break in a select query either. -- greg