Re: [SQL] need ``row number``

From: "Ian Harding" <iharding(at)tpchd(dot)org>
To: <gsstark(at)mit(dot)edu>, <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <Karsten(dot)Hilbert(at)gmx(dot)net>, <pgsql-general(at)postgresql(dot)org>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: [SQL] need ``row number``
Date: 2004-09-24 21:49:56
Message-ID: s1543456.028@mail.tpchd.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

Right. Sequence within a group. I did this in a SRF resetting the sequence after each subgroup. I would love to see a better way.

<<< Greg Stark <gsstark(at)mit(dot)edu> 9/24 1:42p >>>
Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:

> Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net> 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

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Browse pgsql-general by date

  From Date Subject
Next Message Steve Crawford 2004-09-24 23:12:40 Re: Large arrays give long lag on server side before command executes
Previous Message Jerry LeVan 2004-09-24 21:19:38 Re: Building plpython on Mac OSX...

Browse pgsql-sql by date

  From Date Subject
Next Message Szálka Tamás 2004-09-26 16:15:57 plpgsql - accessing fields of record type
Previous Message Chester Kustarz 2004-09-24 21:00:10 Re: select column by position