Re: setting serial start value

From: Greg Philpott <gphilpott(at)mdialogue(dot)com>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: setting serial start value
Date: 2006-07-21 04:26:18
Message-ID: 57F5018A-06AD-4DF0-B251-1ABC8B5E33CE@mdialogue.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks Michael that did the trick!
Greg
On 21-Jul-06, at 12:05 AM, Michael Fuhr wrote:

> On Thu, Jul 20, 2006 at 11:35:51PM -0400, Greg Philpott wrote:
>> Hi Michael, from terminal in psql I enter
>> # ALTER SEQUENCE public.users MINVALUE 9999;
>> But it doesn't work. I don't think I am specifying the field
>> correctly. the schema is public, the table is users, the field is id.
>
> ALTER SEQUENCE uses the sequence name, not the table name. Also,
> use RESTART WITH to set the sequence's current value. Example:
>
> test=> CREATE TABLE users (id serial PRIMARY KEY, username text);
> NOTICE: CREATE TABLE will create implicit sequence "users_id_seq"
> for "serial" column "users.id"
> NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
> "users_pkey" for table "users"
> CREATE TABLE
> test=> ALTER SEQUENCE users_id_seq RESTART WITH 10000;
> ALTER SEQUENCE
> test=> INSERT INTO users (username) VALUES ('Alice');
> INSERT 2592322 1
> test=> INSERT INTO users (username) VALUES ('Bob');
> INSERT 2592323 1
> test=> SELECT * FROM users;
> id | username
> -------+----------
> 10000 | Alice
> 10001 | Bob
> (2 rows)
>
> --
> Michael Fuhr

In response to

Browse pgsql-general by date

  From Date Subject
Next Message deepak pal 2006-07-21 08:53:29 question for JAVA developer who r using postgres sql as backend
Previous Message Michael Fuhr 2006-07-21 04:05:34 Re: setting serial start value