Re: How to implement oracle like rownum(function or seudocolumn)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jan Wieck <JanWieck(at)Yahoo(dot)com>
Cc: Michael Fuhr <mike(at)fuhr(dot)org>, Juan Manuel Diaz Lara <jmdiazlr(at)Yahoo(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: How to implement oracle like rownum(function or seudocolumn)
Date: 2006-04-08 19:04:40
Message-ID: 25474.1144523080@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Jan Wieck <JanWieck(at)Yahoo(dot)com> writes:
> My humble guess is that c) is also the reason why the ANSI didn't find a
> ROWNUM desirable.

I've never understood what the conceptual model is for Oracle's rownum.
Where along the SQL operational pipeline (FROM / WHERE / GROUP BY /
aggregate / compute output columns / ORDER BY) is it supposed to be
computed? To be useful for the often-requested purpose of nicely
labeling output with line numbers, it'd have to be assigned
post-ORDER-BY, but then it doesn't make any sense at all to use it in
WHERE, nor in sub-selects.

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;

unless the planner chances to do the ordering with an indexscan.
If it does it with a sort step then the rownums will be computed before
sorting :-(

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jonah H. Harris 2006-04-08 19:19:43 Re: How to implement oracle like rownum(function or seudocolumn)
Previous Message Markus Schiltknecht 2006-04-08 18:54:35 Re: Support Parallel Query Execution in Executor