From: Michael A Nachbaur <mike@nachbaur.com>
To: teknet@poczta.onet.pl
Cc: pgsql-admin@postgresql.org
Subject: Re: SERIAL type not autoincremented
Date: Fri, 2 Jul 2004 11:31:57 -0700
Message-ID: <200407021131.57987.mike@nachbaur.com> (raw)
In-Reply-To: <20040702172227Z4873738-14310+28550@kps5.test.onet.pl>
References: <20040702172227Z4873738-14310+28550@kps5.test.onet.pl>
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@poczta.onet.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@nachbaur.com>
http://nachbaur.com/pgpkey.asc
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: mike@nachbaur.com, teknet@poczta.onet.pl
Subject: Re: SERIAL type not autoincremented
In-Reply-To: <200407021131.57987.mike@nachbaur.com>
References: <20040702172227Z4873738-14310+28550@kps5.test.onet.pl> <200407021131.57987.mike@nachbaur.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox