Re: SERIAL Field

Поиск
Список
Период
Сортировка
От Joel Burton
Тема Re: SERIAL Field
Дата
Msg-id JGEPJNMCKODMDHGOBKDNEEPCCMAA.joel@joelburton.com
обсуждение исходный текст
Ответ на SERIAL Field  ("Gaetano Mendola" <mendola@bigfoot.com>)
Список 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@joelburton.com | joelburton.com | aim: wjoelburton
Knowledge Management & Technology Consultant


В списке pgsql-admin по дате отправления:

Предыдущее
От: "Mark McEahern"
Дата:
Сообщение: configure datatype name > 31?
Следующее
От: "Rajesh Kumar Mallah."
Дата:
Сообщение: Re: SERIAL Field