pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Claudio Nieder <claudio.nieder.lists@inodes.ch>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #10429: the same update return different result
Date: Fri, 23 May 2014 15:34:05 -0400
Message-ID: <6125.1400873645@sss.pgh.pa.us> (raw)
In-Reply-To: <CB2BE94E-FEE1-4E0D-94A8-547CFF529853@inodes.ch>
References: <20140523074125.2687.92046@wrigleys.postgresql.org>
	<537F827F.8030303@ort.edu.uy>
	<CB2BE94E-FEE1-4E0D-94A8-547CFF529853@inodes.ch>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Claudio Nieder <claudio.nieder.lists@inodes.ch> writes:
>>> postgres=# update t1 set c1 = c1 +1;
>> This controls whether the constraint can be deferred. A constraint that is not deferrable will be checked immediately after every command.
>> 
> My understanding would have been, that "update t1 set c1=c1+1;" is ONE command, so even in the NOT DEFERRABLE case the check would occur only after both values were changed and as such not find any violation of the constraint. 

The important detail is a bit further down the page, in the
"Compatibility" section:

Non-deferred Uniqueness Constraints

When a UNIQUE or PRIMARY KEY constraint is not deferrable, PostgreSQL
checks for uniqueness immediately whenever a row is inserted or
modified. The SQL standard says that uniqueness should be enforced only at
the end of the statement; this makes a difference when, for example, a
single command updates multiple key values. To obtain standard-compliant
behavior, declare the constraint as DEFERRABLE but not deferred (i.e.,
INITIALLY IMMEDIATE). Be aware that this can be significantly slower than
immediate uniqueness checking.

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (4+ messages)

Message-ID: <6125.1400873645@sss.pgh.pa.us>
Permalink:  ../6125.1400873645@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/6125.1400873645@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, claudio.nieder.lists@inodes.ch
  Subject: Re: BUG #10429: the same update return different result
  In-Reply-To: <6125.1400873645@sss.pgh.pa.us>
  References: <20140523074125.2687.92046@wrigleys.postgresql.org> <537F827F.8030303@ort.edu.uy> <CB2BE94E-FEE1-4E0D-94A8-547CFF529853@inodes.ch> <6125.1400873645@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox