Re: [PATCH] Add pg_get_trigger_ddl() to retrieve the CREATE TRIGGER statement

From: Philip Alger <paalger0(at)gmail(dot)com>
To: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
Cc: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>, 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-19 19:30:04
Message-ID: CAPXBC8J-VU86hkh+1_x-s933CtSfsyoBf3fgWuvNrQ+AErjY=g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Marcos,

> In a multi tenant world this feature will be cool for clone or sync ddl of
> two schemas. So, if I’m creating a new schema the way you did works but if
> both exists and I want to update some ddls of a schema, sometimes I have to
> DROP and CREATE or returned command should have CREATE OR REPLACE,
> depending on what ddl you are doing.
>
If you try to create a trigger but it already exists, you’ll get an
> exception, so you can emit a DROP IF EXISTS before CREATE of that trigger.
> For this that param drop_first would be.
> I know you are doing only trigger ddl rigth now but I think we would have
> this kind of functions for tables, constraints, triggers, domains and so
> on, then all of them should work the same way, and for this a drop_first or
> if_exists would be good.
>

Thanks for the feedback.

That makes sense, and you're right, for the 'multi-tenant sync' use case
you're describing, just having the CREATE statement will cause an 'object
exists' error. The way I've scoped this particular function is more
general. That drop_first feature is great for a sync script, but the core
idea here is just to retrieve the DDL text. It's up to the developer using
it to decide how to implement it (like adding a DROP first).

--
Best,
Phil Alger

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message David E. Wheeler 2025-10-19 20:37:42 Re: abi-compliance-check failure due to recent changes to pg_{clear,restore}_{attribute,relation}_stats()
Previous Message David E. Wheeler 2025-10-19 18:58:36 Re: [PATCH] random_normal function