pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Radu-Adrian Popescu <radu.popescu@aldratech.com>
To: teknet@poczta.onet.pl
Cc: pgsql-admin@postgresql.org
Subject: Re: SERIAL type not autoincremented
Date: Fri, 02 Jul 2004 23:11:52 +0300
Message-ID: <40E5C188.7010005@aldratech.com> (raw)
In-Reply-To: <20040702194010Z137290-15166+26852@kps2.test.onet.pl>
References: <20040702194010Z137290-15166+26852@kps2.test.onet.pl>

teknet@poczta.onet.pl wrote:
> i found the problem:
> 
>  
> 
> 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 explicitly put in 1:
	values(1,'myname')
and the second insert
	values('myname2')
	which is short for
	values(default, 'myname2')
gets the value for the ID column from the default (which is 
nextval('test2_id_seq')) and that's 1 too - there you go, unique constraint 
violation.

Remember, this is _not_ mysql, where autoincrement columns are implemented(or so 
I hear) by select max(column_in_question) + 1.

>  
> 
> Thanx
> 
> Michal
> 

Take care and do read/search the manual, it's quite good !
Regards,
-- 
Radu-Adrian Popescu
CSA, DBA, Developer
Aldrapay MD
Aldratech Ltd.
+40213212243




view thread (10+ messages)  latest in thread

Message-ID: <40E5C188.7010005@aldratech.com>
Permalink:  ../40E5C188.7010005@aldratech.com/
Also on:    postgresql.org/message-id/40E5C188.7010005@aldratech.com

 · 

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: radu.popescu@aldratech.com, teknet@poczta.onet.pl
  Subject: Re: SERIAL type not autoincremented
  In-Reply-To: <40E5C188.7010005@aldratech.com>
  References: <20040702194010Z137290-15166+26852@kps2.test.onet.pl> <40E5C188.7010005@aldratech.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