Re: CREATE TABLE LIKE INCLUDING TRIGGERS

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: CREATE TABLE LIKE INCLUDING TRIGGERS
Date: 2025-12-29 01:26:06
Message-ID: CACJufxFu7Y4FhVkaKT2Kaj8ym2T5TcwN93cR_6h4x66iLrSZ-Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

hi.

in CreateTrigger, we have comments:

* relOid, if nonzero, is the relation on which the trigger should be
* created. If zero, the name provided in the statement will be looked up.
*
* refRelOid, if nonzero, is the relation to which the constraint trigger
* refers. If zero, the constraint relation name provided in the statement
* will be looked up as needed.

We can put these two parameters into the CreateTrigStmt.
change it from
CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid,
Oid funcoid, Oid parentTriggerOid, Node *whenClause,
bool isInternal, bool in_partition)
to:

CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
Oid constraintOid, Oid indexOid,
Oid funcoid, Oid parentTriggerOid, Node *whenClause,
bool isInternal, bool in_partition)

This is needed, ProcessUtilitySlow->CreateTrigger don't have the new
target table relation OID information, using CreateTrigStmt.relation
would cause repeated name lookup issue.

v3-0001 and v3-0002 refactor the CreateTrigger function.
The parameters relOid and refRelOid are removed and instead added to the
CreateTrigStmt structure.

These two patch (v3-0001, v3-0002) will also be used in [1]
[1]: https://postgr.es/m/CACJufxGkqYrmwMdvUOUPet0443oUTgF_dKCpw3TfJiutfuywAQ@mail.gmail.com

v3-0003 is for CREATE TABLE LIKE INCLUDING TRIGGERS.

--
jian
https://www.enterprisedb.com/

Attachment Content-Type Size
v3-0002-add-constrrelOid-field-to-CreateTrigStmt.patch application/x-patch 9.3 KB
v3-0001-add-relOid-field-to-CreateTrigStmt.patch application/x-patch 11.8 KB
v3-0003-CREATE-TABLE-LIKE-INCLUDING-TRIGGERS.patch application/x-patch 38.1 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2025-12-29 01:40:32 Re: let ALTER COLUMN SET DATA TYPE cope with trigger dependency
Previous Message Michael Paquier 2025-12-29 00:52:07 Re: [PROPOSAL] Termination of Background Workers for ALTER/DROP DATABASE