Re: SERIAL type not autoincremented - Mailing list pgsql-admin

From Radu-Adrian Popescu
Subject Re: SERIAL type not autoincremented
Date
Msg-id 40E5C188.7010005@aldratech.com
Whole thread Raw
In response to Re: SERIAL type not autoincremented  (teknet@poczta.onet.pl)
List pgsql-admin
teknet@poczta.onet.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


pgsql-admin by date:

Previous
From: Christopher Browne
Date:
Subject: Re: Dumping partial database content
Next
From: Bruno Wolff III
Date:
Subject: Re: SERIAL type not autoincremented