I have a (probably generic) problem: a table like
create table a (
unique( foo, bar ) );
From a PHP script, I do an INSERT and then check by the return value
of pg_exec() function whether the insert failed because the entry
already exists. The problem is that the sequence on the 'id' field
gets incremented even if the insert fails.
What's the typical way of addressing this problem?
I thought about doing a SELECT, and then INSERT only if the SELECT
returns 0 rows. But then there is a possibility that in between the
SELECT and INSERT queries some other client will do an INSERT on the
same values, and then my INSERT will fail (again, incrementing the
Many thanks for any input,
Nostalgia isn't what it used to be.
pgsql-novice by date
|Next:||From: Arcady Genkin||Date: 2001-03-10 12:27:28|
|Subject: Not incrementing the 'serial' counter on failed inserts.|
|Previous:||From: wsmuir||Date: 2001-03-10 02:45:00|
|Subject: look-up cache failures|