agora inbox for pgsql-hackers@postgresql.org
help / color / mirror / Atom feedFrom: Justin Pryzby <pryzbyj@telsasoft.com>
Subject: [PATCH] WIP: fix detaching tables with inherited triggers
Date: Fri, 3 Apr 2020 22:43:26 -0500
---
src/backend/commands/tablecmds.c | 33 ++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 037d457c3d..10a60e158f 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -16797,6 +16797,39 @@ ATExecDetachPartition(Relation rel, RangeVar *name)
}
table_close(classRel, RowExclusiveLock);
+ /* detach triggers too */
+ {
+ /* XXX: relcache.c */
+ ScanKeyData skey;
+ SysScanDesc scan;
+ HeapTuple trigtup;
+ Relation tgrel = table_open(TriggerRelationId, RowExclusiveLock);
+
+ ScanKeyInit(&skey, Anum_pg_trigger_tgrelid, BTEqualStrategyNumber,
+ F_OIDEQ, ObjectIdGetDatum(RelationGetRelid(partRel)));
+
+ scan = systable_beginscan(tgrel, TriggerRelidNameIndexId,
+ true, NULL, 1, &skey);
+
+ while (HeapTupleIsValid(trigtup = systable_getnext(scan)))
+ {
+ Form_pg_trigger pg_trigger;
+ trigtup = heap_copytuple(trigtup); /* need a modifiable copy */
+ pg_trigger = (Form_pg_trigger) GETSTRUCT(trigtup);
+ /* Set the trigger's parent to Invalid */
+ if (!OidIsValid(pg_trigger->tgparentid))
+ continue;
+ if (!pg_trigger->tgisinternal)
+ continue;
+ pg_trigger->tgparentid = InvalidOid;
+ pg_trigger->tgisinternal = false;
+ CatalogTupleUpdate(tgrel, &trigtup->t_self, trigtup);
+ heap_freetuple(trigtup);
+ }
+ systable_endscan(scan);
+ table_close(tgrel, RowExclusiveLock);
+ }
+
/*
* Detach any foreign keys that are inherited. This includes creating
* additional action triggers.
--
2.17.0
--STPqjqpCrtky8aYs--
view thread (2+ messages) latest in thread
Message-ID: <no-message-id-704644@localhost>
Permalink: ../../no-message-id-704644@localhost/
Also on: postgresql.org/message-id/no-message-id-704644@localhost
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 using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: pryzbyj@telsasoft.com
Subject: Re: [PATCH] WIP: fix detaching tables with inherited triggers
In-Reply-To: <no-message-id-704644@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox