sequence

From: "Alain Roger" <raf(dot)news(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: sequence
Date: 2007-12-09 15:41:01
Message-ID: 75645bbb0712090741h5c98b20jcb1c7a71017730d4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-12-09 15:51:32 Re: sequence
Previous Message Greg Steffensen 2007-12-09 06:36:46 Re: function permissions question