From: Joel Burton <joel@joelburton.com>
To: Gaetano Mendola <mendola@bigfoot.com>
To: pgsql-admin@postgresql.org
Subject: Re: SERIAL Field
Date: Mon, 6 May 2002 08:38:46 -0400
Message-ID: <JGEPJNMCKODMDHGOBKDNEEPCCMAA.joel@joelburton.com> (raw)
In-Reply-To: <002901c1f4eb$40cbe240$d5a9fea9@GMENDOLA2>
> 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
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-admin@postgresql.org
Cc: joel@joelburton.com, mendola@bigfoot.com
Subject: Re: SERIAL Field
In-Reply-To: <JGEPJNMCKODMDHGOBKDNEEPCCMAA.joel@joelburton.com>
References: <002901c1f4eb$40cbe240$d5a9fea9@GMENDOLA2> <JGEPJNMCKODMDHGOBKDNEEPCCMAA.joel@joelburton.com>
* 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