Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 31A9B475B12 for ; Mon, 6 May 2002 10:07:28 -0400 (EDT) Received: from temp.joelburton.com (unknown [209.190.238.101]) by postgresql.org (Postfix) with ESMTP id 98111476491 for ; Mon, 6 May 2002 08:38:57 -0400 (EDT) Received: from joeltf0d13cyyp (unknown [209.190.238.100]) by temp.joelburton.com (Postfix) with SMTP id 853FE2B95F; Mon, 6 May 2002 08:42:53 -0400 (EDT) From: "Joel Burton" To: "Gaetano Mendola" , Subject: Re: SERIAL Field Date: Mon, 6 May 2002 08:38:46 -0400 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 In-Reply-To: <002901c1f4eb$40cbe240$d5a9fea9@GMENDOLA2> X-Archive-Number: 200205/28 X-Sequence-Number: 4203 > Hi all, > > having a table with a serial field what is the corrected method > to retrieve the value after an insert ? Use currval(_name_of_sequence_): joel=# create table test ( id serial ); NOTICE: CREATE TABLE will create implicit sequence 'test_id_seq' for SERIAL column 'test.id' NOTICE: CREATE TABLE / UNIQUE will create implicit index 'test_id_key' for table 'test' joel=# insert into test values (default); INSERT 16617 1 joel=# select currval('test_id_seq'); currval --------- 1 (1 row) See also nextval() and setval() for other functions for sequences. Joel BURTON | joel@joelburton.com | joelburton.com | aim: wjoelburton Knowledge Management & Technology Consultant