Re: ROW_NUMBER alias

From: Stefan Becker <pgsql(at)yukonho(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: ROW_NUMBER alias
Date: 2007-05-06 18:41:30
Message-ID: 200705062041.31192.pgsql@yukonho.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I might be told off by some better SQL-User here on the list -
still here is my 2 Cents worth....

> I needed ROW_NUMBER() in PostGresql and I did find the 'temporary sequence'
> method as a workaround and i think it at least gets the job done relatively

you use:

> CREATE TEMP SEQUENCE rownum;
> SELECT nextval('rownum') AS row_number , t.a, t.b, t.c
> FROM (
> SELECT a, b, c
> FROM table
> WHERE table_id = 973
> ORDER BY record_date
> ) t;

Doesn't this just return the 973th single record for the current
sequence order in your table?

I believe:
SELECT a, b, c FROM table
offset 973 limit 1

will accomplish the same result.

Stefan

--
email: stefan(at)yukonho(dot)de
tel : +49 (0)6232-497631
http://www.yukonho.de

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Aaron Bono 2007-05-06 18:45:54 Re: Sequence vs. Index Scan
Previous Message Robins 2007-05-06 16:01:39 ROW_NUMBER alias