On Fri, Jul 02, 2004 at 21:40:02 +0200, [EMAIL PROTECTED] 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 ?
Because you are inserting records without using the sequence. The serial type is really a short cut for specifying that the default value is the value of a sequence created for that column. If you insert records without using the default, then you also need to set the value of the sequence higher than the largest value so far. You can use the setval function to do this. ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives? http://archives.postgresql.org