From: Emils Klotins <emils@mail.usis.bkc.lv>
To: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] Getting primary key from insert statement
Date: Mon, 7 Jun 1999 09:51:06 EET
Message-ID: <199906070647.JAA08463@omega.bkc.lv> (raw)
In-Reply-To: <l03130304b38014d3b9f7@[147.233.159.109]>
References: <551413BBBB03D111BF880060B01AACCE0B38FA@home.priority.net>
[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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: emils@mail.usis.bkc.lv
Subject: Re: [SQL] Getting primary key from insert statement
In-Reply-To: <199906070647.JAA08463@omega.bkc.lv>
References: <551413BBBB03D111BF880060B01AACCE0B38FA@home.priority.net> <199906070647.JAA08463@omega.bkc.lv>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox