From 5c068038ff69469c7ba7c6b88da27ed734ee4ad1 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 24 Apr 2008 20:17:50 +0000 Subject: Fix ALTER TABLE ADD COLUMN ... PRIMARY KEY so that the new column is correctly checked to see if it's been initialized to all non-nulls. The implicit NOT NULL constraint was not being checked during the ALTER (in fact, not even if there was an explicit NOT NULL too), because ATExecAddColumn neglected to set the flag needed to make the test happen. This has been broken since the capability was first added, in 8.0. Brendan Jurd, per a report from Kaloyan Iliev. --- src/backend/commands/tablecmds.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/backend/commands/tablecmds.c') diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index b507f17b7b6..9d6939bbc11 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.250 2008/03/31 03:34:27 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.251 2008/04/24 20:17:50 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -3332,6 +3332,11 @@ ATExecAddColumn(AlteredTableInfo *tab, Relation rel, tab->newvals = lappend(tab->newvals, newval); } + /* + * If the new column is NOT NULL, tell Phase 3 it needs to test that. + */ + tab->new_notnull |= colDef->is_not_null; + /* * Add needed dependency entries for the new column. */ -- cgit v1.2.3