pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Larry Rosenman <ler@lerctr.org>
To: teknet@poczta.onet.pl
To: pgsql-admin@postgresql.org
Subject: Re: SERIAL type not autoincremented
Date: Fri, 2 Jul 2004 15:30:54 -0500
Message-ID: <E1BgUgz-0004RH-7J@lerami.lerctr.org> (raw)
In-Reply-To: <20040702194010Z137290-15166+26852@kps2.test.onet.pl>

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 ?
> 
> 
> 
> Thanx
> 
> Michal

Because you didn't let the serial column do it's magic. 

Try:

Insert into test2(name) values('myname');
Insert into test2(name) values('myname2');

That should work. 

Always let a serial column pick the number. 

LER


-- 
Larry Rosenman                     http://www.lerctr.org/~ler
Phone: +1 972-414-9812                 E-Mail: ler@lerctr.org
US Mail: 1905 Steamboat Springs Drive, Garland, TX 75044-6749





view thread (10+ messages)  latest in thread

Message-ID: <E1BgUgz-0004RH-7J@lerami.lerctr.org>
Permalink:  ../E1BgUgz-0004RH-7J@lerami.lerctr.org/
Also on:    postgresql.org/message-id/E1BgUgz-0004RH-7J@lerami.lerctr.org

 · 

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: ler@lerctr.org, teknet@poczta.onet.pl
  Subject: Re: SERIAL type not autoincremented
  In-Reply-To: <E1BgUgz-0004RH-7J@lerami.lerctr.org>
  References: <20040702194010Z137290-15166+26852@kps2.test.onet.pl> <E1BgUgz-0004RH-7J@lerami.lerctr.org>

* 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