pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-bugs@postgresql.org <pgsql-bugs@postgresql.org>
Subject: Re: Deferrable constraint execution not respecting "initially immediate"?
Date: Mon, 10 Jul 2017 13:25:10 -0400
Message-ID: <4338.1499707510@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwZtwM2ySOHsjTouHuY=ogWqatsaJ50pbQUU6PSkgKd6-A@mail.gmail.com>
References: <CAKFQuwZtwM2ySOHsjTouHuY=ogWqatsaJ50pbQUU6PSkgKd6-A@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Mon, Jul 10, 2017 at 9:25 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> The solution for that is documented: declare the unique constraint as
>> deferrable.
>> 
>> regression=# CREATE TABLE T_UNIK (ID INT UNIQUE deferrable );
>> CREATE TABLE
>> regression=# INSERT INTO T_UNIK VALUES (1), (2), (3), (4), (5);
>> INSERT 0 5
>> regression=# UPDATE T_UNIK SET ID = ID + 1;
>> UPDATE 5

> ​I was expecting the above to require a "set constraints deferred" since
> "initially immediate" is the default.

Right, but "deferrable initially immediate" still means "at the end of the
statement", not "after each row".  "deferrable initially deferred" means
"at the end of the transaction".  In this example there's no real
difference between those two behaviors.

> From "CREATE TABLE":
> "A constraint that is not deferrable will be checked immediately after
> every command."

> I think the above should be "after every row" instead of "after every
> command".

I believe that FK constraints work differently from indexes in this
regard.  Not sure that we want to get into that level of detail here.

			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 (3+ messages)  latest in thread

Message-ID: <4338.1499707510@sss.pgh.pa.us>
Permalink:  ../4338.1499707510@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/4338.1499707510@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, david.g.johnston@gmail.com
  Subject: Re: Deferrable constraint execution not respecting "initially immediate"?
  In-Reply-To: <4338.1499707510@sss.pgh.pa.us>
  References: <CAKFQuwZtwM2ySOHsjTouHuY=ogWqatsaJ50pbQUU6PSkgKd6-A@mail.gmail.com> <4338.1499707510@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