36 #include "utils/fmgroids.h"
65 bool nulls[Natts_pg_type];
76 tupDesc = pg_type_desc->
rd_att;
81 for (
i = 0;
i < Natts_pg_type; ++
i)
124 nulls[Anum_pg_type_typdefaultbin - 1] =
true;
125 nulls[Anum_pg_type_typdefault - 1] =
true;
126 nulls[Anum_pg_type_typacl - 1] =
true;
133 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
134 errmsg(
"pg_type OID value not set when in binary upgrade mode")));
197 const char *typeName,
209 Oid receiveProcedure,
211 Oid typmodinProcedure,
212 Oid typmodoutProcedure,
213 Oid analyzeProcedure,
214 Oid subscriptProcedure,
216 bool isImplicitArray,
219 const char *defaultTypeValue,
220 char *defaultTypeBin,
231 bool isDependentType;
232 bool rebuildDeps =
false;
235 bool nulls[Natts_pg_type];
236 bool replaces[Natts_pg_type];
249 if (!(internalSize > 0 ||
250 internalSize == -1 ||
253 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
254 errmsg(
"invalid type internal size %d",
265 if (internalSize == (
int16)
sizeof(
char))
267 if (alignment != TYPALIGN_CHAR)
269 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
270 errmsg(
"alignment \"%c\" is invalid for passed-by-value type of size %d",
271 alignment, internalSize)));
273 else if (internalSize == (
int16)
sizeof(
int16))
275 if (alignment != TYPALIGN_SHORT)
277 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
278 errmsg(
"alignment \"%c\" is invalid for passed-by-value type of size %d",
279 alignment, internalSize)));
281 else if (internalSize == (
int16)
sizeof(
int32))
283 if (alignment != TYPALIGN_INT)
285 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
286 errmsg(
"alignment \"%c\" is invalid for passed-by-value type of size %d",
287 alignment, internalSize)));
289 #if SIZEOF_DATUM == 8
290 else if (internalSize == (
int16)
sizeof(
Datum))
292 if (alignment != TYPALIGN_DOUBLE)
294 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
295 errmsg(
"alignment \"%c\" is invalid for passed-by-value type of size %d",
296 alignment, internalSize)));
301 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
302 errmsg(
"internal size %d is invalid for passed-by-value type",
308 if (internalSize == -1 &&
309 !(alignment == TYPALIGN_INT || alignment == TYPALIGN_DOUBLE))
311 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
312 errmsg(
"alignment \"%c\" is invalid for variable-length type",
315 if (internalSize == -2 && !(alignment == TYPALIGN_CHAR))
317 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
318 errmsg(
"alignment \"%c\" is invalid for variable-length type",
323 if (
storage != TYPSTORAGE_PLAIN && internalSize != -1)
325 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
326 errmsg(
"fixed-size types must have storage PLAIN")));
336 isDependentType = isImplicitArray ||
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")));
561 bool isImplicitArray,
562 bool isDependentType,
563 bool makeExtensionDep,
567 Oid typeObjectId = typeForm->oid;
575 if (defaultExpr == NULL)
577 datum =
heap_getattr(typeTuple, Anum_pg_type_typdefaultbin,
610 if (!isDependentType)
613 typeForm->typnamespace);
620 typeForm->typowner, typacl);
622 if (makeExtensionDep)
687 typeForm->typcollation != DEFAULT_COLLATION_OID)
713 if (relationKind != RELKIND_COMPOSITE_TYPE)
754 elog(
ERROR,
"cache lookup failed for type %u", typeOid);
758 Assert(typeNamespace == typ->typnamespace);
760 arrayOid = typ->typarray;
782 errmsg(
"type \"%s\" already exists", newTypeName)));
800 if (
OidIsValid(arrayOid) && arrayOid != oldTypeOid)
849 snprintf(suffix,
sizeof(suffix),
"%d", ++pass);
936 rangestr = strstr(rangeTypeName,
"range");
939 char *prefix =
pnstrdup(rangeTypeName, rangestr - rangeTypeName);
941 buf =
psprintf(
"%s%s%s", prefix,
"multi", rangestr);
954 errmsg(
"type \"%s\" already exists",
buf),
955 errdetail(
"Failed while creating a multirange type for type \"%s\".", rangeTypeName),
956 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 PointerIsValid(pointer)
#define OidIsValid(objectId)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
elog(ERROR, "%s: %s", p2, msg)
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)
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)
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)
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)