From: | "Emils Klotins" <emils(at)mail(dot)usis(dot)bkc(dot)lv> |
---|---|
To: | <pgsql-sql(at)postgreSQL(dot)org> |
Subject: | Re: [SQL] Getting primary key from insert statement |
Date: | 1999-06-07 09:51:06 |
Message-ID: | 199906070647.JAA08463@omega.bkc.lv |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)mail(dot)usis(dot)bkc(dot)lv
Systems Manager URL: http://www.usis.bkc.lv/
USIS Riga 7 Smilsu Str., Riga LV1050, LATVIA
From | Date | Subject | |
---|---|---|---|
Next Message | Michael J Davis | 1999-06-07 20:10:26 | RE: [SQL] Getting primary key from insert statement |
Previous Message | Herouth Maoz | 1999-06-07 07:29:17 | Re: [SQL] Getting primary key from insert statement |