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

Function AlterType

src/backend/commands/typecmds.c:4220–4491  ·  view source on GitHub ↗

* AlterType * ALTER TYPE SET (option = ...) * * NOTE: the set of changes that can be allowed here is constrained by many * non-obvious implementation restrictions. Tread carefully when considering * adding new flexibility. */

Source from the content-addressed store, hash-verified

4218 * adding new flexibility.
4219 */
4220ObjectAddress
4221AlterType(AlterTypeStmt *stmt)
4222{
4223 ObjectAddress address;
4224 Relation catalog;
4225 TypeName *typename;
4226 HeapTuple tup;
4227 Oid typeOid;
4228 Form_pg_type typForm;
4229 bool requireSuper = false;
4230 AlterTypeRecurseParams atparams;
4231 ListCell *pl;
4232 List *encoding = NIL;
4233
4234 catalog = table_open(TypeRelationId, RowExclusiveLock);
4235
4236 /* Make a TypeName so we can use standard type lookup machinery */
4237 typename = makeTypeNameFromNameList(stmt->typeName);
4238 tup = typenameType(NULL, typename, NULL);
4239
4240 typeOid = typeTypeId(tup);
4241 typForm = (Form_pg_type) GETSTRUCT(tup);
4242
4243 /* Process options */
4244 memset(&atparams, 0, sizeof(atparams));
4245 foreach(pl, stmt->options)
4246 {
4247 DefElem *defel = (DefElem *) lfirst(pl);
4248
4249 if (strcmp(defel->defname, "storage") == 0)
4250 {
4251 char *a = defGetString(defel);
4252
4253 if (pg_strcasecmp(a, "plain") == 0)
4254 atparams.storage = TYPSTORAGE_PLAIN;
4255 else if (pg_strcasecmp(a, "external") == 0)
4256 atparams.storage = TYPSTORAGE_EXTERNAL;
4257 else if (pg_strcasecmp(a, "extended") == 0)
4258 atparams.storage = TYPSTORAGE_EXTENDED;
4259 else if (pg_strcasecmp(a, "main") == 0)
4260 atparams.storage = TYPSTORAGE_MAIN;
4261 else
4262 ereport(ERROR,
4263 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4264 errmsg("storage \"%s\" not recognized", a)));
4265
4266 /*
4267 * Validate the storage request. If the type isn't varlena, it
4268 * certainly doesn't support non-PLAIN storage.
4269 */
4270 if (atparams.storage != TYPSTORAGE_PLAIN && typForm->typlen != -1)
4271 ereport(ERROR,
4272 (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4273 errmsg("fixed-size types must have storage PLAIN")));
4274
4275 /*
4276 * Switching from PLAIN to non-PLAIN is allowed, but it requires
4277 * superuser, since we can't validate that the type's C functions

Callers 1

ProcessUtilitySlowFunction · 0.85

Calls 15

table_openFunction · 0.85
makeTypeNameFromNameListFunction · 0.85
typenameTypeFunction · 0.85
typeTypeIdFunction · 0.85
defGetStringFunction · 0.85
pg_strcasecmpFunction · 0.85
findTypeReceiveFunctionFunction · 0.85
defGetQualifiedNameFunction · 0.85
findTypeSendFunctionFunction · 0.85
findTypeTypmodinFunctionFunction · 0.85
findTypeAnalyzeFunctionFunction · 0.85

Tested by

no test coverage detected