36 #include "utils/fmgroids.h" 68 bool nulls[Natts_pg_type];
79 tupDesc = pg_type_desc->
rd_att;
84 for (i = 0; i < Natts_pg_type; ++
i)
104 values[Anum_pg_type_typtype - 1] =
CharGetDatum(TYPTYPE_PSEUDO);
105 values[Anum_pg_type_typcategory - 1] =
CharGetDatum(TYPCATEGORY_PSEUDOTYPE);
106 values[Anum_pg_type_typispreferred - 1] =
BoolGetDatum(
false);
107 values[Anum_pg_type_typisdefined - 1] =
BoolGetDatum(
false);
120 values[Anum_pg_type_typalign - 1] =
CharGetDatum(TYPALIGN_INT);
121 values[Anum_pg_type_typstorage - 1] =
CharGetDatum(TYPSTORAGE_PLAIN);
122 values[Anum_pg_type_typnotnull - 1] =
BoolGetDatum(
false);
127 nulls[Anum_pg_type_typdefaultbin - 1] =
true;
128 nulls[Anum_pg_type_typdefault - 1] =
true;
129 nulls[Anum_pg_type_typacl - 1] =
true;
136 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
137 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)
358 values[Anum_pg_type_typlen - 1] =
Int16GetDatum(internalSize);
359 values[Anum_pg_type_typbyval - 1] =
BoolGetDatum(passedByValue);
360 values[Anum_pg_type_typtype - 1] =
CharGetDatum(typeType);
361 values[Anum_pg_type_typcategory - 1] =
CharGetDatum(typeCategory);
362 values[Anum_pg_type_typispreferred - 1] =
BoolGetDatum(typePreferred);
363 values[Anum_pg_type_typisdefined - 1] =
BoolGetDatum(
true);
364 values[Anum_pg_type_typdelim - 1] =
CharGetDatum(typDelim);
366 values[Anum_pg_type_typsubscript - 1] =
ObjectIdGetDatum(subscriptProcedure);
376 values[Anum_pg_type_typalign - 1] =
CharGetDatum(alignment);
377 values[Anum_pg_type_typstorage - 1] =
CharGetDatum(storage);
378 values[Anum_pg_type_typnotnull - 1] =
BoolGetDatum(typeNotNull);
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")));
535 elog(
ERROR,
"cache lookup failed for type %u", typeoid);
540 else if (typeTup->typtype == TYPTYPE_COMPOSITE)
558 else if (typeTup->typtype == TYPTYPE_DOMAIN)
565 else if (typeTup->typtype == TYPTYPE_RANGE)
614 bool isImplicitArray,
615 bool isDependentType,
619 Oid typeObjectId = typeForm->oid;
627 if (defaultExpr == NULL)
629 datum =
heap_getattr(typeTuple, Anum_pg_type_typdefaultbin,
662 if (!isDependentType)
665 typeForm->typnamespace);
672 typeForm->typowner, typacl);
738 typeForm->typcollation != DEFAULT_COLLATION_OID)
764 if (relationKind != RELKIND_COMPOSITE_TYPE)
805 elog(
ERROR,
"cache lookup failed for type %u", typeOid);
809 Assert(typeNamespace == typ->typnamespace);
811 arrayOid = typ->typarray;
833 errmsg(
"type \"%s\" already exists", newTypeName)));
851 if (
OidIsValid(arrayOid) && arrayOid != oldTypeOid)
876 errmsg(
"could not form array type name for type \"%s\"",
962 rangestr = strstr(rangeTypeName,
"range");
965 char *prefix =
pnstrdup(rangeTypeName, rangestr - rangeTypeName);
967 buf =
psprintf(
"%s%s%s", prefix,
"multi", rangestr);
980 errmsg(
"type \"%s\" already exists", buf),
981 errdetail(
"Failed while creating a multirange type for type \"%s\".", rangeTypeName),
982 errhint(
"You can manually specify a multirange type name using the \"multirange_type_name\" attribute")));
1015 namelen = strlen(typeName);
1019 strlcpy(dest + i, typeName, NAMEDATALEN - i);
1020 if (namelen + i >= NAMEDATALEN)
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
char * makeArrayTypeName(const char *typeName, Oid typeNamespace)
void table_close(Relation relation, LOCKMODE lockmode)
int errhint(const char *fmt,...)
char * pnstrdup(const char *in, Size len)
List * list_append_unique_oid(List *list, Oid datum)
#define InvokeObjectPostCreateHook(classId, objectId, subId)
#define RelationGetDescr(relation)
void namestrcpy(Name name, const char *str)
#define RelationGetNumberOfAttributes(relation)
Oid get_element_type(Oid typid)
#define PointerGetDatum(X)
#define TupleDescAttr(tupdesc, i)
Oid get_array_type(Oid typid)
char * pstrdup(const char *in)
char * psprintf(const char *fmt,...)
void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)
long deleteDependencyRecordsFor(Oid classId, Oid objectId, bool skipExtensionDeps)
bool get_typisdefined(Oid typid)
int errcode(int sqlerrcode)
void * stringToNode(const char *str)
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
ObjectAddresses * new_object_addresses(void)
void free_object_addresses(ObjectAddresses *addrs)
void heap_freetuple(HeapTuple htup)
ObjectAddress TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
#define OidIsValid(objectId)
void truncate_identifier(char *ident, int len, bool warn)
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
void pfree(void *pointer)
static char * makeUniqueTypeName(const char *typeName, Oid typeNamespace, bool tryOriginal)
#define ObjectIdGetDatum(X)
List * list_concat_unique_oid(List *list1, const List *list2)
Relation relation_open(Oid relationId, LOCKMODE lockmode)
int pg_mbcliplen(const char *mbstr, int len, int limit)
bool moveArrayTypeName(Oid typeOid, const char *typeName, Oid typeNamespace)
int errdetail(const char *fmt,...)
#define CStringGetDatum(X)
void recordDependencyOnExpr(const ObjectAddress *depender, Node *expr, List *rtable, DependencyType behavior)
FormData_pg_attribute * Form_pg_attribute
#define InvokeObjectPostAlterHook(classId, objectId, subId)
void deleteSharedDependencyRecordsFor(Oid classId, Oid objectId, int32 objectSubId)
Oid binary_upgrade_next_pg_type_oid
#define heap_getattr(tup, attnum, tupleDesc, isnull)
void RenameTypeInternal(Oid typeOid, const char *newTypeName, Oid typeNamespace)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
#define TextDatumGetCString(d)
void CommandCounterIncrement(void)
void ReleaseSysCache(HeapTuple tuple)
#define ereport(elevel,...)
size_t strlcpy(char *dst, const char *src, size_t siz)
#define HeapTupleIsValid(tuple)
void relation_close(Relation relation, LOCKMODE lockmode)
#define Assert(condition)
void GenerateTypeDependencies(HeapTuple typeTuple, Relation typeCatalog, Node *defaultExpr, void *typacl, char relationKind, bool isImplicitArray, bool isDependentType, bool rebuild)
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
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)
FormData_pg_type * Form_pg_type
char * makeMultirangeTypeName(const char *rangeTypeName, Oid typeNamespace)
#define SearchSysCacheExists2(cacheId, key1, key2)
#define ObjectAddressSet(addr, class_id, object_id)
void recordDependencyOnNewAcl(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, Acl *acl)
static Datum values[MAXATTR]
#define IsBootstrapProcessingMode()
#define SearchSysCacheCopy1(cacheId, key1)
List * GetTypeCollations(Oid typeoid)
int errmsg(const char *fmt,...)
#define CStringGetTextDatum(s)
#define SearchSysCacheCopy2(cacheId, key1, key2)
Relation table_open(Oid relationId, LOCKMODE lockmode)
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
#define ERRCODE_DUPLICATE_OBJECT
#define PointerIsValid(pointer)
Oid get_range_subtype(Oid rangeOid)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Acl * get_user_default_acl(ObjectType objtype, Oid ownerId, Oid nsp_oid)
#define DatumGetAclPCopy(X)