Re: sequence - Mailing list pgsql-general

From Tom Lane
Subject Re: sequence
Date
Msg-id 11021.1197215492@sss.pgh.pa.us
Whole thread Raw
In response to sequence  ("Alain Roger" <raf.news@gmail.com>)
Responses Re: sequence
Simpler dump?
List pgsql-general
"Alain Roger" <raf.news@gmail.com> writes:
> 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.

Really?  Works fine for me:

regression=# create sequence foo start with 10;
CREATE SEQUENCE
regression=# select nextval('foo');
 nextval
---------
      10
(1 row)

regression=# select nextval('foo');
 nextval
---------
      11
(1 row)

If you're initializing the sequence some other way, such as with
setval(), maybe you need to make use of the is_called option to setval().

            regards, tom lane

pgsql-general by date:

Previous
From: "Alain Roger"
Date:
Subject: sequence
Next
From: "Alain Roger"
Date:
Subject: Re: sequence