public inbox for [email protected]  
help / color / mirror / Atom feed
From: Zsolt Parragi <[email protected]>
To: [email protected]
Subject: Re: CREATE TABLE LIKE INCLUDING TRIGGERS
Date: Wed, 27 May 2026 15:53:13 -0700
Message-ID: <CAN4CZFPZTgG62QOgdxu0nUF_nU1R1UjyDPYYsZBee3BeR=ehAw@mail.gmail.com> (raw)
In-Reply-To: <CACJufxGhZy9s1ZZhOOu95AMpynk5acVxFVqHqoYcbbscezrbMA@mail.gmail.com>
References: <CACJufxHJAr2FjbeB6ghg_-N5dxX5JVnjKSLOUxOyt4TeaAWQkg@mail.gmail.com>
	<CACJufxHQ8tDG09mXW=8xfEK2_h+By1zLgrFd0EcshHp-TDGiGw@mail.gmail.com>
	<CACJufxFu7Y4FhVkaKT2Kaj8ym2T5TcwN93cR_6h4x66iLrSZ-Q@mail.gmail.com>
	<CACJufxHMYq2ZqvOhoSKUmx+wZUo=HixjfgGKDJ6L4cdCvwh2VA@mail.gmail.com>
	<[email protected]>
	<CACJufxH5YDMAQ_KXaPJaC4Zt1i2HNSNaYoskzNDRjSrE_UWjKw@mail.gmail.com>
	<CAN4CZFM_8jL7Rf43zLa-9P2BwC+_H-oM9kYxVLGcwu83KC6faA@mail.gmail.com>
	<CACJufxGGXnRP+Em521KvPVOmnPtya2zpPqrTuYDmrSY=AFVmfw@mail.gmail.com>
	<CAN4CZFNPE_UeTEy5TH9wwc6mBAtX7vnBhLSL47jRiHXA=6yXjQ@mail.gmail.com>
	<CACJufxGTxbpbaQjUxc69-Dovx6+KJd=81T5111uizUrdsEkDNQ@mail.gmail.com>
	<CAN4CZFOdet_ZZEr+sZhTUiAd-fjOprhMXDhkjdhz48pEoJc9Pg@mail.gmail.com>
	<CACJufxEKK44FtxiShTZtPtCehwm47k5wB+RobuRCUJRa_b0owg@mail.gmail.com>
	<CACJufxFT-P-QZ-w5tVKOicWayUb1p407mWTDX5CGbf6XP2MGcA@mail.gmail.com>
	<CACJufxGhZy9s1ZZhOOu95AMpynk5acVxFVqHqoYcbbscezrbMA@mail.gmail.com>

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.






view thread (12+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: CREATE TABLE LIKE INCLUDING TRIGGERS
  In-Reply-To: <CAN4CZFPZTgG62QOgdxu0nUF_nU1R1UjyDPYYsZBee3BeR=ehAw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox