MCPcopy Create free account
hub / github.com/apache/cloudberry / ATPrepAlterColumnType

Function ATPrepAlterColumnType

src/backend/commands/tablecmds.c:13747–14105  ·  view source on GitHub ↗

* ALTER COLUMN TYPE * * Unlike other subcommand types, we do parse transformation for ALTER COLUMN * TYPE during phase 1 --- the AlterTableCmd passed in here is already * transformed (and must be, because we rely on some transformed fields). * * The point of this is that the execution of all ALTER COLUMN TYPEs for a * table will be done "in parallel" during phase 3, so all the USING * expr

Source from the content-addressed store, hash-verified

13745 * against the unmodified table's state.
13746 */
13747static void
13748ATPrepAlterColumnType(List **wqueue,
13749 AlteredTableInfo *tab, Relation rel,
13750 bool recurse, bool recursing,
13751 AlterTableCmd *cmd, LOCKMODE lockmode,
13752 AlterTableUtilityContext *context)
13753{
13754 char *colName = cmd->name;
13755 ColumnDef *def = (ColumnDef *) cmd->def;
13756 TypeName *typeName = def->typeName;
13757 Node *transform = def->cooked_default;
13758 HeapTuple tuple;
13759 Form_pg_attribute attTup;
13760 AttrNumber attnum;
13761 Oid targettype;
13762 int32 targettypmod;
13763 Oid targetcollid;
13764 NewColumnValue *newval;
13765 ParseState *pstate = make_parsestate(NULL);
13766 AclResult aclresult;
13767 Oid new_opclass = InvalidOid;
13768 Oid old_opclass = InvalidOid;
13769 Oid old_opfamily = InvalidOid;
13770 Oid new_opfamily = InvalidOid;
13771 bool is_expr;
13772
13773 if (rel->rd_rel->reloftype && !recursing)
13774 ereport(ERROR,
13775 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
13776 errmsg("cannot alter column type of typed table")));
13777
13778 /* lookup the attribute so we can check inheritance status */
13779 tuple = SearchSysCacheAttName(RelationGetRelid(rel), colName);
13780 if (!HeapTupleIsValid(tuple))
13781 ereport(ERROR,
13782 (errcode(ERRCODE_UNDEFINED_COLUMN),
13783 errmsg("column \"%s\" of relation \"%s\" does not exist",
13784 colName, RelationGetRelationName(rel))));
13785 attTup = (Form_pg_attribute) GETSTRUCT(tuple);
13786 attnum = attTup->attnum;
13787
13788 /* Can't alter a system attribute */
13789 if (attnum <= 0)
13790 ereport(ERROR,
13791 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13792 errmsg("cannot alter system column \"%s\"",
13793 colName)));
13794
13795 /*
13796 * Don't alter inherited columns. At outer level, there had better not be
13797 * any inherited definition; when recursing, we assume this was checked at
13798 * the parent level (see below).
13799 */
13800 if (attTup->attinhcount > 0 && !recursing)
13801 ereport(ERROR,
13802 (errcode(ERRCODE_INVALID_TABLE_DEFINITION),
13803 errmsg("cannot alter inherited column \"%s\"",
13804 colName)));

Callers 1

ATPrepCmdFunction · 0.85

Calls 15

make_parsestateFunction · 0.85
SearchSysCacheAttNameFunction · 0.85
has_partition_attrsFunction · 0.85
bms_make_singletonFunction · 0.85
typenameTypeIdAndModFunction · 0.85
pg_type_aclcheckFunction · 0.85
GetUserIdFunction · 0.85
aclcheck_error_typeFunction · 0.85
GetColumnDefCollationFunction · 0.85
CheckAttributeTypeFunction · 0.85
get_opclass_familyFunction · 0.85
GetDefaultOpClassFunction · 0.85

Tested by

no test coverage detected