Re: primary key

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: "Peter Evens" <peter(at)bandit(dot)be>
Subject: Re: primary key
Date: 2011-03-14 15:28:17
Message-ID: 201103140828.17750.adrian.klaver@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Monday, March 14, 2011 12:57:07 am Peter Evens wrote:
> hello,
>
> i have a question about the PRIMARY KEY,
> how can we let it start from for example 1000 instead of 1?
>
> This is our program:
> CREATE TABLE hy3_pack
> (
> hy3_id serial NOT NULL,
> hy3_serie_nummer text NOT NULL,
> hy3_barcode text NOT NULL,
> hy3_type_vulling text NOT NULL,
> hy3_tarra_gewicht text,
> hy3_artikel_id numeric NOT NULL,
> hy3_refill boolean,
> vernietigd boolean,
> opmerking text,
> CONSTRAINT hy3_pack_pkey PRIMARY KEY (hy3_id)
> )
> WITH (
> OIDS=FALSE
> );
> ALTER TABLE hy3_pack OWNER TO postgres;
>
> what must i change in my program?
>

First do something like below to get the name of the sequence associated with
the serial type:

test(5432)aklaver=>\d serial_test
Table "public.serial_test"
Column | Type | Modifiers
--------+---------+----------------------------------------------------------
id | integer | not null default nextval('serial_test_id_seq'::regclass)
fld_1 | text |

Then go here:
http://www.postgresql.org/docs/9.0/interactive/functions-sequence.html

and use one of the setval() functions to set the sequence start to 1000.

Note: This is assuming the table is empty and you will not have any id
collisions.

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Allan Kamau 2011-03-14 15:35:43 Re: Primary key
Previous Message roopal oswal 2011-03-14 15:25:19 Re: