aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/tablecmds.c
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2019-10-09 22:00:50 -0700
committerAndres Freund <andres@anarazel.de>2019-10-09 22:13:48 -0700
commitf224c7c11ea7be2751e3342e11317070ffb5622d (patch)
tree901a3eb376c063f851e8c48bf7de1f4c5a263322 /src/backend/commands/tablecmds.c
parent07c314968712a2cb1818f6d884c9818f95dee02e (diff)
downloadpostgresql-f224c7c11ea7be2751e3342e11317070ffb5622d.tar.gz
postgresql-f224c7c11ea7be2751e3342e11317070ffb5622d.zip
Fix table rewrites that include a column without a default.
In c2fe139c201c I made ATRewriteTable() use tuple slots. Unfortunately I did not notice that columns can be added in a rewrite that do not have a default, when another column is added/altered requiring one. Initialize columns to NULL again, and add tests. Bug: #16038 Reported-By: anonymous Author: Andres Freund Discussion: https://postgr.es/m/16038-5c974541f2bf6749@postgresql.org Backpatch: 12, where the bug was introduced in c2fe139c201c
Diffstat (limited to 'src/backend/commands/tablecmds.c')
-rw-r--r--src/backend/commands/tablecmds.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 792ba56d757..c15b1b979cc 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -4893,6 +4893,16 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
table_slot_callbacks(oldrel));
newslot = MakeSingleTupleTableSlot(newTupDesc,
table_slot_callbacks(newrel));
+
+ /*
+ * Set all columns in the new slot to NULL initially, to ensure
+ * columns added as part of the rewrite are initialized to
+ * NULL. That is necessary as tab->newvals will not contain an
+ * expression for columns with a NULL default, e.g. when adding a
+ * column without a default together with a column with a default
+ * requiring an actual rewrite.
+ */
+ ExecStoreAllNullTuple(newslot);
}
else
{