From 3f33229efe1246e769566b35960e17e8bc2aba59 Mon Sep 17 00:00:00 2001 From: Yugo Nagata Date: Thu, 8 May 2025 17:09:37 +0900 Subject: [PATCH] Use quoted column names in targetlist of subquery substituting modified table (#135) Fix a bug introduced by 5b8b2f0, which built targetlist of subquery substituting modified table. When a table has a column whose name includes a capital letter, incremental view maintenance failed because crafted targetlist contains incorrect column name which was parsed as lower case. Isseu #124 --- expected/pg_ivm.out | 15 +++++++++++++++ matview.c | 2 +- sql/pg_ivm.sql | 8 ++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/expected/pg_ivm.out b/expected/pg_ivm.out index 524e300..61526b4 100644 --- a/expected/pg_ivm.out +++ b/expected/pg_ivm.out @@ -81,6 +81,21 @@ SELECT * FROM mv_ivm_1 ORDER BY 1,2,3; 4 | 40 | 104 (4 rows) +-- test for renaming column name to camel style +BEGIN; +ALTER TABLE mv_base_a RENAME i TO "I"; +ALTER TABLE mv_base_a RENAME j TO "J"; +UPDATE mv_base_a SET "J" = 0 WHERE "I" = 1; +SELECT * FROM mv_ivm_1 ORDER BY 1,2,3; + i | j | k +---+----+----- + 1 | 0 | 101 + 2 | 20 | 102 + 3 | 30 | 103 + 4 | 40 | 104 +(4 rows) + +ROLLBACK; -- TRUNCATE a base table in join views BEGIN; TRUNCATE mv_base_a; diff --git a/matview.c b/matview.c index d9b9db6..66709b5 100644 --- a/matview.c +++ b/matview.c @@ -1612,7 +1612,7 @@ make_subquery_targetlist_from_table(MV_TriggerTable *table) if (attr->attisdropped) appendStringInfo(&str, "null"); else - appendStringInfo(&str, "%s", NameStr(attr->attname)); + appendStringInfo(&str, "%s", quote_identifier(NameStr(attr->attname))); } return str.data; diff --git a/sql/pg_ivm.sql b/sql/pg_ivm.sql index 5dbd396..6d917ea 100644 --- a/sql/pg_ivm.sql +++ b/sql/pg_ivm.sql @@ -37,6 +37,14 @@ SELECT * FROM mv_ivm_1 ORDER BY 1,2,3; ROLLBACK; SELECT * FROM mv_ivm_1 ORDER BY 1,2,3; +-- test for renaming column name to camel style +BEGIN; +ALTER TABLE mv_base_a RENAME i TO "I"; +ALTER TABLE mv_base_a RENAME j TO "J"; +UPDATE mv_base_a SET "J" = 0 WHERE "I" = 1; +SELECT * FROM mv_ivm_1 ORDER BY 1,2,3; +ROLLBACK; + -- TRUNCATE a base table in join views BEGIN; TRUNCATE mv_base_a;