Re: Deferrable constraint execution not respecting "initially immediate"?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: Deferrable constraint execution not respecting "initially immediate"?
Date: 2017-07-10 17:25:10
Message-ID: 4338.1499707510@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Mon, Jul 10, 2017 at 9:25 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter J. Holzer 2017-07-10 20:17:15 Re: [HACKERS] Postgres process invoking exit resulting in sh-QUIT core
Previous Message David G. Johnston 2017-07-10 17:00:23 Deferrable constraint execution not respecting "initially immediate"?