From 983a57e8dc5f71ba80e855fc00143e9193f243a9 Mon Sep 17 00:00:00 2001 From: Peter Geoghegan Date: Wed, 5 Aug 2026 18:19:00 -0400 Subject: [PATCH] Add a test for a missing attribute lost inside a whole-row reference --- src/test/regress/expected/fast_default.out | 44 ++++++++++++++++++++++ src/test/regress/sql/fast_default.sql | 15 ++++++++ 2 files changed, 59 insertions(+) diff --git a/src/test/regress/expected/fast_default.out b/src/test/regress/expected/fast_default.out index 49485f5ec..6ce1e8d03 100644 --- a/src/test/regress/expected/fast_default.out +++ b/src/test/regress/expected/fast_default.out @@ -944,6 +944,50 @@ SELECT * FROM t ORDER BY id; (3 rows) DROP TABLE t; +CREATE TABLE t_missing_wholerow (rid int NOT NULL, nul "char"); +INSERT INTO t_missing_wholerow (rid) VALUES (5), (6); +ALTER TABLE t_missing_wholerow ADD COLUMN m0 int NOT NULL DEFAULT 40; +ALTER TABLE t_missing_wholerow ADD COLUMN m1 bigint NOT NULL DEFAULT 41; +SELECT rid, m0, m1 FROM t_missing_wholerow ORDER BY rid; + rid | m0 | m1 +-----+----+---- + 5 | 40 | 41 + 6 | 40 | 41 +(2 rows) + +SELECT x::text FROM t_missing_wholerow x ORDER BY 1; + x +------------ + (5,,40,41) + (6,,40,41) +(2 rows) + +SELECT x.m0, x::text FROM t_missing_wholerow x ORDER BY 1; + m0 | x +----+------------ + 40 | (5,,40,41) + 40 | (6,,40,41) +(2 rows) + +-- reading the second added column first is not affected +SELECT x.m1, x::text FROM t_missing_wholerow x ORDER BY 1; + m1 | x +----+------------ + 41 | (5,,40,41) + 41 | (6,,40,41) +(2 rows) + +-- the whole-row value is stored, not only returned +CREATE TABLE t_missing_copy AS + SELECT x.m0 AS direct, x::text AS whole_row FROM t_missing_wholerow x; +SELECT * FROM t_missing_copy ORDER BY 1; + direct | whole_row +--------+------------ + 40 | (5,,40,41) + 40 | (6,,40,41) +(2 rows) + +DROP TABLE t_missing_copy, t_missing_wholerow; -- cleanup DROP FOREIGN TABLE ft1; DROP SERVER s0; diff --git a/src/test/regress/sql/fast_default.sql b/src/test/regress/sql/fast_default.sql index ccd138c4e..3ed3e6e9d 100644 --- a/src/test/regress/sql/fast_default.sql +++ b/src/test/regress/sql/fast_default.sql @@ -618,6 +618,21 @@ REPACK t; SELECT * FROM t ORDER BY id; DROP TABLE t; +CREATE TABLE t_missing_wholerow (rid int NOT NULL, nul "char"); +INSERT INTO t_missing_wholerow (rid) VALUES (5), (6); +ALTER TABLE t_missing_wholerow ADD COLUMN m0 int NOT NULL DEFAULT 40; +ALTER TABLE t_missing_wholerow ADD COLUMN m1 bigint NOT NULL DEFAULT 41; +SELECT rid, m0, m1 FROM t_missing_wholerow ORDER BY rid; +SELECT x::text FROM t_missing_wholerow x ORDER BY 1; +SELECT x.m0, x::text FROM t_missing_wholerow x ORDER BY 1; +-- reading the second added column first is not affected +SELECT x.m1, x::text FROM t_missing_wholerow x ORDER BY 1; +-- the whole-row value is stored, not only returned +CREATE TABLE t_missing_copy AS + SELECT x.m0 AS direct, x::text AS whole_row FROM t_missing_wholerow x; +SELECT * FROM t_missing_copy ORDER BY 1; +DROP TABLE t_missing_copy, t_missing_wholerow; + -- cleanup DROP FOREIGN TABLE ft1; DROP SERVER s0; -- 2.53.0