Tom Lane wrote:
>
> That doesn't really buy anything in safety terms: if two backends
> execute this sort of command concurrently, it's perfectly likely
> that both sub-SELECTS will find no row matching 'v1', and so they'll
> both try the INSERT anyway.
I wasn't looking for safety so much as avoiding the insert if possible.
I've just finished a long thread about this and the consensus was that
this query would be:
1- the insert would always happen if there was no record with the same
primary key
2- is concurrency safe. Even if this query is executed by multiple
backends at the same time one will always succeed.
The reason I had asked for a query that could check before insert was to
reduce the number of log errors the phpOpenTracker tool generates from
trying to insert duplicate records into a table.
The above would reduce (but not eliminate) the number attempts to insert
duplicates and as such reduce the number of log error entries.
At least that's what I am hoping for ...
Jean-Christian Imbeault