Re: ROW_NUMBER alias

From: Robins <tharakan(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Cc: "Stefan Becker" <pgsql(at)yukonho(dot)de>
Subject: Re: ROW_NUMBER alias
Date: 2007-05-07 02:03:15
Message-ID: 36af4bed0705061903y711ceb53v79ed176d5f849509@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi Stefan,

Well that was just an example. That table had a primary key on (id, date).
By bad then, coz I guess I should have clarified that earlier.

But what I meant from the example was that it is trivial for the parser to
automatically put an enveloping SELECT to add a ROW_NUMBER() field to any
user given query.

Regards,
Robins Tharakan

On 5/7/07, Stefan Becker <pgsql(at)yukonho(dot)de> wrote:
>
> 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Nemo Terry 2007-05-07 08:07:00 How to use function PointN?
Previous Message John Summerfield 2007-05-06 23:42:39 Re: hi