Received: from omega.bkc.lv (omega.bkc.lv [195.244.128.2]) by hub.org (8.9.3/8.9.3) with ESMTP id CAA16312 for ; Mon, 7 Jun 1999 02:47:58 -0400 (EDT) (envelope-from emils@mail.usis.bkc.lv) Received: from mail.usis.bkc.lv (mail.usis.bkc.lv [195.244.132.2]) by omega.bkc.lv (8.9.1/8.9.1) with ESMTP id JAA08463 for ; Mon, 7 Jun 1999 09:47:52 +0300 (EEDT) Message-Id: <199906070647.JAA08463@omega.bkc.lv> Received: from USIS-RIGA/SpoolDir by mail.usis.bkc.lv (Mercury 1.44); 7 Jun 99 09:51:54 EET Received: from SpoolDir by USIS-RIGA (Mercury 1.44); 7 Jun 99 09:51:30 EET From: "Emils Klotins" Organization: USIS Riga To: Date: Mon, 7 Jun 1999 09:51:06 EET MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: [SQL] Getting primary key from insert statement Reply-to: emils@mail.usis.bkc.lv Priority: normal In-reply-to: References: <551413BBBB03D111BF880060B01AACCE0B38FA@home.priority.net> X-mailer: Pegasus Mail for Win32 (v3.02b14) [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