Getting "duplicate key value violates unique constraint" on 2nd run of function.

From: David Kerr <dmk(at)mr-paradox(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Getting "duplicate key value violates unique constraint" on 2nd run of function.
Date: 2009-11-25 22:19:09
Message-ID: 20091125221908.GA13237@mr-paradox.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Howdy all.

I've got a function that basically does this:

DELETE FROM test where id = $1
INSERT into test (id) values ($1);

id is the primay key, so it has to be unique.

First time I run it, works great.

If I run it again in the same session, I get
ERROR: duplicate key value violates unique constraint "test_pkey"

If I log out and then log back in, it runs fine again (the first time).

Is there some setting for the function that I need to set to make this run correctly
every time?

Thanks

Dave

Responses

Browse pgsql-general by date

  From Date Subject
Next Message akp geek 2009-11-25 22:24:52 Re: pg_standby instructions
Previous Message Bruno Lavoie 2009-11-25 21:03:51 Re: limiting resources to users