Re: [SQL] Getting primary key from insert statement - Mailing list pgsql-sql

From Emils Klotins
Subject Re: [SQL] Getting primary key from insert statement
Date
Msg-id 199906070647.JAA08463@omega.bkc.lv
Whole thread Raw
In response to Re: [SQL] Getting primary key from insert statement  (Herouth Maoz <herouth@oumail.openu.ac.il>)
Responses Re: [SQL] Getting primary key from insert statement
List 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 by date:

Previous
From: Vikrant Rathore
Date:
Subject: Re: [SQL] Mail about duplicate rows
Next
From: Herouth Maoz
Date:
Subject: Re: [SQL] Getting primary key from insert statement