Re: Cannot insert dup id in pk

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Scott Cain <cain(at)cshl(dot)org>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Cannot insert dup id in pk
Date: 2003-07-15 15:25:59
Message-ID: 22800.1058282759@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Scott Cain <cain(at)cshl(dot)org> writes:
> Note that I do not try to insert anything into fid, the primary key on
> this table. Why does Postgres think I am?

But you *are* trying to insert something into fid, namely the default
value:
default nextval('public.fdata _fid_seq'::text)

My guess is that you have been inconsistent about whether you used the
sequence or explicit assignment to fid, and now you have some rows in
the table that have fid values higher than the current sequence value.

I'd suggest adjusting the sequence, along the lines of

SELECT setval('public.fdata _fid_seq', max(fid)+1) FROM fdata;

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Viorel Dragomir 2003-07-15 15:32:07 Re: summing tables
Previous Message Tom Lane 2003-07-15 15:17:35 Re: Non-Blocking Locks (i.e. Oracle NOWAIT)