From: | "Joel Burton" <joel(at)joelburton(dot)com> |
---|---|
To: | "Gaetano Mendola" <mendola(at)bigfoot(dot)com>, <pgsql-admin(at)postgresql(dot)org> |
Subject: | Re: SERIAL Field |
Date: | 2002-05-06 12:38:46 |
Message-ID: | JGEPJNMCKODMDHGOBKDNEEPCCMAA.joel@joelburton.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
> 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(at)joelburton(dot)com | joelburton.com | aim: wjoelburton
Knowledge Management & Technology Consultant
From | Date | Subject | |
---|---|---|---|
Next Message | Rajesh Kumar Mallah. | 2002-05-06 13:26:10 | Re: SERIAL Field |
Previous Message | Gaetano Mendola | 2002-05-06 10:46:18 | SERIAL Field |