sequence - Mailing list pgsql-general

From Alain Roger
Subject sequence
Date
Msg-id 75645bbb0712090741h5c98b20jcb1c7a71017730d4@mail.gmail.com
Whole thread Raw
Responses Re: sequence
List pgsql-general
Hi,

I'm still trying to understand how the sequences work under PostgreSQL.

for example i have a sequence called : users_user_id_seq
with :
current value = 1
min value = 1
max value = 9223372036854775807
start = 1
a typical "serial" field.

to perform an autoincrement in my SQL queries...specially while i use insert into i do the following thing :

INSERT INTO mytable VALUES
(
 select nextval('users_user_id_seq'),
 ...
);

however this get the currentvalue + 1, or during creating the sequence i must say that start = 0.

how can i get the current value (to use it into my "insert into statement") and by the same time,. increment it by 1, to be ready for the next time ?

--
Alain
------------------------------------
Windows XP SP2
PostgreSQL 8.2.4 / MS SQL server 2005
Apache 2.2.4
PHP 5.2.4
C# 2005-2008

pgsql-general by date:

Previous
From: "Greg Steffensen"
Date:
Subject: Re: function permissions question
Next
From: Tom Lane
Date:
Subject: Re: sequence