Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1viX5N-00915D-2y for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Jan 2026 12:13:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1viX5L-0072mN-2U for pgsql-hackers@arkaria.postgresql.org; Wed, 21 Jan 2026 12:13:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1viX5L-0072mE-10 for pgsql-hackers@lists.postgresql.org; Wed, 21 Jan 2026 12:13:19 +0000 Received: from mail-yw1-x1134.google.com ([2607:f8b0:4864:20::1134]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1viX5I-001adA-1f for pgsql-hackers@postgresql.org; Wed, 21 Jan 2026 12:13:18 +0000 Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-7927541abfaso62758687b3.3 for ; Wed, 21 Jan 2026 04:13:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1768997596; cv=none; d=google.com; s=arc-20240605; b=gWmSKdImIZSWMuP4YiHlHDeIpPSwTnqGaTjNwB5YW7O3vMsbHQwQeo7X9/UpQ1rJAV Wlv+JcpnxBqUTNiFVMO3pqbdQb/2aIALeeS3GYwzYEXXPPDfnkBZ3/tdsIM9s8r6FXCK ZefWFQWYjWtAREPCds5pywZgM5GoKM/yEtQooZrZnc6n8Jtk1bFxAMx9imWDrEJPcEqP e8SFvj74YWAc0V1kLiSilOuGSdXP5z5dnST0lsOA2uEG08PZWambYpHdyC8XCjrn2/En 9RUFlnDDcPfkOv64ECwOBeaA3AYsYldIWNdUUDeGb4uaD+5FGOgzf7Bmu0FxulsM1b75 ukLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=UhHziNJH79cShgFccfCCyimXFq67DEBLiVyVgAIlt0A=; fh=qt5JPY/+jMIYBV8gHbBJA/aB0iply2vQ1TwkFaNElME=; b=DNogaGXtl0KHpuU16Ms/G618qj9MFQfjHFqcGWx1O1ZXed9+Eqw45vOTU4SN3YSrBf xUmnImRsCeiMfYTbm9mgSxMD8sxDdKsjeRGZ8IRuX8YTwPtIJNnv48VvLM9k8TGOQtRE 3O95m0rFoclJ7NDItsD50WckZR1iagFCT87P/mWo+ZCEGBUB750sR07POi0pWE3tIfQT K+HHWVTKqSuWw29p7BvzI/EgokY3hcv7+ntKN9neUFROhKA2JU4uWB/JlZtonfUJXqIw gbNhx1HhskF1a0xX72+EzZhHY54ukZ8UxlcuYBvK+FYogkDqWWy01tLeerJm5hp0JETV ZeLg==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=percona.com; s=google; t=1768997596; x=1769602396; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=UhHziNJH79cShgFccfCCyimXFq67DEBLiVyVgAIlt0A=; b=duFYaQXvv/WJ/P0/U1IpgMObaxC29R4DS7AvIK6byT5XUAXpjg3FCMx8tZK0U+p5ZM Z7OUSy5UdjgNgcum/S1gTI3bS1WTnoaZRJLb3VNi3BVb49GnQW+nhI2yc/vSxoLrx6pm g1wYfF6MsGKwdHlknT4VFVstVNaoqXQpRIyoE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768997596; x=1769602396; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=UhHziNJH79cShgFccfCCyimXFq67DEBLiVyVgAIlt0A=; b=UrpnVfttwK7b9vwQnb08XY/nJOBPMckShPYgM3IlWNxygIiqCX59irs70jQzEO8omg 7U5pDrm+dXwndFzdewpx2VPVkVuznBqNoXOzEkuUHEEaxUDTT2A9KIWbzWVglRBsJZey 68dmWqBhd8Auk49rxlCHi2Cz5M4r19PWkYyCaj91VlpT2o/zW3Yyu1PQRt/TAQkyQSCQ yC4uKLMg2MqrHNH7G+wZ27mUxnPwtjGXV9VMN33L+16AzK7chx0SFlDz5Ah23ncScySZ vSx2AmqEhxgSLr9k5WV4Z1CgI9l69mQu+ti6jy5XJygHK2PWYeh+XQKHirS/RfJfdLCO vC+g== X-Forwarded-Encrypted: i=1; AJvYcCXxt9k7oO4Z8nbzZYt0hiPNfZOdisbsu0KXC3izr0KFNUuPPaJJS+Tozdmq6+vGgncCUtevOexueOK3wYi+@postgresql.org X-Gm-Message-State: AOJu0Yx0SnNYTlG6QVGkrB+jh6BFQDeXyS1fvP5zPGXSGxKqcyFY9Yoi 9qVL5cMw+S9W0kEP4lWbFGEO0CvPxZv9085NIHh9fLMe1rTm2PO+8T/MQ9Mg/RhRr/8qci5irS5 Xchiss77pcBnUUBV8GCVI8/HUYByYX2RNwakhvK9AyWMM32D4fVGLIxx7fYRiVn/bHA0FDIphq/ Em+qLkdXo9S/urwjZWWcwnzsxilimnHzVC+zNZNitSxEhBhGEshpXynOo3UmXgwlwSab8Sqgbzp uZT+C+a1Kj0aqNVWxok46Bsugh1Qf1ywSLC/uQwvoKswc9J+oI= X-Gm-Gg: AZuq6aKDGgqjfhH8ExVFZ6QlxNa2dk+6Fd3UBTAiiEeMYRI1QSswPWWCXueOSR+Wdkn UEC6G7qR889x9GGDoKAZRtyo9rrjzCOvXZoohl/vypwRn3gHpkGn0h7WUKyR8+jfGuTHDeWykHl rFIDxRdvF5nUv+tcfzAW3ZqZa8lOXxdqevNYipjo9t/2/UfmiE9tmQoMITbEVukupt2wgwI9N6w kJ5u/xIuA35FyLvmRUvyyq8gFmwtmGN3zpAWDPo2zRncYdcf75Cg0d/h3t8r7qoiXa22cp1VHu0 vanUllO9aHjQWjeFXv3YnLGmX6Uo8/JNzFDlxb4MdxYnpuSDqOcihMiD X-Received: by 2002:a05:690c:6893:b0:793:bc39:1fbc with SMTP id 00721157ae682-7940a245063mr39873817b3.36.1768997596292; Wed, 21 Jan 2026 04:13:16 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Zsolt Parragi Date: Wed, 21 Jan 2026 12:13:04 +0000 X-Gm-Features: AZwV_QjRnbPT0x4746JhEKInAkt0UkDVF8BlCx9oIfIO_BaQto0yERdu7t0Zci0 Message-ID: Subject: Re: CREATE TABLE LIKE INCLUDING TRIGGERS To: jian he Cc: Andrey Borodin , PostgreSQL-development Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-CLOUD-SEC-AV-Sent: true X-CLOUD-SEC-AV-Info: percona,google_mail,monitor X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello! I tested the patch, it works as described, but I did notice one possible is= sue: Shouldn't this preserve the enabled state of the triggers, or if it doesn't, should the documentation include this limitations? Currently the new table will always use the default TRIGGER_FIRES_ON_ORIGIN, regardless how it is configured for the original table. diff --git a/src/test/regress/sql/triggers.sql b/src/test/regress/sql/triggers.sql index a1e9dbba8bd..24f7bfb5837 100644 --- a/src/test/regress/sql/triggers.sql +++ b/src/test/regress/sql/triggers.sql @@ -260,6 +260,18 @@ ON pc.oid =3D pd.tgrelid AND pd.tgname =3D 'before_ins_stmt_trig' ORDER BY 1; COMMENT ON TRIGGER before_ins_stmt_trig ON main_table IS NULL; +-- Test that trigger firing state is not preserved by LIKE INCLUDING TRIGG= ERS +ALTER TABLE main_table DISABLE TRIGGER before_ins_stmt_trig; +CREATE TABLE main_table2 (LIKE main_table INCLUDING TRIGGERS); +SELECT c.relname, t.tgname, t.tgenabled +FROM pg_trigger t +JOIN pg_class c ON t.tgrelid =3D c.oid +WHERE t.tgname =3D 'before_ins_stmt_trig' + AND c.relname IN ('main_table', 'main_table2') +ORDER BY c.relname; +DROP TABLE main_table2; +ALTER TABLE main_table ENABLE TRIGGER before_ins_stmt_trig; + -- -- Test case for bug with BEFORE trigger followed by AFTER trigger with WH= EN -- On Wed, Jan 21, 2026 at 12:00=E2=80=AFPM jian he wrote: > > On Fri, Jan 2, 2026 at 5:25=E2=80=AFPM Andrey Borodin wrote: > > > > + char *trigcomment; /* comment to apply to trigger, or NULL */ > > No other Create*Stmt has a comment field. Comments seem to be handled t= hrough separate CommentStmt creation. > > > > See CreateStatsStmt.stxcomment, IndexStmt.idxcomment. > We need CreateTrigStmt.trigcomment, because if INCLUDING COMMENTS is spec= ified, > CreateTrigStmt.trigcomment can be used to hold the source object's commen= ts. > > > Some nitpicking about tests: > > 1. INSTEAD OF triggers on views - The error is tested, but should also = test that statement-level VIEW triggers work > ok. test added. > > > 2. Triggers on partitioned tables - What happens when you LIKE a partit= ioned table? Are partition triggers cloned? > no. only the trigger on the partitioned table itself will be cloned. > see tests ``create table parted_constr_copy (like parted_constr > including all);`` > > > 3. Cross-schema trigger functions - The function name reconstruction ha= ndles schemas, but is it tested? > > > ok. test added. > > > + funcname =3D list_make2(makeString(schemaname),makeString(NameStr(pro= cform->proname))); > > Other NameStr() are pstrdup()'d, maybe let's pstrdup() this too? > > > ok. > > > + /* Reconstruct trigger old transition table */ > > Second instance of this comment is wrong. > > > ok. > > > + PG_KEYWORD("triggers", TRIGGERS, UNRESERVED_KEYWORD, BARE_LABEL) > > Won't this break some user SQLs? > it's marked as an un-reserved word, so it won't break any SQL, i think. > > v4-0001, v4-0002 was removed, as Robert said in [1], now I am using > the same ugly > hack consistently, now code is more aligned with INCLUDING INDEXES, INCLU= DING > STATISTICS. > > pstrdup have been used in more places in generateClonedTriggerStmt. > > > > -- > jian > https://url.avanan.click/v2/r01/___https://www.enterprisedb.com/___.YXAzO= nBlcmNvbmE6YTpnOjE5NWMwMWNmNDE3Y2Y3Yzg3MGZkNWQyM2FkM2UxYjc4Ojc6NWM5NTo0YjU3= NGI1Y2MzZjIyMjk5MzRiYWU0Njk1Yjk4NTJkNzg0YjMwYzMwZWFiMjIzYTQ4YjU1ZWUwZDIxZWI= 4ZWFhOnA6VDpO