Re: Atomicity?

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Martijn van Oosterhout <kleptog(at)svana(dot)org>, Naz Gassiep <naz(at)mira(dot)net>, Michael Glaesemann <grzm(at)seespotcode(dot)net>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: Atomicity?
Date: 2006-08-28 23:21:57
Message-ID: 200608282321.k7SNLvu21171@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Tom Lane wrote:
> Martijn van Oosterhout <kleptog(at)svana(dot)org> writes:
> > Sure, UNIQUE constraints are not deferrable. With normal constraints
> > you can defer the check until the end of transaction and be in an
> > inconsistant state for while. However, PostgreSQL doesn't support this
> > for uniqueness checks.
>
> Actually, what the spec says is (SQL92 4.10.1)
>
> The checking of a constraint depends on its constraint mode within
> the current SQL-transaction. If the constraint mode is immedi-
> ate, then the constraint is effectively checked at the end of
> each SQL-statement. If the constraint mode is deferred, then the
> constraint is effectively checked when the constraint mode is
> changed to immediate either explicitly by execution of a <set con-
> straints mode statement>, or implicitly at the end of the current
> SQL-transaction.
>
> So even for a non-deferred unique constraint, it should be legal to
> update multiple rows to new non-conflicting values within a single
> UPDATE command. Plus, as Martijn says, we have no support at all
> for the defer-to-end-of-transaction case.
>
> We've discussed this before, and I thought it was on the TODO list,
> but AFAICS the only entry there is
>
> * Allow DEFERRABLE UNIQUE constraints?
>
> which is misfiled under "Triggers" and doesn't cover the existing
> spec violation anyway. Bruce?

TODO updated:

* Allow DEFERRABLE and end-of-statement UNIQUE constraints?

This would allow UPDATE tab SET col = col + 1 to work if col has
a unique index. Currently, uniqueness checks are done while the
command is being executed, rather than at the end of the statement
or transaction.

and moved to "referential integrity" section.

--
Bruce Momjian bruce(at)momjian(dot)us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2006-08-28 23:23:05 Re: Atomicity?
Previous Message Scott Marlowe 2006-08-28 22:36:08 Re: Postgresql mentioned on Newsforge MySQL article