Re: sequence

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: sequence
Дата
Msg-id 12592.1060948906@sss.pgh.pa.us
обсуждение исходный текст
Ответ на sequence  ("cristi" <cristi@dmhi.ct.ro>)
Список pgsql-sql
"cristi" <cristi@dmhi.ct.ro> writes:
> What is wrong here?
> insert into table_name (field_name) values (select
> setval('sequence_name')-1) as currval);

Either too few parentheses, or too many ;-)

You could write this as an INSERT/SELECT:

insert into table_name (field_name) select setval('sequence_name')-1 as currval;

or you could write it as an INSERT/VALUES with scalar subquery
expression:

insert into table_name (field_name) values ((select setval('sequence_name')-1 as currval));

(all the parentheses are required here).  But really you do not need
a subquery for this at all; VALUES is perfectly content with scalar
expressions:

insert into table_name (field_name) values (setval('sequence_name')-1);
        regards, tom lane


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

Предыдущее
От: Bertrand Petit
Дата:
Сообщение: Re: sequence
Следующее
От: Tim Andersen
Дата:
Сообщение: Re: About primary keys.