From: Dennis Björklund <db@zigo.dhs.org>
To: cristi <cristi@dmhi.ct.ro>
Cc: pgsql-sql@postgresql.org
Subject: Re: sequence
Date: Fri, 15 Aug 2003 12:40:28 +0200 (CEST)
Message-ID: <Pine.LNX.4.44.0308151234480.2191-100000@zigo.dhs.org> (raw)
In-Reply-To: <006601c36310$29da3a20$7201a8c0@dmhi.ct.ro>
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
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: db@zigo.dhs.org, cristi@dmhi.ct.ro
Subject: Re: sequence
In-Reply-To: <Pine.LNX.4.44.0308151234480.2191-100000@zigo.dhs.org>
References: <006601c36310$29da3a20$7201a8c0@dmhi.ct.ro> <Pine.LNX.4.44.0308151234480.2191-100000@zigo.dhs.org>
* 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