Re: How to implement oracle like rownum(function or seudocolumn) - Mailing list pgsql-hackers

From Jonah H. Harris
Subject Re: How to implement oracle like rownum(function or seudocolumn)
Date
Msg-id 36e682920604081219q31adf9dct75b4c9fc65c3b3c1@mail.gmail.com
Whole thread Raw
In response to Re: How to implement oracle like rownum(function or seudocolumn)  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On 4/8/06, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> A function implemented as per Michael's example would not give the
> results that I think people would expect for
>
>         SELECT rownum(), * FROM foo ORDER BY whatever;
>

Yep, the query would have to be rewritten similar to Oracle's:

SELECT rownum(), * FROM (SELECT * FROM foo ORDER BY whatever);

IIRC, processing-wise, rownum and order-by processing is handled as follows:

SELECT id, whatever FROM foo WHERE rownum <= 10 ORDER BY id;

is the same as PostgreSQL's

SELECT id, whatever FROM (SELECT id, whatever FROM foo LIMIT 10) ORDER BY id;

--
Jonah H. Harris, Database Internals Architect
EnterpriseDB Corporation
732.331.1324


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: How to implement oracle like rownum(function or seudocolumn)
Next
From: Josh Berkus
Date:
Subject: Summer of Code -- mentors needed as well