Skip site navigation (1) Skip section navigation (2)

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

From: Greg Stark <gsstark(at)mit(dot)edu>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Karsten Hilbert <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 20:34:47
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-generalpgsql-sql
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


In response to

pgsql-sql by date

Next:From: Chester KustarzDate: 2004-09-24 21:00:10
Subject: Re: select column by position
Previous:From: Oliver NoldenDate: 2004-09-24 15:39:53
Subject: How to insert values in bytea?

pgsql-general by date

Next:From: John LiuDate: 2004-09-24 20:55:43
Subject: core dump on select
Previous:From: Robert FitzpatrickDate: 2004-09-24 20:14:46
Subject: Returning a list of fields in a composite type

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group