Re: sequence - Mailing list pgsql-sql

From Dennis Björklund
Subject Re: sequence
Date
Msg-id Pine.LNX.4.44.0308151234480.2191-100000@zigo.dhs.org
Whole thread Raw
In response to sequence  ("cristi" <cristi@dmhi.ct.ro>)
List 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 by date:

Previous
From: "cristi"
Date:
Subject: sequence
Next
From: Bertrand Petit
Date:
Subject: Re: sequence