From: Tom Lane <tgl@sss.pgh.pa.us>
To: Clemens Eisserer <linuxhippy@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Implicit sequence with start value?
Date: Sun, 26 Jul 2009 12:18:37 -0400
Message-ID: <27956.1248625117@sss.pgh.pa.us> (raw)
In-Reply-To: <194f62550907260910x5a286204g3280e4eb5e583cca@mail.gmail.com>
References: <194f62550907260910x5a286204g3280e4eb5e583cca@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: tgl@sss.pgh.pa.us, linuxhippy@gmail.com, pgsql-general@postgresql.org
Subject: Re: Implicit sequence with start value?
In-Reply-To: <27956.1248625117@sss.pgh.pa.us>
References: <194f62550907260910x5a286204g3280e4eb5e583cca@mail.gmail.com> <27956.1248625117@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox