Re: SERIAL type not autoincremented

From: "Larry Rosenman" <ler(at)lerctr(dot)org>
To: <teknet(at)poczta(dot)onet(dot)pl>, <pgsql-admin(at)postgresql(dot)org>
Subject: Re: SERIAL type not autoincremented
Date: 2004-07-02 20:30:54
Message-ID: E1BgUgz-0004RH-7J@lerami.lerctr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

teknet(at)poczta(dot)onet(dot)pl wrote:
> i found the problem:
>
>
>
> sys=> create table test2(
> sys(> id serial,
> sys(> name varchar(10),
> sys(> primary key(id)
> sys(> );
> NOTICE: CREATE TABLE will create implicit sequence "test2_id_seq"
> for "serial" column "test2.id"
> NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index
> "test2_pkey" for table "test2"
> CREATE TABLE
> sys=> insert into test2 values(1,'myname'); INSERT 18765 1 sys=>
> insert into test2 (name) values('myname2'); ERROR: duplicate key
> violates unique constraint "test2_pkey"
> sys=>
>
>
> Why is it so ?
>
>
>
> Thanx
>
> Michal

Because you didn't let the serial column do it's magic.

Try:

Insert into test2(name) values('myname');
Insert into test2(name) values('myname2');

That should work.

Always let a serial column pick the number.

LER

--
Larry Rosenman http://www.lerctr.org/~ler
Phone: +1 972-414-9812 E-Mail: ler(at)lerctr(dot)org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Mike Rylander 2004-07-02 20:32:02 Re: SERIAL type not autoincremented
Previous Message Christopher Browne 2004-07-02 20:19:01 Re: SERIAL type not autoincremented