Re: Problems inserting data into a table with a sequence

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: RNG <rgasch(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Problems inserting data into a table with a sequence
Date: 2007-10-15 22:59:17
Message-ID: 26029.1192489157@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

RNG <rgasch(at)gmail(dot)com> writes:
> Trying to insert data into this table using the following SQL
> ...
> gives us the following error:
> ERROR: duplicate key violates unique constraint "pn_categories_category_pkey"

Usually the reason for this is that you inserted some rows with manually
assigned serial numbers (perhaps a COPY from an old version of the
table?) and forgot to advance the sequence past those numbers. Try
something like

SELECT setval('pn_categories_category_cat_id_seq',
(SELECT MAX(cat_id) + 1 FROM pn_categories_category));

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2007-10-16 01:21:53 Re: Convert bytea to Float8
Previous Message RNG 2007-10-15 21:58:46 Problems inserting data into a table with a sequence