Re: sequence

Поиск
Список
Период
Сортировка
От Dennis Björklund
Тема Re: sequence
Дата
Msg-id Pine.LNX.4.44.0308151234480.2191-100000@zigo.dhs.org
обсуждение исходный текст
Ответ на sequence  ("cristi" <cristi@dmhi.ct.ro>)
Список pgsql-sql
On Fri, 15 Aug 2003, cristi wrote:

> What is wrong here?
> 
> insert into table_name (field_name) values (select
> setval('sequence_name')-1) as currval);

Your probably want this instead:
 insert into table_name (field_name) values (nextval('sequence_name'));

The reason why your insert fail above is that setval() should have more 
parameters, but even if it had worked it does not make sense to call 
setval() there. See
 http://www.postgresql.org/docs/7.3/static/functions-sequence.html

Also, it's easier to use a serial column:
 http://www.postgresql.org/docs/7.3/static/datatype.html#DATATYPE-SERIAL

then you can do
 insert into table_name (field_name) values (DEFAULT);

-- 
/Dennis



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

Предыдущее
От: "cristi"
Дата:
Сообщение: sequence
Следующее
От: Bertrand Petit
Дата:
Сообщение: Re: sequence