From: | Radu-Adrian Popescu <radu(dot)popescu(at)aldratech(dot)com> |
---|---|
To: | teknet(at)poczta(dot)onet(dot)pl |
Cc: | pgsql-admin(at)postgresql(dot)org |
Subject: | Re: SERIAL type not autoincremented |
Date: | 2004-07-02 20:11:52 |
Message-ID: | 40E5C188.7010005@aldratech.com |
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=> 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 explicitly put in 1:
values(1,'myname')
and the second insert
values('myname2')
which is short for
values(default, 'myname2')
gets the value for the ID column from the default (which is
nextval('test2_id_seq')) and that's 1 too - there you go, unique constraint
violation.
Remember, this is _not_ mysql, where autoincrement columns are implemented(or so
I hear) by select max(column_in_question) + 1.
>
>
> Thanx
>
> Michal
>
Take care and do read/search the manual, it's quite good !
Regards,
--
Radu-Adrian Popescu
CSA, DBA, Developer
Aldrapay MD
Aldratech Ltd.
+40213212243
From | Date | Subject | |
---|---|---|---|
Next Message | Christopher Browne | 2004-07-02 20:19:01 | Re: SERIAL type not autoincremented |
Previous Message | teknet | 2004-07-02 19:40:02 | Re: SERIAL type not autoincremented |