Re: Deferred constraint trigger semantics

From: Bryn Llewellyn <bryn(at)yugabyte(dot)com>
To: alias <postgres(dot)rocks(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, pgsql-general list <pgsql-general(at)lists(dot)postgresql(dot)org>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Subject: Re: Deferred constraint trigger semantics
Date: 2022-05-12 18:40:27
Message-ID: F7A532E2-5876-4C7F-9F42-4C2C0BE78578@yugabyte.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> postgres(dot)rocks(at)gmail(dot)com wrote:
>
> It adds the "initially deferred" decoration to the "create constraint trigger" statement. This is (still) the result:
>
> INFO: trg fired. new.v = 10, n = 5
> INFO: trg fired. new.v = 20, n = 5
> INFO: trg fired. new.v = 30, n = 5
> INFO: trg fired. new.v = 40, n = 5
> INFO: trg fired. new.v = 50, n = 5
> INFO: trg fired. new.v = 60, n = 8
> INFO: trg fired. new.v = 70, n = 8
> INFO: trg fired. new.v = 80, n = 8
> Because You can do
> create constraint trigger trg
> after insert on t2
> deferrable initially deferred
> for each row
> execute function trg_fn();
>
> You didn't explicitly defer the trigger trg on t1!. That means after you insert on t1 then the trigger trg on t1 invoked rather than on commit time.
> If you
> create constraint trigger trg
> after insert on t1
> deferrable initially deferred
> for each row
> execute function trg_fn();
>
> create constraint trigger trg
> after insert on t2
> deferrable initially deferred
> for each row
> execute function trg_fn();
> then you will get
> INFO: 00000: trg fired. new.v = 10, n = 8
> INFO: 00000: trg fired. new.v = 20, n = 8
> INFO: 00000: trg fired. new.v = 30, n = 8
> INFO: 00000: trg fired. new.v = 40, n = 8
> INFO: 00000: trg fired. new.v = 50, n = 8
> INFO: 00000: trg fired. new.v = 60, n = 8
> INFO: 00000: trg fired. new.v = 70, n = 8
> INFO: 00000: trg fired. new.v = 80, n = 8

Er… yes. David Johnston pointed that out too. I'm embarrassed beyond belief. Sorry to have wasted folks' time because of my mistake.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2022-05-12 18:44:27 Re: Restricting user to see schema structure
Previous Message Bryn Llewellyn 2022-05-12 18:29:59 Re: Restricting user to see schema structure