From: Mike Rylander <miker@purplefrog.com>
To: pgsql-admin@postgresql.org
Subject: Re: SERIAL type not autoincremented
Date: Fri, 02 Jul 2004 16:32:02 -0400
Message-ID: <cc4hm8$14d0$1@news.hub.org> (raw)
References: <20040702194010Z137290-15166+26852@kps2.test.onet.pl>
<E1BgUgz-0004RH-7J@lerami.lerctr.org>
Larry Rosenman wrote:
> teknet@poczta.onet.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.
Or, if you must specify the column, specify DEFAULT for the value:
INSERT INTO test2 (id,name) values (DEFAULT,'myname3');
>
> LER
>
>
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-admin@postgresql.org
Cc: miker@purplefrog.com
Subject: Re: SERIAL type not autoincremented
In-Reply-To: <cc4hm8$14d0$1@news.hub.org>
References: <20040702194010Z137290-15166+26852@kps2.test.onet.pl> <E1BgUgz-0004RH-7J@lerami.lerctr.org> <cc4hm8$14d0$1@news.hub.org>
* 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