Re: SERIAL type not autoincremented

Поиск
Список
Период
Сортировка
От Radu-Adrian Popescu
Тема Re: SERIAL type not autoincremented
Дата
Msg-id 40E5C188.7010005@aldratech.com
обсуждение исходный текст
Ответ на Re: SERIAL type not autoincremented  (teknet@poczta.onet.pl)
Список 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 по дате отправления:

Предыдущее
От: Christopher Browne
Дата:
Сообщение: Re: Dumping partial database content
Следующее
От: Bruno Wolff III
Дата:
Сообщение: Re: SERIAL type not autoincremented