Обсуждение: Newbie ex-Oracle person's question: Oracle ROWID = PSQL OID, Orac le ROWNUM = PSQL ???

Поиск
Список
Период
Сортировка

Newbie ex-Oracle person's question: Oracle ROWID = PSQL OID, Orac le ROWNUM = PSQL ???

От
Robert Beer
Дата:
Oracle has a ROWNUM pseudo column that works like this ...
TEST>select callid, rownum from cs_calls where rownum < 5;
   CALLID     ROWNUM
---------- ----------     7806          1     7807          2     7809          3     6443          4

4 rows selected.

... which can be quite handy.

Is there something like this in PSQL?

By the way, having used Oracle since 1987 it's a pleasure to use PSQL.
Someone actually thinks about the implemented features.
For example, Oracle's implementation of ROWNUM gives them in the order the
rows were BEFORE the ORDER BY, which is not of much use as adding an ORDER
BY jumbles them up.  Duh!

Thanks in advance for any responses.


Re: Newbie ex-Oracle person's question: Oracle ROWID = PSQL OID, Orac le ROWNUM = PSQL ???

От
Cliff Crawford
Дата:
* Robert Beer <Robert.Beer@Callserve.com> menulis:
> Oracle has a ROWNUM pseudo column that works like this ...
> TEST>select callid, rownum from cs_calls where rownum < 5;
> 
>     CALLID     ROWNUM
> ---------- ----------
>       7806          1
>       7807          2
>       7809          3
>       6443          4
> 
> 4 rows selected.
> 
> ... which can be quite handy.
> 
> Is there something like this in PSQL?

You can use the LIMIT clause:

SELECT callid FROM cs_calls LIMIT 4;

See
<http://postgresql.readysetnet.com/users-lounge/docs/7.1/postgres/sql-select.html>
for more info.


> By the way, having used Oracle since 1987 it's a pleasure to use PSQL.
> Someone actually thinks about the implemented features.
> For example, Oracle's implementation of ROWNUM gives them in the order the
> rows were BEFORE the ORDER BY, which is not of much use as adding an ORDER
> BY jumbles them up.  Duh!

LIMIT in PostgreSQL applies *after* ORDER BY, so you won't have this
problem :)


-- 
Cliff Crawford   http://www.sowrong.org/
birthday party cheesecake jellybean BOOM


Re: Newbie ex-Oracle person's question: Oracle ROWID = PSQL OID, Orac le ROWNUM = PSQL ???

От
jdassen@cistron.nl (J.H.M. Dassen (Ray))
Дата:
Robert Beer <Robert.Beer@Callserve.com> wrote:
> Oracle has a ROWNUM pseudo column that works like this ...
> TEST>select callid, rownum from cs_calls where rownum < 5;

> Is there something like this in PSQL?

SELECT callid FROM cs_calls LIMIT 4;

HTH,
Ray
-- 
Give a man a fire, he's warm for a day.  Set a man on fire, he's warm for
the rest of his life.