Antwort vor der Frage ;-)

akretschmer

Datenbank-Guru
Beiträge
10.311
vermutlich wird @nopsibob gleich fragen, wie man eine automatisch generierte ID ermitteln kann. Hier schon mal die Antwort:

Code:
test=# create table nopsibob(id serial primary key, val text);
CREATE TABLE
test=*# insert into nopsibob (val) values ('a') returning id;
 id
----
  1
(1 Zeile)

INSERT 0 1
test=*# insert into nopsibob (val) values ('b');
INSERT 0 1
test=*# select currval('nopsibob_id_seq');
 currval
---------
       2
(1 Zeile)

test=*# with tmp as (insert into nopsibob (val) values ('c') returning id) select * from tmp;
 id
----
  3
(1 Zeile)

test=*#

Das waren jetzt 3 mögliche Wege...
 
Werbung:
Zurück
Oben