Re: Rename of triggers for partitioned tables - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: Rename of triggers for partitioned tables
Date
Msg-id 20210329132536.GA9798@alvherre.pgsql
Whole thread Raw
In response to Re: Rename of triggers for partitioned tables  (Arne Roland <A.Roland@index.de>)
Responses Re: Rename of triggers for partitioned tables
List 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,
> +                    (errcode(ERRCODE_UNDEFINED_OBJECT),
> +                     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)



pgsql-hackers by date:

Previous
From: Matthias van de Meent
Date:
Subject: Re: Calendar support in localization
Next
From: Ashutosh Bapat
Date:
Subject: Re: UniqueKey on Partitioned table.