> 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