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 else if (internalSize == (
int16)
sizeof(
int64))
290 if (alignment != TYPALIGN_DOUBLE)
292 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
293 errmsg(
"alignment \"%c\" is invalid for passed-by-value type of size %d",
294 alignment, internalSize)));
298 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
299 errmsg(
"internal size %d is invalid for passed-by-value type",
305 if (internalSize == -1 &&
306 !(alignment == TYPALIGN_INT || alignment == TYPALIGN_DOUBLE))
308 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
309 errmsg(
"alignment \"%c\" is invalid for variable-length type",
312 if (internalSize == -2 && !(alignment == TYPALIGN_CHAR))
314 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
315 errmsg(
"alignment \"%c\" is invalid for variable-length type",
320 if (
storage != TYPSTORAGE_PLAIN && internalSize != -1)
322 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
323 errmsg(
"fixed-size types must have storage PLAIN")));
333 isDependentType = isImplicitArray ||
334 typeType == TYPTYPE_MULTIRANGE ||
335 (
OidIsValid(relationOid) && relationKind != RELKIND_COMPOSITE_TYPE);
340 for (
i = 0;
i < Natts_pg_type; ++
i)
387 nulls[Anum_pg_type_typdefaultbin - 1] =
true;
392 if (defaultTypeValue)
395 nulls[Anum_pg_type_typdefault - 1] =
true;
408 nulls[Anum_pg_type_typacl - 1] =
true;
429 if (typform->typisdefined)
432 errmsg(
"type \"%s\" already exists", typeName)));
437 if (typform->typowner != ownerId)
442 elog(
ERROR,
"cannot assign new OID to existing shell type");
444 replaces[Anum_pg_type_oid - 1] =
false;
457 typeObjectId = typform->oid;
465 typeObjectId = newTypeOid;
471 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
472 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,
611 if (!isDependentType || typeForm->typtype == TYPTYPE_MULTIRANGE)
614 typeForm->typnamespace);
618 if (!isDependentType)
624 typeForm->typowner, typacl);
634 if (makeExtensionDep)
698 typeForm->typcollation != DEFAULT_COLLATION_OID)
724 if (relationKind != RELKIND_COMPOSITE_TYPE)
775 elog(
ERROR,
"cache lookup failed for type %u", typeOid);
779 Assert(typeNamespace == typ->typnamespace);
781 arrayOid = typ->typarray;
803 errmsg(
"type \"%s\" already exists", newTypeName)));
821 if (
OidIsValid(arrayOid) && arrayOid != oldTypeOid)
870 snprintf(suffix,
sizeof(suffix),
"%d", ++pass);
957 rangestr = strstr(rangeTypeName,
"range");
960 char *prefix =
pnstrdup(rangeTypeName, rangestr - rangeTypeName);
962 buf =
psprintf(
"%s%s%s", prefix,
"multi", rangestr);
975 errmsg(
"type \"%s\" already exists",
buf),
976 errdetail(
"Failed while creating a multirange type for type \"%s\".", rangeTypeName),
977 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 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)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
ObjectAddresses * new_object_addresses(void)
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,...)
Assert(PointerIsAligned(start, uint64))
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)
static void * GETSTRUCT(const HeapTupleData *tuple)
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 * pstrdup(const char *in)
void pfree(void *pointer)
char * pnstrdup(const char *in, Size len)
#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)
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)
bool moveArrayTypeName(Oid typeOid, const char *typeName, Oid typeNamespace)
ObjectAddress TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
char * makeMultirangeTypeName(const char *rangeTypeName, Oid typeNamespace)
char * makeArrayTypeName(const char *typeName, Oid typeNamespace)
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)