pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ed Loehr <eloehr@austin.rr.com>
To: jml@obs.coe.int
Cc: pgsql-sql@postgresql.org
Subject: Re: SERIAL type does not generate new ID ?
Date: Mon, 10 Jul 2000 13:08:58 -0500
Message-ID: <396A113A.CEDC8733@austin.rr.com> (raw)
References: <Pine.LNX.4.21.0006101911550.29725-100000@centaure.obs.coe.int>

Jean-Marc Libs wrote:
> 
> I have this table:
> 
> CREATE TABLE film (
>    film_id serial,
> ...
>
> SELECT setval ('film_film_id_seq', 6);
> 
> I have this query in PHP:
> insert into film
> (film_country_id,film_country_id2,film_country_id3,film_country_id4,film_prod_year,film_ec_certif,film_ce_certif,film_eur_support,film_media_support,film_provisoire) values ('FR','','','','2000','f','f','f','f','f')
> 
> And it gives the following error:
> ERROR: Cannot insert a duplicate key into a unique index

You should not have to do anything special with the serial or the
sequence (including setting it to 6).  Possible sources for for your
error:  1) you are resetting the sequence value to 6 when you already
have a row with that value for film_id in the table, or 2) could be the
message is coming from a triggered insert "downstream" from your initial
insert (see your server log).  BTW, 7.0+ tells you *which* index caused
the problem.

Regards,
Ed Loher



view thread (3+ messages)  latest in thread

Message-ID: <396A113A.CEDC8733@austin.rr.com>
Permalink:  ../396A113A.CEDC8733@austin.rr.com/
Also on:    postgresql.org/message-id/396A113A.CEDC8733@austin.rr.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-sql@postgresql.org
  Cc: eloehr@austin.rr.com, jml@obs.coe.int
  Subject: Re: SERIAL type does not generate new ID ?
  In-Reply-To: <396A113A.CEDC8733@austin.rr.com>
  References: <Pine.LNX.4.21.0006101911550.29725-100000@centaure.obs.coe.int> <396A113A.CEDC8733@austin.rr.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