Re: Re: "Oracle's ROWNUM" - Mailing list pgsql-general

From Hiroshi Inoue
Subject Re: Re: "Oracle's ROWNUM"
Date
Msg-id 3B650A78.1926B0C5@tpf.co.jp
Whole thread Raw
In response to Re: Re: "Oracle's ROWNUM"  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Re: "Oracle's ROWNUM"  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Svenne Krap wrote:
>
> On Mon, 30 Jul 2001 00:05:42 +0000 (UTC), tgl@sss.pgh.pa.us (Tom Lane)
> wrote:
>
> >Svenne Krap <usenet@krap.dk> writes:
> >> I thought of the possibility to do something like
> >
> >> select rownum as artistplacement, s.* from (select rownum as
> >> techplacement, * from ranking order by technical_points) order by
> >> s.artiste_points
> >
> >This is an interesting example, but I do not believe that ROWNUM could
> >really be used that way.  You are assuming that ROWNUM is computed after
> >the rows are sorted --- but in fact SQL requires the target expressions
> >of a SELECT to be computed before ORDER BY is applied.  What would you
> >expect to happen with
> >       SELECT rownum, * FROM table ORDER BY 1
> >
> >Does anyone know what the actual semantics of Oracle's ROWNUM are?
>
> Well, I'm quite positive, that Oracle calculates ROWNUM after having
> ordered the set. As I'm not sure, ROWNUM is counted as part of the
> resultset (until it is selected of a second select)
>

Isn't it a little different ?
Oracle doc says.

If you embed the ORDER BY clause in a subquery and place the ROWNUM
condition in the top-level query, you can force the ROWNUM condition
to be applied after the ordering of the rows. For example, the
following query returns the 10 smallest employee numbers. This
is sometimes referred to as a "top-N query":

SELECT * FROM
   (SELECT empno FROM emp ORDER BY empno)
   WHERE ROWNUM < 11;


regards,
Hiroshi Inoue

pgsql-general by date:

Previous
From: will trillich
Date:
Subject: RULE vs TRIGGER
Next
From: "Kapil Tilwani"
Date:
Subject: C / FoxPro