From: Tom Lane <tgl@sss.pgh.pa.us>
To: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: Emanuel Araújo <eacshm@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: disable and enable trigger all when a foreign keys
Date: Fri, 12 Jul 2019 10:43:13 -0400
Message-ID: <28189.1562942593@sss.pgh.pa.us> (raw)
In-Reply-To: <92dd264a-d273-a057-1c1b-3bf419235232@aklaver.com>
References: <CAMuTAkaqysXHaGgQH3NBv-Rh-01RDGJQEz6wyuGBpu+Y1kDNxQ@mail.gmail.com>
<26583.1562940265@sss.pgh.pa.us>
<92dd264a-d273-a057-1c1b-3bf419235232@aklaver.com>
Adrian Klaver <adrian.klaver@aklaver.com> writes:
> On 7/12/19 7:04 AM, Tom Lane wrote:
>> Well, yeah, DISABLE TRIGGER ALL defeats enforcement of FK constraints.
>> That's why you have to be superuser to use it[1].
> The OP is probably trying to understand why the below happens:
> alter table a add constraint a_id_b_fkey foreign key (id_b) references
> b(id);
> ERROR: insert or update on table "a" violates foreign key constraint
> "a_id_b_fkey"
> DETAIL: Key (id_b)=(3) is not present in table "b".
> Versus the above not happening when you re-enable a trigger.
Well, because ALTER ... ENABLE TRIGGER does what it says on the tin: it
re-enables firing of the trigger. That means future inserts and updates
will be checked; it doesn't extend to somehow checking events for which
trigger firings didn't happen in the past.
The OP already found the best method to get out of this, which is to
drop and re-add the FK constraint. Adding the constraint will force
a full verification scan, which is what you need here since there's
no information available about which checks were missed.
regards, tom lane
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-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, adrian.klaver@aklaver.com, eacshm@gmail.com
Subject: Re: disable and enable trigger all when a foreign keys
In-Reply-To: <28189.1562942593@sss.pgh.pa.us>
References: <CAMuTAkaqysXHaGgQH3NBv-Rh-01RDGJQEz6wyuGBpu+Y1kDNxQ@mail.gmail.com> <26583.1562940265@sss.pgh.pa.us> <92dd264a-d273-a057-1c1b-3bf419235232@aklaver.com> <28189.1562942593@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