On 2019-Feb-09, Tom Lane wrote: > Amit Langote <amitlangot...@gmail.com> writes: > > On Sat, Feb 9, 2019 at 9:41 AM Tom Lane <t...@sss.pgh.pa.us> wrote: > >> +1. The best solution would presumably be to go through the normal > >> object deletion mechanism; though possibly there's a reason that > >> won't work given you're already inside some other DDL. > > > Maybe: > > - CatalogTupleDelete(trigrel, &trigtup->t_self); > > + RemoveTriggerById(trgform->oid)? > > No, that's still the back end of the deletion machinery, and in particular > it would fail to clean pg_depend entries for the trigger. Going in by the > front door would use performDeletion(). (See deleteOneObject() to get > an idea of what's being possibly missed out here.)
This patch I think does the right thing. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
commit 7031ce2b1f79a2e03b29ac896f0a008b0621d654 Author: Alvaro Herrera <alvhe...@alvh.no-ip.org> AuthorDate: Sat Feb 9 12:31:25 2019 -0300 CommitDate: Sat Feb 9 12:53:00 2019 -0300 fix trigger drop diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 910e5deaa3f..923866b7e11 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8024,17 +8024,21 @@ CloneFkReferencing(Relation pg_constraint, Relation parentRel, while ((trigtup = systable_getnext(scan)) != NULL) { Form_pg_trigger trgform = (Form_pg_trigger) GETSTRUCT(trigtup); + ObjectAddress trigger; if (trgform->tgconstrrelid != fk->conrelid) continue; if (trgform->tgrelid != fk->confrelid) continue; - deleteDependencyRecordsForClass(TriggerRelationId, - HeapTupleGetOid(trigtup), - ConstraintRelationId, - DEPENDENCY_INTERNAL); - CatalogTupleDelete(trigrel, &trigtup->t_self); + deleteDependencyRecordsFor(TriggerRelationId, + HeapTupleGetOid(trigtup), + false); + /* make dependency deletion visible to performDeletion */ + CommandCounterIncrement(); + ObjectAddressSet(trigger, TriggerRelationId, + HeapTupleGetOid(trigtup)); + performDeletion(&trigger, DROP_RESTRICT, 0); } systable_endscan(scan);