diff --git a/src/gausskernel/optimizer/commands/tablecmds.cpp b/src/gausskernel/optimizer/commands/tablecmds.cpp index 677932f75..0463912c9 100644 --- a/src/gausskernel/optimizer/commands/tablecmds.cpp +++ b/src/gausskernel/optimizer/commands/tablecmds.cpp @@ -12995,13 +12995,6 @@ static void ATExecAlterColumnType(AlteredTableInfo* tab, Relation rel, AlterTabl Node* update_expr = NULL; bool flagDropOnUpdateTimestamp = false; bool existOnUpdateTimestamp = false; - /* def->constraints maybe is null when execute sql(alter table x alter column type new_type) */ - if (cmd->subtype == AT_AlterColumnType && def->constraints && def->constraints->head) { - Constraint* temp_cons = (Constraint*)lfirst(def->constraints->head); - if (temp_cons->contype == CONSTR_DEFAULT && temp_cons->update_expr != NULL) { - update_expr = temp_cons->update_expr; - } - } attrelation = heap_open(AttributeRelationId, RowExclusiveLock); @@ -13327,6 +13320,14 @@ static void ATExecAlterColumnType(AlteredTableInfo* tab, Relation rel, AlterTabl RemoveStatistics<'c'>(RelationGetRelid(rel), attnum); } + /* def->constraints maybe is null when execute sql(alter table x alter column type new_type) */ + if (cmd->subtype == AT_AlterColumnType && def->constraints && def->constraints->head) { + Constraint* temp_cons = (Constraint*)lfirst(def->constraints->head); + if (temp_cons->contype == CONSTR_DEFAULT && temp_cons->update_expr != NULL) { + update_expr = temp_cons->update_expr; + } + } + /* when the default expr is NULL and on update expr exist, the defaultexpr should be NULL. * because the build_column_default maybe return the on update expr. */ if (rel->rd_att->constr && rel->rd_att->constr->num_defval > 0) {