Re: [SQL] Getting primary key from insert statement
От | Emils Klotins |
---|---|
Тема | Re: [SQL] Getting primary key from insert statement |
Дата | |
Msg-id | 199906070647.JAA08463@omega.bkc.lv обсуждение исходный текст |
Ответ на | Re: [SQL] Getting primary key from insert statement (Herouth Maoz <herouth@oumail.openu.ac.il>) |
Ответы |
Re: [SQL] Getting primary key from insert statement
|
Список | pgsql-sql |
[6 Jun 99,, 15:31] Herouth Maoz wrote: > At 00:46 +0300 on 03/06/1999, Pham, Thinh wrote: > > > > Hi, is there a way you can get back the primary key (serialized) from an > > insert you just do on a table. For example i have a table called "order" and [snip] > Yes. You have to know the name of the sequence which the serial type caused > to be created. You are notified of the name when you create the table. It > would be 'order_pid_seq' in the case you described (remember that ORDER is > a reserved word, though). [snip] > Anyway, after you make the insert, you can retrieve the recently-created > value of the sequence, using currval( 'order_pid_seq' ). [snip] > Note that currval will not work until somebody does a nextval on the same > sequence. > Wouldn't it be simpler just to SELECT the next value from the sequence BEFORE the insert and use it in the INSERT statement directly? Emils Klotins e-mail: emils@mail.usis.bkc.lv Systems Manager URL: http://www.usis.bkc.lv/ USIS Riga 7 Smilsu Str., Riga LV1050, LATVIA
В списке pgsql-sql по дате отправления: