=== Applying patches on top of PostgreSQL commit ID 50fd428b2b9cb036c9c5982b56443d7e28119707 === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Sun Jun 29 15:10:21 UTC 2025 On branch cf/5645 nothing to commit, working tree clean === using 'git am' to apply patch ./v1-0001-generated-column-set-expression-with-check-constraint.patch === Applying: generated column set expression with check constraint Using index info to reconstruct a base tree... M src/backend/commands/tablecmds.c M src/test/regress/expected/generated_virtual.out M src/test/regress/sql/generated_virtual.sql Falling back to patching base and 3-way merge... Auto-merging src/test/regress/sql/generated_virtual.sql Auto-merging src/test/regress/expected/generated_virtual.out CONFLICT (content): Merge conflict in src/test/regress/expected/generated_virtual.out Auto-merging src/backend/commands/tablecmds.c CONFLICT (content): Merge conflict in src/backend/commands/tablecmds.c error: Failed to merge in the changes. hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 generated column set expression with check constraint When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". Unstaged changes after reset: M src/backend/commands/tablecmds.c M src/test/regress/expected/generated_virtual.out M src/test/regress/sql/generated_virtual.sql === using patch(1) to apply patch ./v1-0001-generated-column-set-expression-with-check-constraint.patch === patching file src/backend/commands/tablecmds.c Hunk #1 FAILED at 8601. 1 out of 2 hunks FAILED -- saving rejects to file src/backend/commands/tablecmds.c.rej patching file src/test/regress/expected/generated_virtual.out Hunk #1 FAILED at 636. Hunk #2 succeeded at 982 (offset 9 lines). 1 out of 2 hunks FAILED -- saving rejects to file src/test/regress/expected/generated_virtual.out.rej patching file src/test/regress/sql/generated_virtual.sql Hunk #1 succeeded at 313 (offset 1 line). Hunk #2 succeeded at 539 (offset 9 lines). Unstaged changes after reset: M src/backend/commands/tablecmds.c M src/test/regress/expected/generated_virtual.out M src/test/regress/sql/generated_virtual.sql Removing src/backend/commands/tablecmds.c.rej Removing src/test/regress/expected/generated_virtual.out.rej === using 'git apply' to apply patch ./v1-0001-generated-column-set-expression-with-check-constraint.patch === Applied patch to 'src/backend/commands/tablecmds.c' with conflicts. Applied patch to 'src/test/regress/expected/generated_virtual.out' with conflicts. Applied patch to 'src/test/regress/sql/generated_virtual.sql' cleanly. U src/backend/commands/tablecmds.c U src/test/regress/expected/generated_virtual.out diff --cc src/backend/commands/tablecmds.c index 991bc946ffc,dc4eb160f69..00000000000 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@@ -8601,18 -8601,6 +8601,21 @@@ ATExecSetExpression(AlteredTableInfo *t errmsg("column \"%s\" of relation \"%s\" is not a generated column", colName, RelationGetRelationName(rel)))); ++<<<<<<< ours + /* + * TODO: This could be done, just need to recheck any constraints + * afterwards. + */ + if (attgenerated == ATTRIBUTE_GENERATED_VIRTUAL && + rel->rd_att->constr && rel->rd_att->constr->num_check > 0) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("ALTER TABLE / SET EXPRESSION is not supported for virtual generated columns in tables with check constraints"), + errdetail("Column \"%s\" of relation \"%s\" is a virtual generated column.", + colName, RelationGetRelationName(rel)))); + ++======= ++>>>>>>> theirs if (attgenerated == ATTRIBUTE_GENERATED_VIRTUAL && attTup->attnotnull) tab->verify_new_notnull = true; diff --cc src/test/regress/expected/generated_virtual.out index df704b5166f,ae4cf5abf76..00000000000 --- a/src/test/regress/expected/generated_virtual.out +++ b/src/test/regress/expected/generated_virtual.out @@@ -633,12 -636,22 +633,31 @@@ INSERT INTO gtest20 (a) VALUES (10); - INSERT INTO gtest20 (a) VALUES (30); -- violates constraint ERROR: new row for relation "gtest20" violates check constraint "gtest20_b_check" DETAIL: Failing row contains (30, virtual). ++<<<<<<< ours +ALTER TABLE gtest20 ALTER COLUMN b SET EXPRESSION AS (a * 100); -- violates constraint (currently not supported) +ERROR: ALTER TABLE / SET EXPRESSION is not supported for virtual generated columns in tables with check constraints +DETAIL: Column "b" of relation "gtest20" is a virtual generated column. +ALTER TABLE gtest20 ALTER COLUMN b SET EXPRESSION AS (a * 3); -- ok (currently not supported) +ERROR: ALTER TABLE / SET EXPRESSION is not supported for virtual generated columns in tables with check constraints +DETAIL: Column "b" of relation "gtest20" is a virtual generated column. ++======= + ALTER TABLE gtest20 ALTER COLUMN b SET EXPRESSION AS (a * 100); -- violates constraint + ERROR: check constraint "gtest20_b_check" of relation "gtest20" is violated by some row + ALTER TABLE gtest20 ALTER COLUMN b SET EXPRESSION AS (a * 3); -- ok + --test no table rewrite happen + ALTER TABLE gtest20 ALTER COLUMN b SET EXPRESSION AS (a * 4), ADD COLUMN C int default 11; + SELECT pa.attnum,pa.attname,attmissingval + FROM pg_attribute pa + JOIN pg_attrdef patt ON pa.attrelid = patt.adrelid AND pa.attnum = patt.adnum + WHERE pa.attrelid = 'gtest20'::regclass + ORDER BY pa.attnum; + attnum | attname | attmissingval + --------+---------+--------------- + 2 | b | + 3 | c | {11} + (2 rows) + ++>>>>>>> theirs CREATE TABLE gtest20a (a int PRIMARY KEY, b int GENERATED ALWAYS AS (a * 2) VIRTUAL); INSERT INTO gtest20a (a) VALUES (10); INSERT INTO gtest20a (a) VALUES (30);