Re: Implicit sequence with start value? - Mailing list pgsql-general

From Tom Lane
Subject Re: Implicit sequence with start value?
Date
Msg-id 27956.1248625117@sss.pgh.pa.us
Whole thread Raw
In response to Implicit sequence with start value?  (Clemens Eisserer <linuxhippy@gmail.com>)
Responses Re: Implicit sequence with start value?
List pgsql-general
Clemens Eisserer <linuxhippy@gmail.com> writes:
> Is it possible to use an implicit sequence with a start value?
> Something like:  CREATE TABLE foo (key SERIAL START 1000 PRIMARY KEY NOT NULL);

Well, you can't do it just that way, but you could issue a setval() or
ALTER SEQUENCE command after creating the table.  For instance

regression=# create table foo (bar serial);
NOTICE:  CREATE TABLE will create implicit sequence "foo_bar_seq" for serial column "foo.bar"
CREATE TABLE
regression=# alter sequence foo_bar_seq start with 1000;
ALTER SEQUENCE

or you might prefer

regression=# select setval(pg_get_serial_sequence('foo', 'bar'), 1000);
 setval
--------
   1000
(1 row)


            regards, tom lane

pgsql-general by date:

Previous
From: Clemens Eisserer
Date:
Subject: Implicit sequence with start value?
Next
From: Clemens Eisserer
Date:
Subject: Re: Implicit sequence with start value?