Re: Rename of triggers for partitioned tables

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Arne Roland <A(dot)Roland(at)index(dot)de>
Cc: David Steele <david(at)pgmasters(dot)net>, Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Rename of triggers for partitioned tables
Date: 2021-03-29 13:25:36
Message-ID: 20210329132536.GA9798@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2021-Mar-29, Arne Roland wrote:

> @@ -1475,7 +1467,12 @@ renametrig(RenameStmt *stmt)
> tuple = heap_copytuple(tuple); /* need a modifiable copy */
> trigform = (Form_pg_trigger) GETSTRUCT(tuple);
> tgoid = trigform->oid;
> -
> + if (tgparent != 0 && tgparent != trigform->tgparentid) {
> + ereport(ERROR,
> + errmsg("trigger \"%s\" for table \"%s\" is not dependent on the trigger on \"%s\"",
> + stmt->subname, RelationGetRelationName(targetrel), stmt->relation->relname)));
> + }

I think this is not what we want to do. What you're doing here as I
understand is traversing the inheritance hierarchy down using the
trigger name, and then fail if the trigger with that name has a
different parent or if no trigger with that name exists in the child.

What we really want to have happen, is to search the list of triggers in
the child, see which one has tgparentid=<the one we're renaming>, and
rename that one -- regardless of what name it had originally.

Also, you added grammar support for the ONLY keyword in the command, but
it doesn't do anything different when given that flag, does it? At
least, I see no change or addition to recursion behavior in ATExecCmd.
I would expect that if I say "ALTER TRIGGER .. ON ONLY tab" then it
renames the trigger on table "tab" but not on its child tables; only if
I remove the ONLY from the command it recurses.

I think it would be good to have a new test for pg_dump that verifies
that this stuff is doing the right thing.

Álvaro Herrera 39°49'30"S 73°17'W
"Siempre hay que alimentar a los dioses, aunque la tierra esté seca" (Orual)

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Ashutosh Bapat 2021-03-29 13:26:59 Re: UniqueKey on Partitioned table.
Previous Message Matthias van de Meent 2021-03-29 13:18:37 Re: Calendar support in localization