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 7B3F2329E6F; Fri, 24 Sep 2004 22:54:51 +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 34882-08; Fri, 24 Sep 2004 21:54:40 +0000 (GMT) Received: from mail.tpchd.org (unknown [192.103.155.40]) by svr1.postgresql.org (Postfix) with SMTP id 5B995329C67; Fri, 24 Sep 2004 22:54:39 +0100 (BST) Received: from TPC-Message_Server by mail.tpchd.org with Novell_GroupWise; Fri, 24 Sep 2004 14:51:02 -0700 Message-Id: X-Mailer: Novell GroupWise Internet Agent 5.5.2.1 Date: Fri, 24 Sep 2004 14:49:56 -0700 From: "Ian Harding" To: , Cc: , , Subject: Re: [SQL] need ``row number`` Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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/1064 X-Sequence-Number: 66270 Right. Sequence within a group. I did this in a SRF resetting the sequenc= e after each subgroup. I would love to see a better way. <<< Greg Stark 9/24 1:42p >>> 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. >=20 > A fairly common hack for this is to use a sequence: >=20 > 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. --=20 greg ---------------------------(end of broadcast)--------------------------- TIP 8: explain analyze is your friend =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20