Re: CREATE TABLE LIKE INCLUDING TRIGGERS

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: CREATE TABLE LIKE INCLUDING TRIGGERS
Date: 2026-05-27 22:53:13
Message-ID: CAN4CZFPZTgG62QOgdxu0nUF_nU1R1UjyDPYYsZBee3BeR=ehAw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello!

Sorry for the late reply, somehow I missed the previous updates.

I found one more problematic scenario, I think the patch should ignore
INSTEAD OF triggers:

CREATE TABLE base (id int, val text);
CREATE VIEW v_instead AS SELECT id, val FROM base;
CREATE FUNCTION v_instead_ins() RETURNS trigger LANGUAGE plpgsql AS $$
BEGIN
INSERT INTO base VALUES (NEW.id, NEW.val);
RETURN NEW;
END;
$$;
CREATE TRIGGER v_instead_trg
INSTEAD OF INSERT ON v_instead
FOR EACH ROW EXECUTE FUNCTION v_instead_ins();
-- currently fails
-- ERROR: "t_all" is a table
-- DETAIL: Tables cannot have INSTEAD OF triggers.
CREATE TABLE t_all (LIKE v_instead INCLUDING ALL);

And also, either I don't understand something here, or the diff can be
simplified a bit:

- /* Transform expression. Copy to be sure we don't modify original */
- whenClause = transformWhereClause(pstate,
- copyObject(stmt->whenClause),
- EXPR_KIND_TRIGGER_WHEN,
- "WHEN");
- /* we have to fix its collations too */
- assign_expr_collations(pstate, whenClause);
+ if (stmt->transformed)
+ whenClause = stmt->whenClause;
+ else
+ {
+ /* Transform expression. Copy to be sure we don't modify original */
+ whenClause = transformWhereClause(pstate,
+ copyObject(stmt->whenClause),
+ EXPR_KIND_TRIGGER_WHEN,
+ "WHEN");
+
+ /* we have to fix its collations too */
+ assign_expr_collations(pstate, whenClause);
+
+ stmt->transformed = true;
+ }

Do we need the last assignment in this diff? It sets
stmt->transformed, but we don't actually transform the statement, we
create a copy. The flag also doesn't seem to be used after that.
Everything seems to work fine if I remove this assignment, and we
don't need the const related function signature changes without it.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2026-05-27 22:56:48 Re: effective_wal_level is not decreasing after using REPACK (CONCURRENTLY)
Previous Message Srinivas Kumar 2026-05-27 22:18:34 Re: DBeaver Experiencing timeouts while connecting to New Linux PostgreSql server