Re: Re: Failed Statements within Transactions - Mailing list pgsql-general

From Tom Lane
Subject Re: Re: Failed Statements within Transactions
Date
Msg-id 2344.978158285@sss.pgh.pa.us
Whole thread Raw
In response to Re: Re: Failed Statements within Transactions  (Mike Mascari <mascarm@mascari.com>)
List pgsql-general
Mike Mascari <mascarm@mascari.com> writes:
> How about:
> INSERT INTO foo SELECT 1, 'Hello' WHERE NOT EXISTS (SELECT
> key FROM foo WHERE key = 1);

Cute idea, but it doesn't eliminate the race-condition problem.
If two backends execute this code concurrently, both will find
that the subselect returns no rows, and both will try to do the
INSERT.  If you have a unique index on the table, then one will
succeed and the other will get an error (after waiting to see
if the first commits or not).

There's no doubt that savepoints within transactions would be a
good improvement to Postgres, and I believe Vadim has hopes of
making that happen in 7.2 or 7.3.  But in the meantime, transactions
without savepoints are a lot better than "transactions" that fail to
notice errors at all.  Any MySQL partisans who contend otherwise
just plain Don't Get It.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: authenticating local users
Next
From:
Date:
Subject: How to get the MOST out of a database?