Re: Implicit sequence with start value?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Clemens Eisserer <linuxhippy(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Implicit sequence with start value?
Date: 2009-07-26 16:18:37
Message-ID: 27956.1248625117@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-jdbc

Clemens Eisserer <linuxhippy(at)gmail(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Clemens Eisserer 2009-07-26 17:20:41 Re: Implicit sequence with start value?
Previous Message Clemens Eisserer 2009-07-26 16:10:07 Implicit sequence with start value?

Browse pgsql-jdbc by date

  From Date Subject
Next Message Clemens Eisserer 2009-07-26 17:20:41 Re: Implicit sequence with start value?
Previous Message Clemens Eisserer 2009-07-26 16:10:07 Implicit sequence with start value?