am Wed, dem 11.04.2007, um 16:50:17 +0100 mailte Oliveiros Cristina folgendes:
> Hello, All,
>
> I would like to know if Postgres has a function similar to ROW_NUMBER().
> I would like that the output of a query looked something like this
>
> column1 column2
> 1 x1 x2
> 2 y1 y2
> 3 z1 z2
> ...
>
> I suspect that my question has an easy and quick answer, but from my searches I
> couldn't find it yet :-(
You can do this either in the client-app or, for instance, with a
sequence like this:
test=# create table test (a text);
CREATE TABLE
test=*# insert into test values ('a');
INSERT 0 1
test=*# insert into test values ('c');
INSERT 0 1
test=*# insert into test values ('b');
INSERT 0 1
test=*# commit;
COMMIT
test=# create sequence s_test;
CREATE SEQUENCE
test=*# select nextval('s_test'), a from (select a from test order by 1)
foo;
nextval | a
---------+---
1 | a
2 | b
3 | c
(3 rows)
Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net