From 5b61d832db58fa85e3cfee5b394232bd62c02305 Mon Sep 17 00:00:00 2001 From: shihao zhong Date: Mon, 16 Nov 2026 20:21:59 -0500 Subject: [PATCH 2/2] Add tests for LIKE with INHERITS on generated columns Kept separate so it can be dropped or rewritten. --- .../regress/expected/create_table_like.out | 30 +++++++++++++++++++ src/test/regress/sql/create_table_like.sql | 17 +++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/test/regress/expected/create_table_like.out b/src/test/regress/expected/create_table_like.out index 0deba8b6ac4..932ea0d46e4 100644 --- a/src/test/regress/expected/create_table_like.out +++ b/src/test/regress/expected/create_table_like.out @@ -265,6 +265,36 @@ Inherits: test_like_5 test_like_5x +-- LIKE with INHERITS follows the same rules as columns written out +CREATE TABLE test_like_7p (a int, + b int GENERATED ALWAYS AS (a * 2) STORED); +CREATE TABLE test_like_7s (a int, + b int GENERATED ALWAYS AS (a * 3) STORED); +CREATE TABLE test_like_7c (LIKE test_like_7s INCLUDING GENERATED) + INHERITS (test_like_7p); +NOTICE: merging column "a" with inherited definition +NOTICE: merging column "b" with inherited definition +INSERT INTO test_like_7c (a) VALUES (1); +SELECT * FROM test_like_7c; + a | b +---+--- + 1 | 3 +(1 row) + +CREATE TABLE test_like_7d (a int, b int DEFAULT 42, + c int GENERATED ALWAYS AS (b * 2) STORED); +CREATE TABLE test_like_7e (LIKE test_like_7d INCLUDING DEFAULTS) + INHERITS (test_like_7p); -- error +NOTICE: merging column "a" with inherited definition +NOTICE: merging column "b" with inherited definition +ERROR: column "b" inherits from generated column but specifies default +CREATE TABLE test_like_7e (LIKE test_like_7d INCLUDING GENERATED) + INHERITS (test_like_7p); -- error +NOTICE: merging column "a" with inherited definition +NOTICE: merging column "b" with inherited definition +ERROR: cannot use generated column "b" in column generation expression +DETAIL: A generated column cannot reference another generated column. +DROP TABLE test_like_7p, test_like_7s, test_like_7c, test_like_7d; -- Test updating of column numbers in statistics expressions (bug #18468) CREATE TABLE test_like_6 (a int, c text, b text); CREATE STATISTICS ext_stat ON (a || b) FROM test_like_6; diff --git a/src/test/regress/sql/create_table_like.sql b/src/test/regress/sql/create_table_like.sql index 5dd81f4eaf9..5256d51158e 100644 --- a/src/test/regress/sql/create_table_like.sql +++ b/src/test/regress/sql/create_table_like.sql @@ -95,6 +95,23 @@ CREATE TABLE test_like_5c (LIKE test_like_4 INCLUDING ALL) INHERITS (test_like_5, test_like_5x); \d test_like_5c +-- LIKE with INHERITS follows the same rules as columns written out +CREATE TABLE test_like_7p (a int, + b int GENERATED ALWAYS AS (a * 2) STORED); +CREATE TABLE test_like_7s (a int, + b int GENERATED ALWAYS AS (a * 3) STORED); +CREATE TABLE test_like_7c (LIKE test_like_7s INCLUDING GENERATED) + INHERITS (test_like_7p); +INSERT INTO test_like_7c (a) VALUES (1); +SELECT * FROM test_like_7c; +CREATE TABLE test_like_7d (a int, b int DEFAULT 42, + c int GENERATED ALWAYS AS (b * 2) STORED); +CREATE TABLE test_like_7e (LIKE test_like_7d INCLUDING DEFAULTS) + INHERITS (test_like_7p); -- error +CREATE TABLE test_like_7e (LIKE test_like_7d INCLUDING GENERATED) + INHERITS (test_like_7p); -- error +DROP TABLE test_like_7p, test_like_7s, test_like_7c, test_like_7d; + -- Test updating of column numbers in statistics expressions (bug #18468) CREATE TABLE test_like_6 (a int, c text, b text); CREATE STATISTICS ext_stat ON (a || b) FROM test_like_6; -- 2.37.1 (Apple Git-137.1)