Re: SERIAL type does not generate new ID ? - Mailing list pgsql-sql

From Ed Loehr
Subject Re: SERIAL type does not generate new ID ?
Date
Msg-id 396A113A.CEDC8733@austin.rr.com
Whole thread Raw
In response to SERIAL type does not generate new ID ?  ("Jean-Marc Libs" <jean-marc.libs@obs.coe.int>)
List pgsql-sql
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


pgsql-sql by date:

Previous
From: "Jean-Marc Libs"
Date:
Subject: SERIAL type does not generate new ID ?
Next
From: Shalini shikha
Date:
Subject: problem with date