pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: teknet@poczta.onet.pl
Cc: pgsql-admin@postgresql.org
Subject: Re: SERIAL type not autoincremented
Date: Fri, 2 Jul 2004 15:36:23 -0500
Message-ID: <20040702203623.GA3839@wolff.to> (raw)
In-Reply-To: <20040702194010Z137290-15166+26852@kps2.test.onet.pl>
References: <200407021131.57987.mike@nachbaur.com>
	<20040702194010Z137290-15166+26852@kps2.test.onet.pl>

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.



view thread (10+ messages)

Message-ID: <20040702203623.GA3839@wolff.to>
Permalink:  ../20040702203623.GA3839@wolff.to/
Also on:    postgresql.org/message-id/20040702203623.GA3839@wolff.to

 · 

reply

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: bruno@wolff.to, teknet@poczta.onet.pl
  Subject: Re: SERIAL type not autoincremented
  In-Reply-To: <20040702203623.GA3839@wolff.to>
  References: <200407021131.57987.mike@nachbaur.com> <20040702194010Z137290-15166+26852@kps2.test.onet.pl> <20040702203623.GA3839@wolff.to>

* 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