| From: | Philip Alger <paalger0(at)gmail(dot)com> |
|---|---|
| To: | Jim Jones <jim(dot)jones(at)uni-muenster(dot)de> |
| Cc: | Andrew Dunstan <andrew(at)dunslane(dot)net>, Cary Huang <cary(dot)huang(at)highgo(dot)ca>, jian he <jian(dot)universality(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: [PATCH] Add pg_get_trigger_ddl() to retrieve the CREATE TRIGGER statement |
| Date: | 2025-10-16 14:20:14 |
| Message-ID: | CAPXBC8KAxFD2yMA11PWZxMxpp0YKUvivkpVk1FfQZx7A7CS+2w@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Jim,
Appreciate the feedback!
> The function fails to look up triggers with quoted names
>
Not exactly. If you put "FOO" in the function pg_get_trigger_ddl('tbl',
'"FOO"') it will error because you don't need the double quotes. They are
already preserved. You just need the name, and pg_get_triggerdef works
similarly except with a plain OID.
postgres=# CREATE TRIGGER "π" BEFORE INSERT ON main_table FOR EACH
STATEMENT EXECUTE PROCEDURE trigger_func('modified_a');
postgres=# CREATE TRIGGER "FOO" BEFORE INSERT ON main_table FOR EACH
STATEMENT EXECUTE PROCEDURE trigger_func('modified_a');
postgres=# select tgname, oid from pg_trigger;
tgname | oid
--------------+-------
π | 16397
FOO | 16498
(it does work if we omit the double quotes)
>
Right, the double quote does show up in the result. We aren't removing it.
postgres=# SELECT pg_get_trigger_ddl('main_table', 'π');
pg_get_trigger_ddl
------------------------------------------------------------------------------------------------------------------------
CREATE TRIGGER "π" BEFORE INSERT ON public.main_table FOR EACH STATEMENT
EXECUTE FUNCTION trigger_func('modified_a');
(1 row)
pg_get_viewdef() sees it differently (opposite approach)
>
That's true, and it's pretty strict. However, pg_get_trigger_ddl seems more
intuitive since it can return the statement whether the trigger is quoted
or unquoted without the user thinking about adding quotes.
--
Best,
Phil Alger
| From | Date | Subject | |
|---|---|---|---|
| Next Message | jian he | 2025-10-16 14:22:52 | Re: pg_restore --no-policies should not restore policies' comment |
| Previous Message | Peter Eisentraut | 2025-10-16 13:46:30 | Re: Built-in case-insensitive collation pg_unicode_ci |