From: Tom Lane <tgl@sss.pgh.pa.us>
To: cristi <cristi@dmhi.ct.ro>
Cc: pgsql-sql@postgresql.org
Subject: Re: sequence
Date: Fri, 15 Aug 2003 08:01:46 -0400
Message-ID: <12592.1060948906@sss.pgh.pa.us> (raw)
In-Reply-To: <006601c36310$29da3a20$7201a8c0@dmhi.ct.ro>
References: <006601c36310$29da3a20$7201a8c0@dmhi.ct.ro>
"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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, cristi@dmhi.ct.ro
Subject: Re: sequence
In-Reply-To: <12592.1060948906@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox