35 #include "utils/fmgroids.h"
67 bool nulls[Natts_pg_type];
78 tupDesc = pg_type_desc->
rd_att;
83 for (
i = 0;
i < Natts_pg_type; ++
i)
126 nulls[Anum_pg_type_typdefaultbin - 1] =
true;
127 nulls[Anum_pg_type_typdefault - 1] =
true;
128 nulls[Anum_pg_type_typacl - 1] =
true;
135 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
136 errmsg(
"pg_type OID value not set when in binary upgrade mode")));
199 const char *typeName,
211 Oid receiveProcedure,
213 Oid typmodinProcedure,
214 Oid typmodoutProcedure,
215 Oid analyzeProcedure,
216 Oid subscriptProcedure,
218 bool isImplicitArray,
221 const char *defaultTypeValue,
222 char *defaultTypeBin,
233 bool isDependentType;
234 bool rebuildDeps =
false;
237 bool nulls[Natts_pg_type];
238 bool replaces[Natts_pg_type];
251 if (!(internalSize > 0 ||
252 internalSize == -1 ||
255 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
256 errmsg(
"invalid type internal size %d",
267 if (internalSize == (
int16)
sizeof(
char))
269 if (alignment != TYPALIGN_CHAR)
271 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
272 errmsg(
"alignment \"%c\" is invalid for passed-by-value type of size %d",
273 alignment, internalSize)));
275 else if (internalSize == (
int16)
sizeof(
int16))
277 if (alignment != TYPALIGN_SHORT)
279 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
280 errmsg(
"alignment \"%c\" is invalid for passed-by-value type of size %d",
281 alignment, internalSize)));
283 else if (internalSize == (
int16)
sizeof(
int32))
285 if (alignment != TYPALIGN_INT)
287 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
288 errmsg(
"alignment \"%c\" is invalid for passed-by-value type of size %d",
289 alignment, internalSize)));
291 #if SIZEOF_DATUM == 8
292 else if (internalSize == (
int16)
sizeof(
Datum))
294 if (alignment != TYPALIGN_DOUBLE)
296 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
297 errmsg(
"alignment \"%c\" is invalid for passed-by-value type of size %d",
298 alignment, internalSize)));
303 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
304 errmsg(
"internal size %d is invalid for passed-by-value type",
310 if (internalSize == -1 &&
311 !(alignment == TYPALIGN_INT || alignment == TYPALIGN_DOUBLE))
313 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
314 errmsg(
"alignment \"%c\" is invalid for variable-length type",
317 if (internalSize == -2 && !(alignment == TYPALIGN_CHAR))
319 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
320 errmsg(
"alignment \"%c\" is invalid for variable-length type",
325 if (storage != TYPSTORAGE_PLAIN && internalSize != -1)
327 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
328 errmsg(
"fixed-size types must have storage PLAIN")));
338 isDependentType = isImplicitArray ||
339 (
OidIsValid(relationOid) && relationKind != RELKIND_COMPOSITE_TYPE);
344 for (
i = 0;
i < Natts_pg_type; ++
i)
391 nulls[Anum_pg_type_typdefaultbin - 1] =
true;
396 if (defaultTypeValue)
399 nulls[Anum_pg_type_typdefault - 1] =
true;
412 nulls[Anum_pg_type_typacl - 1] =
true;
433 if (typform->typisdefined)
436 errmsg(
"type \"%s\" already exists", typeName)));
441 if (typform->typowner != ownerId)
446 elog(
ERROR,
"cannot assign new OID to existing shell type");
448 replaces[Anum_pg_type_oid - 1] =
false;
461 typeObjectId = typform->oid;
469 typeObjectId = newTypeOid;
475 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
476 errmsg(
"pg_type OID value not set when in binary upgrade mode")));
560 bool isImplicitArray,
561 bool isDependentType,
562 bool makeExtensionDep,
566 Oid typeObjectId = typeForm->oid;
574 if (defaultExpr == NULL)
576 datum =
heap_getattr(typeTuple, Anum_pg_type_typdefaultbin,
609 if (!isDependentType)
612 typeForm->typnamespace);
619 typeForm->typowner, typacl);
621 if (makeExtensionDep)
686 typeForm->typcollation != DEFAULT_COLLATION_OID)
712 if (relationKind != RELKIND_COMPOSITE_TYPE)
753 elog(
ERROR,
"cache lookup failed for type %u", typeOid);
757 Assert(typeNamespace == typ->typnamespace);
759 arrayOid = typ->typarray;
781 errmsg(
"type \"%s\" already exists", newTypeName)));
799 if (
OidIsValid(arrayOid) && arrayOid != oldTypeOid)
824 errmsg(
"could not form array type name for type \"%s\"",
910 rangestr = strstr(rangeTypeName,
"range");
913 char *prefix =
pnstrdup(rangeTypeName, rangestr - rangeTypeName);
915 buf =
psprintf(
"%s%s%s", prefix,
"multi", rangestr);
928 errmsg(
"type \"%s\" already exists",
buf),
929 errdetail(
"Failed while creating a multirange type for type \"%s\".", rangeTypeName),
930 errhint(
"You can manually specify a multirange type name using the \"multirange_type_name\" attribute.")));
963 namelen = strlen(typeName);
#define DatumGetAclPCopy(X)
void recordDependencyOnNewAcl(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, Acl *acl)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Acl * get_user_default_acl(ObjectType objtype, Oid ownerId, Oid nsp_oid)
static Datum values[MAXATTR]
#define CStringGetTextDatum(s)
#define TextDatumGetCString(d)
#define PointerIsValid(pointer)
#define OidIsValid(objectId)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
void recordDependencyOnExpr(const ObjectAddress *depender, Node *expr, List *rtable, DependencyType behavior)
ObjectAddresses * new_object_addresses(void)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
void free_object_addresses(ObjectAddresses *addrs)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Assert(fmt[strlen(fmt) - 1] !='\n')
Oid get_element_type(Oid typid)
bool get_typisdefined(Oid typid)
Oid get_array_type(Oid typid)
int pg_mbcliplen(const char *mbstr, int len, int limit)
char * pnstrdup(const char *in, Size len)
char * pstrdup(const char *in)
void pfree(void *pointer)
#define IsBootstrapProcessingMode()
void namestrcpy(Name name, const char *str)
#define InvokeObjectPostCreateHook(classId, objectId, subId)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
#define ObjectAddressSet(addr, class_id, object_id)
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
long deleteDependencyRecordsFor(Oid classId, Oid objectId, bool skipExtensionDeps)
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId, int32 objectSubId)
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
char * makeMultirangeTypeName(const char *rangeTypeName, Oid typeNamespace)
static char * makeUniqueTypeName(const char *typeName, Oid typeNamespace, bool tryOriginal)
void GenerateTypeDependencies(HeapTuple typeTuple, Relation typeCatalog, Node *defaultExpr, void *typacl, char relationKind, bool isImplicitArray, bool isDependentType, bool makeExtensionDep, bool rebuild)
void RenameTypeInternal(Oid typeOid, const char *newTypeName, Oid typeNamespace)
Oid binary_upgrade_next_pg_type_oid
ObjectAddress TypeCreate(Oid newTypeOid, const char *typeName, Oid typeNamespace, Oid relationOid, char relationKind, Oid ownerId, int16 internalSize, char typeType, char typeCategory, bool typePreferred, char typDelim, Oid inputProcedure, Oid outputProcedure, Oid receiveProcedure, Oid sendProcedure, Oid typmodinProcedure, Oid typmodoutProcedure, Oid analyzeProcedure, Oid subscriptProcedure, Oid elementType, bool isImplicitArray, Oid arrayType, Oid baseType, const char *defaultTypeValue, char *defaultTypeBin, bool passedByValue, char alignment, char storage, int32 typeMod, int32 typNDims, bool typeNotNull, Oid typeCollation)
char * makeArrayTypeName(const char *typeName, Oid typeNamespace)
bool moveArrayTypeName(Oid typeOid, const char *typeName, Oid typeNamespace)
ObjectAddress TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
FormData_pg_type * Form_pg_type
size_t strlcpy(char *dst, const char *src, size_t siz)
#define CStringGetDatum(X)
#define ObjectIdGetDatum(X)
#define PointerGetDatum(X)
char * psprintf(const char *fmt,...)
void * stringToNode(const char *str)
#define RelationGetDescr(relation)
void truncate_identifier(char *ident, int len, bool warn)
#define ERRCODE_DUPLICATE_OBJECT
#define SearchSysCacheCopy1(cacheId, key1)
#define SearchSysCacheCopy2(cacheId, key1, key2)
#define SearchSysCacheExists2(cacheId, key1, key2)
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
void CommandCounterIncrement(void)