Re: sequence

From: Dennis Björklund <db(at)zigo(dot)dhs(dot)org>
To: cristi <cristi(at)dmhi(dot)ct(dot)ro>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: sequence
Date: 2003-08-15 10:40:28
Message-ID: Pine.LNX.4.44.0308151234480.2191-100000@zigo.dhs.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

  • sequence at 2003-08-15 09:32:36 from cristi

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2003-08-15 12:01:46 Re: sequence
Previous Message Bertrand Petit 2003-08-15 10:30:26 Re: sequence