Re: rownum

From: Richard Huxton <dev(at)archonet(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Josh Berkus <josh(at)agliodbs(dot)com>
Cc: chester c young <chestercyoung(at)yahoo(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: rownum
Date: 2003-02-14 10:10:15
Message-ID: 200302141010.15271.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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 the
select and prepend a pg_rownum column?

--
Richard Huxton

In response to

Responses

  • Re: rownum at 2003-02-14 15:42:30 from Joe Conway

Browse pgsql-sql by date

  From Date Subject
Next Message Gary Stainburn 2003-02-14 12:02:18 Re: Table Pivot
Previous Message Christoph Haller 2003-02-14 09:48:17 Re: Table Pivot