Re: SERIAL type not autoincremented

Поиск
Список
Период
Сортировка
От Bruno Wolff III
Тема Re: SERIAL type not autoincremented
Дата
Msg-id 20040702203623.GA3839@wolff.to
обсуждение исходный текст
Ответ на Re: SERIAL type not autoincremented  (teknet@poczta.onet.pl)
Список pgsql-admin
On Fri, Jul 02, 2004 at 21:40:02 +0200,
  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 ?

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.

В списке pgsql-admin по дате отправления:

Предыдущее
От: Radu-Adrian Popescu
Дата:
Сообщение: Re: SERIAL type not autoincremented
Следующее
От: "Larry Rosenman"
Дата:
Сообщение: Re: SERIAL type not autoincremented