]> granicus.if.org Git - postgresql/blobdiff - src/backend/commands/tablecmds.c
Fix table rewrites that include a column without a default.
[postgresql] / src / backend / commands / tablecmds.c
index 05593f331624650a1886187a08157bb81bf0aa20..ba8f4459f3d5ca1a9606ddd1309db84b0d1f1e4b 100644 (file)
@@ -4890,6 +4890,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
                {