Re: SERIAL type not autoincremented

From: Michael A Nachbaur <mike(at)nachbaur(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 18:31:57
Message-ID: 200407021131.57987.mike@nachbaur.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

The serial datatype creates a sequence in the background. So, in your
example, you'll have a sequence called "student_id_seq". Your sequence was
probably reset, dropped/created, or whatever, to cause it to feed IDs back
that already exist in your table.

On July 2, 2004 10:22 am, teknet(at)poczta(dot)onet(dot)pl wrote:
> Hello
> i have:
> create table student(
> id SERIAL NOT NULL,
> name VARCHAR(35) NOT NULL,
> primary key (id)
> );
>
> and when i try to insert like this:
> insert into student (name) values('me');
> i receive error:
> ERROR: duplicate key violates unique constraint "student_pkey"
>
> Why ? Do i understeand correctly that SERIAL == AUTO_INCREMENT ?
> As far as i remember i used such type in the past and had no problem.
> What do i miss ?
>
> Thanx
> Michal
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend

--
Michael A. Nachbaur <mike(at)nachbaur(dot)com>
http://nachbaur.com/pgpkey.asc

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Edoardo Ceccarelli 2004-07-02 18:50:26 finding a max value
Previous Message Bruno Wolff III 2004-07-02 18:21:09 Re: SERIAL type not autoincremented