35 #include "utils/fmgroids.h"
64 bool nulls[Natts_pg_type];
75 tupDesc = pg_type_desc->
rd_att;
80 for (
i = 0;
i < Natts_pg_type; ++
i)
123 nulls[Anum_pg_type_typdefaultbin - 1] =
true;
124 nulls[Anum_pg_type_typdefault - 1] =
true;
125 nulls[Anum_pg_type_typacl - 1] =
true;
132 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
133 errmsg(
"pg_type OID value not set when in binary upgrade mode")));
196 const char *typeName,
208 Oid receiveProcedure,
210 Oid typmodinProcedure,
211 Oid typmodoutProcedure,
212 Oid analyzeProcedure,
213 Oid subscriptProcedure,
215 bool isImplicitArray,
218 const char *defaultTypeValue,
219 char *defaultTypeBin,
230 bool isDependentType;
231 bool rebuildDeps =
false;
234 bool nulls[Natts_pg_type];
235 bool replaces[Natts_pg_type];
248 if (!(internalSize > 0 ||
249 internalSize == -1 ||
252 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
253 errmsg(
"invalid type internal size %d",
264 if (internalSize == (
int16)
sizeof(
char))
266 if (alignment != TYPALIGN_CHAR)
268 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
269 errmsg(
"alignment \"%c\" is invalid for passed-by-value type of size %d",
270 alignment, internalSize)));
272 else if (internalSize == (
int16)
sizeof(
int16))
274 if (alignment != TYPALIGN_SHORT)
276 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
277 errmsg(
"alignment \"%c\" is invalid for passed-by-value type of size %d",
278 alignment, internalSize)));
280 else if (internalSize == (
int16)
sizeof(
int32))
282 if (alignment != TYPALIGN_INT)
284 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
285 errmsg(
"alignment \"%c\" is invalid for passed-by-value type of size %d",
286 alignment, internalSize)));
288 #if SIZEOF_DATUM == 8
289 else if (internalSize == (
int16)
sizeof(
Datum))
291 if (alignment != TYPALIGN_DOUBLE)
293 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
294 errmsg(
"alignment \"%c\" is invalid for passed-by-value type of size %d",
295 alignment, internalSize)));
300 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
301 errmsg(
"internal size %d is invalid for passed-by-value type",
307 if (internalSize == -1 &&
308 !(alignment == TYPALIGN_INT || alignment == TYPALIGN_DOUBLE))
310 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
311 errmsg(
"alignment \"%c\" is invalid for variable-length type",
314 if (internalSize == -2 && !(alignment == TYPALIGN_CHAR))
316 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
317 errmsg(
"alignment \"%c\" is invalid for variable-length type",
322 if (
storage != TYPSTORAGE_PLAIN && internalSize != -1)
324 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
325 errmsg(
"fixed-size types must have storage PLAIN")));
335 isDependentType = isImplicitArray ||
336 typeType == TYPTYPE_MULTIRANGE ||
337 (
OidIsValid(relationOid) && relationKind != RELKIND_COMPOSITE_TYPE);
342 for (
i = 0;
i < Natts_pg_type; ++
i)
389 nulls[Anum_pg_type_typdefaultbin - 1] =
true;
394 if (defaultTypeValue)
397 nulls[Anum_pg_type_typdefault - 1] =
true;
410 nulls[Anum_pg_type_typacl - 1] =
true;
431 if (typform->typisdefined)
434 errmsg(
"type \"%s\" already exists", typeName)));
439 if (typform->typowner != ownerId)
444 elog(
ERROR,
"cannot assign new OID to existing shell type");
446 replaces[Anum_pg_type_oid - 1] =
false;
459 typeObjectId = typform->oid;
467 typeObjectId = newTypeOid;
473 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
474 errmsg(
"pg_type OID value not set when in binary upgrade mode")));
562 bool isImplicitArray,
563 bool isDependentType,
564 bool makeExtensionDep,
568 Oid typeObjectId = typeForm->oid;
576 if (defaultExpr == NULL)
578 datum =
heap_getattr(typeTuple, Anum_pg_type_typdefaultbin,
613 if (!isDependentType || typeForm->typtype == TYPTYPE_MULTIRANGE)
616 typeForm->typnamespace);
620 if (!isDependentType)
626 typeForm->typowner, typacl);
636 if (makeExtensionDep)
700 typeForm->typcollation != DEFAULT_COLLATION_OID)
726 if (relationKind != RELKIND_COMPOSITE_TYPE)
777 elog(
ERROR,
"cache lookup failed for type %u", typeOid);
781 Assert(typeNamespace == typ->typnamespace);
783 arrayOid = typ->typarray;
805 errmsg(
"type \"%s\" already exists", newTypeName)));
823 if (
OidIsValid(arrayOid) && arrayOid != oldTypeOid)
872 snprintf(suffix,
sizeof(suffix),
"%d", ++pass);
959 rangestr = strstr(rangeTypeName,
"range");
962 char *prefix =
pnstrdup(rangeTypeName, rangestr - rangeTypeName);
964 buf =
psprintf(
"%s%s%s", prefix,
"multi", rangestr);
977 errmsg(
"type \"%s\" already exists",
buf),
978 errdetail(
"Failed while creating a multirange type for type \"%s\".", rangeTypeName),
979 errhint(
"You can manually specify a multirange type name using the \"multirange_type_name\" attribute.")));
#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 Assert(condition)
#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_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
char * makeObjectName(const char *name1, const char *name2, const char *label)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
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)
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
static Datum PointerGetDatum(const void *X)
static Datum Int16GetDatum(int16 X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
static Datum NameGetDatum(const NameData *X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
static Datum CharGetDatum(char X)
char * psprintf(const char *fmt,...)
void * stringToNode(const char *str)
#define RelationGetDescr(relation)
#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)