PostgreSQL Source Code git master
Loading...
Searching...
No Matches
objectaddress.h File Reference
#include "access/htup.h"
#include "catalog/syscache_ids.h"
#include "nodes/parsenodes.h"
#include "storage/lockdefs.h"
#include "utils/relcache.h"
Include dependency graph for objectaddress.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ObjectAddress
 

Macros

#define ObjectAddressSubSet(addr, class_id, object_id, object_sub_id)
 
#define ObjectAddressSet(addr, class_id, object_id)    ObjectAddressSubSet(addr, class_id, object_id, 0)
 

Typedefs

typedef struct ObjectAddress ObjectAddress
 

Functions

ObjectAddress get_object_address (ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
ObjectAddress get_object_address_rv (ObjectType objtype, RangeVar *rel, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
void check_object_ownership (Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
 
Oid get_object_namespace (const ObjectAddress *address)
 
bool is_objectclass_supported (Oid class_id)
 
const charget_object_class_descr (Oid class_id)
 
Oid get_object_oid_index (Oid class_id)
 
SysCacheIdentifier get_object_catcache_oid (Oid class_id)
 
SysCacheIdentifier get_object_catcache_name (Oid class_id)
 
AttrNumber get_object_attnum_oid (Oid class_id)
 
AttrNumber get_object_attnum_name (Oid class_id)
 
AttrNumber get_object_attnum_namespace (Oid class_id)
 
AttrNumber get_object_attnum_owner (Oid class_id)
 
AttrNumber get_object_attnum_acl (Oid class_id)
 
ObjectType get_object_type (Oid class_id, Oid object_id)
 
bool get_object_namensp_unique (Oid class_id)
 
HeapTuple get_catalog_object_by_oid (Relation catalog, AttrNumber oidcol, Oid objectId)
 
HeapTuple get_catalog_object_by_oid_extended (Relation catalog, AttrNumber oidcol, Oid objectId, bool locktup)
 
chargetObjectDescription (const ObjectAddress *object, bool missing_ok)
 
chargetObjectDescriptionOids (Oid classid, Oid objid)
 
int read_objtype_from_string (const char *objtype)
 
chargetObjectTypeDescription (const ObjectAddress *object, bool missing_ok)
 
chargetObjectIdentity (const ObjectAddress *object, bool missing_ok)
 
chargetObjectIdentityParts (const ObjectAddress *object, List **objname, List **objargs, bool missing_ok)
 
struct ArrayTypestrlist_to_textarray (List *list)
 
ObjectType get_relkind_objtype (char relkind)
 

Variables

PGDLLIMPORT const ObjectAddress InvalidObjectAddress
 

Macro Definition Documentation

◆ ObjectAddressSet

#define ObjectAddressSet (   addr,
  class_id,
  object_id 
)     ObjectAddressSubSet(addr, class_id, object_id, 0)

Definition at line 41 of file objectaddress.h.

◆ ObjectAddressSubSet

#define ObjectAddressSubSet (   addr,
  class_id,
  object_id,
  object_sub_id 
)
Value:
do { \
(addr).classId = (class_id); \
(addr).objectId = (object_id); \
(addr).objectSubId = (object_sub_id); \
} while (0)
static int fb(int x)

Definition at line 34 of file objectaddress.h.

35 { \
36 (addr).classId = (class_id); \
37 (addr).objectId = (object_id); \
38 (addr).objectSubId = (object_sub_id); \
39 } while (0)

Typedef Documentation

◆ ObjectAddress

Function Documentation

◆ check_object_ownership()

void check_object_ownership ( Oid  roleid,
ObjectType  objtype,
ObjectAddress  address,
Node object,
Relation  relation 
)
extern

Definition at line 2493 of file objectaddress.c.

2495{
2496 switch (objtype)
2497 {
2498 case OBJECT_INDEX:
2499 case OBJECT_SEQUENCE:
2500 case OBJECT_TABLE:
2501 case OBJECT_VIEW:
2502 case OBJECT_MATVIEW:
2504 case OBJECT_PROPGRAPH:
2505 case OBJECT_COLUMN:
2506 case OBJECT_RULE:
2507 case OBJECT_TRIGGER:
2508 case OBJECT_POLICY:
2510 if (!object_ownercheck(RelationRelationId, RelationGetRelid(relation), roleid))
2512 RelationGetRelationName(relation));
2513 break;
2514 case OBJECT_TYPE:
2515 case OBJECT_DOMAIN:
2516 case OBJECT_ATTRIBUTE:
2517 if (!object_ownercheck(address.classId, address.objectId, roleid))
2519 break;
2521 {
2522 HeapTuple tuple;
2523 Oid contypid;
2524
2525 tuple = SearchSysCache1(CONSTROID,
2526 ObjectIdGetDatum(address.objectId));
2527 if (!HeapTupleIsValid(tuple))
2528 elog(ERROR, "constraint with OID %u does not exist",
2529 address.objectId);
2530
2532
2533 ReleaseSysCache(tuple);
2534
2535 /*
2536 * Fallback to type ownership check in this case as this is
2537 * what domain constraints rely on.
2538 */
2541 }
2542 break;
2543 case OBJECT_AGGREGATE:
2544 case OBJECT_FUNCTION:
2545 case OBJECT_PROCEDURE:
2546 case OBJECT_ROUTINE:
2547 case OBJECT_OPERATOR:
2548 if (!object_ownercheck(address.classId, address.objectId, roleid))
2550 NameListToString((castNode(ObjectWithArgs, object))->objname));
2551 break;
2552 case OBJECT_DATABASE:
2554 case OBJECT_EXTENSION:
2555 case OBJECT_FDW:
2557 case OBJECT_LANGUAGE:
2558 case OBJECT_PUBLICATION:
2559 case OBJECT_SCHEMA:
2561 case OBJECT_TABLESPACE:
2562 if (!object_ownercheck(address.classId, address.objectId, roleid))
2564 strVal(object));
2565 break;
2566 case OBJECT_COLLATION:
2567 case OBJECT_CONVERSION:
2568 case OBJECT_OPCLASS:
2569 case OBJECT_OPFAMILY:
2573 if (!object_ownercheck(address.classId, address.objectId, roleid))
2575 NameListToString(castNode(List, object)));
2576 break;
2577 case OBJECT_LARGEOBJECT:
2578 if (!lo_compat_privileges &&
2579 !object_ownercheck(address.classId, address.objectId, roleid))
2580 ereport(ERROR,
2582 errmsg("must be owner of large object %u",
2583 address.objectId)));
2584 break;
2585 case OBJECT_CAST:
2586 {
2587 /* We can only check permissions on the source/target types */
2588 TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2589 TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2590 Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2591 Oid targettypeid = typenameTypeId(NULL, targettype);
2592
2595 ereport(ERROR,
2597 errmsg("must be owner of type %s or type %s",
2600 }
2601 break;
2602 case OBJECT_TRANSFORM:
2603 {
2604 TypeName *typename = linitial_node(TypeName, castNode(List, object));
2605 Oid typeid = typenameTypeId(NULL, typename);
2606
2607 if (!object_ownercheck(TypeRelationId, typeid, roleid))
2609 }
2610 break;
2611 case OBJECT_ROLE:
2612
2613 /*
2614 * We treat roles as being "owned" by those with CREATEROLE priv,
2615 * provided that they also have admin option on the role.
2616 *
2617 * However, superusers are only owned by superusers.
2618 */
2619 if (superuser_arg(address.objectId))
2620 {
2621 if (!superuser_arg(roleid))
2622 ereport(ERROR,
2624 errmsg("permission denied"),
2625 errdetail("The current user must have the %s attribute.",
2626 "SUPERUSER")));
2627 }
2628 else
2629 {
2630 if (!has_createrole_privilege(roleid))
2631 ereport(ERROR,
2633 errmsg("permission denied"),
2634 errdetail("The current user must have the %s attribute.",
2635 "CREATEROLE")));
2636 if (!is_admin_of_role(roleid, address.objectId))
2637 ereport(ERROR,
2639 errmsg("permission denied"),
2640 errdetail("The current user must have the %s option on role \"%s\".",
2641 "ADMIN",
2643 true))));
2644 }
2645 break;
2646 case OBJECT_TSPARSER:
2647 case OBJECT_TSTEMPLATE:
2650 /* We treat these object types as being owned by superusers */
2651 if (!superuser_arg(roleid))
2652 ereport(ERROR,
2654 errmsg("must be superuser")));
2655 break;
2656 case OBJECT_AMOP:
2657 case OBJECT_AMPROC:
2658 case OBJECT_DEFAULT:
2659 case OBJECT_DEFACL:
2663 /* These are currently not supported or don't make sense here. */
2664 elog(ERROR, "unsupported object type: %d", (int) objtype);
2665 break;
2666 }
2667}
bool is_admin_of_role(Oid member, Oid role)
Definition acl.c:5447
@ ACLCHECK_NOT_OWNER
Definition acl.h:186
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition aclchk.c:2672
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition aclchk.c:4156
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition aclchk.c:2997
bool has_createrole_privilege(Oid roleid)
Definition aclchk.c:4235
int errcode(int sqlerrcode)
Definition elog.c:875
int errdetail(const char *fmt,...) pg_attribute_printf(1
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
#define ereport(elevel,...)
Definition elog.h:152
char * format_type_be(Oid type_oid)
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
bool lo_compat_privileges
Definition inv_api.c:56
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition miscinit.c:990
char * NameListToString(const List *names)
Definition namespace.c:3666
#define castNode(_type_, nodeptr)
Definition nodes.h:180
static char * errmsg
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition parse_type.c:291
@ OBJECT_EVENT_TRIGGER
@ OBJECT_FDW
@ OBJECT_TSPARSER
@ OBJECT_COLLATION
@ OBJECT_USER_MAPPING
@ OBJECT_PROPGRAPH
@ OBJECT_ACCESS_METHOD
@ OBJECT_OPCLASS
@ OBJECT_DEFACL
@ OBJECT_AGGREGATE
@ OBJECT_MATVIEW
@ OBJECT_SCHEMA
@ OBJECT_POLICY
@ OBJECT_OPERATOR
@ OBJECT_FOREIGN_TABLE
@ OBJECT_TSCONFIGURATION
@ OBJECT_OPFAMILY
@ OBJECT_DOMAIN
@ OBJECT_COLUMN
@ OBJECT_TABLESPACE
@ OBJECT_ROLE
@ OBJECT_ROUTINE
@ OBJECT_LARGEOBJECT
@ OBJECT_PUBLICATION_NAMESPACE
@ OBJECT_PROCEDURE
@ OBJECT_EXTENSION
@ OBJECT_INDEX
@ OBJECT_DEFAULT
@ OBJECT_DATABASE
@ OBJECT_SEQUENCE
@ OBJECT_TSTEMPLATE
@ OBJECT_LANGUAGE
@ OBJECT_AMOP
@ OBJECT_PUBLICATION_REL
@ OBJECT_FOREIGN_SERVER
@ OBJECT_TSDICTIONARY
@ OBJECT_ATTRIBUTE
@ OBJECT_PUBLICATION
@ OBJECT_RULE
@ OBJECT_CONVERSION
@ OBJECT_AMPROC
@ OBJECT_TABLE
@ OBJECT_VIEW
@ OBJECT_PARAMETER_ACL
@ OBJECT_TYPE
@ OBJECT_FUNCTION
@ OBJECT_TABCONSTRAINT
@ OBJECT_DOMCONSTRAINT
@ OBJECT_SUBSCRIPTION
@ OBJECT_STATISTIC_EXT
@ OBJECT_CAST
@ OBJECT_TRIGGER
@ OBJECT_TRANSFORM
END_CATALOG_STRUCT typedef FormData_pg_constraint * Form_pg_constraint
#define linitial_node(type, l)
Definition pg_list.h:181
#define lsecond_node(type, l)
Definition pg_list.h:186
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
unsigned int Oid
#define RelationGetRelid(relation)
Definition rel.h:516
#define RelationGetRelationName(relation)
Definition rel.h:550
Definition pg_list.h:54
bool superuser_arg(Oid roleid)
Definition superuser.c:57
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:265
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:221
#define strVal(v)
Definition value.h:82

References aclcheck_error(), aclcheck_error_type(), ACLCHECK_NOT_OWNER, castNode, ObjectAddress::classId, elog, ereport, errcode(), errdetail(), errmsg, ERROR, fb(), Form_pg_constraint, format_type_be(), GETSTRUCT(), GetUserNameFromId(), has_createrole_privilege(), HeapTupleIsValid, is_admin_of_role(), linitial_node, lo_compat_privileges, lsecond_node, NameListToString(), OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_AMOP, OBJECT_AMPROC, OBJECT_ATTRIBUTE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DEFACL, OBJECT_DEFAULT, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, object_ownercheck(), OBJECT_PARAMETER_ACL, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PROPGRAPH, OBJECT_PUBLICATION, OBJECT_PUBLICATION_NAMESPACE, OBJECT_PUBLICATION_REL, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_USER_MAPPING, OBJECT_VIEW, ObjectAddress::objectId, ObjectIdGetDatum(), RelationGetRelationName, RelationGetRelid, ReleaseSysCache(), SearchSysCache1(), strVal, superuser_arg(), and typenameTypeId().

Referenced by CommentObject(), ExecAlterExtensionContentsStmt(), ExecAlterObjectDependsStmt(), ExecSecLabelStmt(), and RemoveObjects().

◆ get_catalog_object_by_oid()

HeapTuple get_catalog_object_by_oid ( Relation  catalog,
AttrNumber  oidcol,
Oid  objectId 
)
extern

Definition at line 2888 of file objectaddress.c.

2889{
2890 return
2892}
HeapTuple get_catalog_object_by_oid_extended(Relation catalog, AttrNumber oidcol, Oid objectId, bool locktup)

References fb(), and get_catalog_object_by_oid_extended().

Referenced by getConstraintTypeDescription(), getObjectDescription(), getObjectIdentityParts(), obtain_object_name_namespace(), pg_event_trigger_ddl_commands(), pg_get_acl(), and pg_identify_object().

◆ get_catalog_object_by_oid_extended()

HeapTuple get_catalog_object_by_oid_extended ( Relation  catalog,
AttrNumber  oidcol,
Oid  objectId,
bool  locktup 
)
extern

Definition at line 2901 of file objectaddress.c.

2905{
2906 HeapTuple tuple;
2907 Oid classId = RelationGetRelid(catalog);
2909
2910 if (oidCacheId >= 0)
2911 {
2912 if (locktup)
2914 ObjectIdGetDatum(objectId));
2915 else
2917 ObjectIdGetDatum(objectId));
2918 if (!HeapTupleIsValid(tuple)) /* should not happen */
2919 return NULL;
2920 }
2921 else
2922 {
2924 SysScanDesc scan;
2926
2928
2930 oidcol,
2932 ObjectIdGetDatum(objectId));
2933
2935 NULL, 1, &skey);
2936 tuple = systable_getnext(scan);
2937 if (!HeapTupleIsValid(tuple))
2938 {
2939 systable_endscan(scan);
2940 return NULL;
2941 }
2942
2943 if (locktup)
2945
2946 tuple = heap_copytuple(tuple);
2947
2948 systable_endscan(scan);
2949 }
2950
2951 return tuple;
2952}
#define Assert(condition)
Definition c.h:1002
#define OidIsValid(objectId)
Definition c.h:917
void systable_endscan(SysScanDesc sysscan)
Definition genam.c:604
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition genam.c:515
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition genam.c:388
HeapTuple heap_copytuple(HeapTuple tuple)
Definition heaptuple.c:686
void LockTuple(Relation relation, const ItemPointerData *tid, LOCKMODE lockmode)
Definition lmgr.c:562
#define InplaceUpdateTupleLock
Definition lockdefs.h:48
Oid get_object_oid_index(Oid class_id)
SysCacheIdentifier get_object_catcache_oid(Oid class_id)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition scankey.c:76
#define BTEqualStrategyNumber
Definition stratnum.h:31
ItemPointerData t_self
Definition htup.h:65
HeapTuple SearchSysCacheLockedCopy1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:400
#define SearchSysCacheCopy1(cacheId, key1)
Definition syscache.h:91

References Assert, BTEqualStrategyNumber, fb(), get_object_catcache_oid(), get_object_oid_index(), heap_copytuple(), HeapTupleIsValid, InplaceUpdateTupleLock, LockTuple(), ObjectIdGetDatum(), OidIsValid, RelationGetRelid, ScanKeyInit(), SearchSysCacheCopy1, SearchSysCacheLockedCopy1(), systable_beginscan(), systable_endscan(), systable_getnext(), and HeapTupleData::t_self.

Referenced by AlterObjectOwner_internal(), and get_catalog_object_by_oid().

◆ get_object_address()

ObjectAddress get_object_address ( ObjectType  objtype,
Node object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
extern

Definition at line 1016 of file objectaddress.c.

1018{
1019 ObjectAddress address = {InvalidOid, InvalidOid, 0};
1021 Relation relation = NULL;
1023
1024 /* Some kind of lock must be taken. */
1025 Assert(lockmode != NoLock);
1026
1027 for (;;)
1028 {
1029 /*
1030 * Remember this value, so that, after looking up the object name and
1031 * locking it, we can check whether any invalidation messages have
1032 * been processed that might require a do-over.
1033 */
1035
1036 /* Look up object address. */
1037 switch (objtype)
1038 {
1039 case OBJECT_INDEX:
1040 case OBJECT_SEQUENCE:
1041 case OBJECT_TABLE:
1042 case OBJECT_VIEW:
1043 case OBJECT_MATVIEW:
1045 case OBJECT_PROPGRAPH:
1046 address =
1048 &relation, lockmode,
1049 missing_ok);
1050 break;
1051 case OBJECT_ATTRIBUTE:
1052 case OBJECT_COLUMN:
1053 address =
1054 get_object_address_attribute(objtype, castNode(List, object),
1055 &relation, lockmode,
1056 missing_ok);
1057 break;
1058 case OBJECT_DEFAULT:
1059 address =
1060 get_object_address_attrdef(objtype, castNode(List, object),
1061 &relation, lockmode,
1062 missing_ok);
1063 break;
1064 case OBJECT_RULE:
1065 case OBJECT_TRIGGER:
1067 case OBJECT_POLICY:
1068 address = get_object_address_relobject(objtype, castNode(List, object),
1069 &relation, missing_ok);
1070 break;
1072 {
1073 List *objlist;
1075 char *constrname;
1076
1077 objlist = castNode(List, object);
1080 missing_ok);
1082
1083 address.classId = ConstraintRelationId;
1084 address.objectId = get_domain_constraint_oid(domaddr.objectId,
1085 constrname, missing_ok);
1086 address.objectSubId = 0;
1087 }
1088 break;
1089 case OBJECT_DATABASE:
1090 case OBJECT_EXTENSION:
1091 case OBJECT_TABLESPACE:
1092 case OBJECT_ROLE:
1093 case OBJECT_SCHEMA:
1094 case OBJECT_LANGUAGE:
1095 case OBJECT_FDW:
1100 case OBJECT_PUBLICATION:
1102 address = get_object_address_unqualified(objtype,
1103 castNode(String, object), missing_ok);
1104 break;
1105 case OBJECT_TYPE:
1106 case OBJECT_DOMAIN:
1107 address = get_object_address_type(objtype, castNode(TypeName, object), missing_ok);
1108 break;
1109 case OBJECT_AGGREGATE:
1110 case OBJECT_FUNCTION:
1111 case OBJECT_PROCEDURE:
1112 case OBJECT_ROUTINE:
1113 address.classId = ProcedureRelationId;
1114 address.objectId = LookupFuncWithArgs(objtype, castNode(ObjectWithArgs, object), missing_ok);
1115 address.objectSubId = 0;
1116 break;
1117 case OBJECT_OPERATOR:
1118 address.classId = OperatorRelationId;
1119 address.objectId = LookupOperWithArgs(castNode(ObjectWithArgs, object), missing_ok);
1120 address.objectSubId = 0;
1121 break;
1122 case OBJECT_COLLATION:
1123 address.classId = CollationRelationId;
1124 address.objectId = get_collation_oid(castNode(List, object), missing_ok);
1125 address.objectSubId = 0;
1126 break;
1127 case OBJECT_CONVERSION:
1128 address.classId = ConversionRelationId;
1129 address.objectId = get_conversion_oid(castNode(List, object), missing_ok);
1130 address.objectSubId = 0;
1131 break;
1132 case OBJECT_OPCLASS:
1133 case OBJECT_OPFAMILY:
1134 address = get_object_address_opcf(objtype, castNode(List, object), missing_ok);
1135 break;
1136 case OBJECT_AMOP:
1137 case OBJECT_AMPROC:
1138 address = get_object_address_opf_member(objtype, castNode(List, object), missing_ok);
1139 break;
1140 case OBJECT_LARGEOBJECT:
1142 address.objectId = oidparse(object);
1143 address.objectSubId = 0;
1144 if (!LargeObjectExists(address.objectId))
1145 {
1146 if (!missing_ok)
1147 ereport(ERROR,
1149 errmsg("large object %u does not exist",
1150 address.objectId)));
1151 }
1152 break;
1153 case OBJECT_CAST:
1154 {
1155 TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
1156 TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
1159
1160 sourcetypeid = LookupTypeNameOid(NULL, sourcetype, missing_ok);
1161 targettypeid = LookupTypeNameOid(NULL, targettype, missing_ok);
1162 address.classId = CastRelationId;
1163 address.objectId =
1165 address.objectSubId = 0;
1166 }
1167 break;
1168 case OBJECT_TRANSFORM:
1169 {
1170 TypeName *typename = linitial_node(TypeName, castNode(List, object));
1171 char *langname = strVal(lsecond(castNode(List, object)));
1172 Oid type_id = LookupTypeNameOid(NULL, typename, missing_ok);
1173 Oid lang_id = get_language_oid(langname, missing_ok);
1174
1175 address.classId = TransformRelationId;
1176 address.objectId =
1177 get_transform_oid(type_id, lang_id, missing_ok);
1178 address.objectSubId = 0;
1179 }
1180 break;
1181 case OBJECT_TSPARSER:
1182 address.classId = TSParserRelationId;
1183 address.objectId = get_ts_parser_oid(castNode(List, object), missing_ok);
1184 address.objectSubId = 0;
1185 break;
1188 address.objectId = get_ts_dict_oid(castNode(List, object), missing_ok);
1189 address.objectSubId = 0;
1190 break;
1191 case OBJECT_TSTEMPLATE:
1192 address.classId = TSTemplateRelationId;
1193 address.objectId = get_ts_template_oid(castNode(List, object), missing_ok);
1194 address.objectSubId = 0;
1195 break;
1197 address.classId = TSConfigRelationId;
1198 address.objectId = get_ts_config_oid(castNode(List, object), missing_ok);
1199 address.objectSubId = 0;
1200 break;
1202 address = get_object_address_usermapping(castNode(List, object),
1203 missing_ok);
1204 break;
1207 missing_ok);
1208 break;
1211 &relation,
1212 missing_ok);
1213 break;
1214 case OBJECT_DEFACL:
1215 address = get_object_address_defacl(castNode(List, object),
1216 missing_ok);
1217 break;
1221 missing_ok);
1222 address.objectSubId = 0;
1223 break;
1224 /* no default, to let compiler warn about missing case */
1225 }
1226
1227 if (!address.classId)
1228 elog(ERROR, "unrecognized object type: %d", (int) objtype);
1229
1230 /*
1231 * If we could not find the supplied object, return without locking.
1232 */
1233 if (!OidIsValid(address.objectId))
1234 {
1235 Assert(missing_ok);
1236 return address;
1237 }
1238
1239 /*
1240 * If we're retrying, see if we got the same answer as last time. If
1241 * so, we're done; if not, we locked the wrong thing, so give up our
1242 * lock.
1243 */
1244 if (OidIsValid(old_address.classId))
1245 {
1246 if (old_address.classId == address.classId
1247 && old_address.objectId == address.objectId
1248 && old_address.objectSubId == address.objectSubId)
1249 break;
1250 if (old_address.classId != RelationRelationId)
1251 {
1252 if (IsSharedRelation(old_address.classId))
1254 old_address.objectId,
1255 0, lockmode);
1256 else
1258 old_address.objectId,
1259 0, lockmode);
1260 }
1261 }
1262
1263 /*
1264 * If we're dealing with a relation or attribute, then the relation is
1265 * already locked. Otherwise, we lock it now.
1266 */
1267 if (address.classId != RelationRelationId)
1268 {
1269 if (IsSharedRelation(address.classId))
1270 LockSharedObject(address.classId, address.objectId, 0,
1271 lockmode);
1272 else
1273 LockDatabaseObject(address.classId, address.objectId, 0,
1274 lockmode);
1275 }
1276
1277 /*
1278 * At this point, we've resolved the name to an OID and locked the
1279 * corresponding database object. However, it's possible that by the
1280 * time we acquire the lock on the object, concurrent DDL has modified
1281 * the database in such a way that the name we originally looked up no
1282 * longer resolves to that OID.
1283 *
1284 * We can be certain that this isn't an issue if (a) no shared
1285 * invalidation messages have been processed or (b) we've locked a
1286 * relation somewhere along the line. All the relation name lookups
1287 * in this module ultimately use RangeVarGetRelid() to acquire a
1288 * relation lock, and that function protects against the same kinds of
1289 * races we're worried about here. Even when operating on a
1290 * constraint, rule, or trigger, we still acquire AccessShareLock on
1291 * the relation, which is enough to freeze out any concurrent DDL.
1292 *
1293 * In all other cases, however, it's possible that the name we looked
1294 * up no longer refers to the object we locked, so we retry the lookup
1295 * and see whether we get the same answer.
1296 */
1297 if (inval_count == SharedInvalidMessageCounter || relation != NULL)
1298 break;
1299 old_address = address;
1300 }
1301
1302 /* relp must be given if it's a relation */
1303 Assert(!relation || relp);
1304
1305 /* Return the object address and the relation. */
1306 if (relp)
1307 *relp = relation;
1308 return address;
1309}
uint64_t uint64
Definition c.h:684
bool IsSharedRelation(Oid relationId)
Definition catalog.c:331
Oid get_transform_oid(Oid type_id, Oid lang_id, bool missing_ok)
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition lmgr.c:1088
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition lmgr.c:1008
void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition lmgr.c:1148
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition lmgr.c:1068
#define NoLock
Definition lockdefs.h:34
Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok)
Definition lsyscache.c:1233
Oid get_statistics_object_oid(List *names, bool missing_ok)
Definition namespace.c:2644
Oid get_collation_oid(List *collname, bool missing_ok)
Definition namespace.c:4043
Oid get_conversion_oid(List *conname, bool missing_ok)
Definition namespace.c:4097
Oid get_ts_dict_oid(List *names, bool missing_ok)
Definition namespace.c:2933
Oid get_ts_parser_oid(List *names, bool missing_ok)
Definition namespace.c:2788
Oid get_ts_config_oid(List *names, bool missing_ok)
Definition namespace.c:3224
Oid get_ts_template_oid(List *names, bool missing_ok)
Definition namespace.c:3079
static ObjectAddress get_object_address_publication_schema(List *object, bool missing_ok)
static ObjectAddress get_object_address_relobject(ObjectType objtype, List *object, Relation *relp, bool missing_ok)
static ObjectAddress get_object_address_defacl(List *object, bool missing_ok)
static ObjectAddress get_object_address_unqualified(ObjectType objtype, String *strval, bool missing_ok)
static ObjectAddress get_object_address_publication_rel(List *object, Relation *relp, bool missing_ok)
static ObjectAddress get_object_address_opf_member(ObjectType objtype, List *object, bool missing_ok)
static ObjectAddress get_object_address_type(ObjectType objtype, TypeName *typename, bool missing_ok)
static ObjectAddress get_object_address_usermapping(List *object, bool missing_ok)
static ObjectAddress get_object_address_opcf(ObjectType objtype, List *object, bool missing_ok)
static ObjectAddress get_object_address_attribute(ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
static ObjectAddress get_relation_by_qualified_name(ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
static ObjectAddress get_object_address_attrdef(ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
Oid oidparse(Node *node)
Definition oid.c:264
Oid LookupFuncWithArgs(ObjectType objtype, ObjectWithArgs *func, bool missing_ok)
Oid LookupOperWithArgs(ObjectWithArgs *oper, bool noError)
Definition parse_oper.c:136
Oid LookupTypeNameOid(ParseState *pstate, const TypeName *typeName, bool missing_ok)
Definition parse_type.c:232
Oid get_domain_constraint_oid(Oid typid, const char *conname, bool missing_ok)
bool LargeObjectExists(Oid loid)
#define lsecond(l)
Definition pg_list.h:183
#define InvalidOid
Oid get_language_oid(const char *langname, bool missing_ok)
Definition proclang.c:227
uint64 SharedInvalidMessageCounter
Definition sinval.c:24
Definition value.h:64

References Assert, castNode, ObjectAddress::classId, elog, ereport, errcode(), errmsg, ERROR, fb(), get_cast_oid(), get_collation_oid(), get_conversion_oid(), get_domain_constraint_oid(), get_language_oid(), get_object_address_attrdef(), get_object_address_attribute(), get_object_address_defacl(), get_object_address_opcf(), get_object_address_opf_member(), get_object_address_publication_rel(), get_object_address_publication_schema(), get_object_address_relobject(), get_object_address_type(), get_object_address_unqualified(), get_object_address_usermapping(), get_relation_by_qualified_name(), get_statistics_object_oid(), get_transform_oid(), get_ts_config_oid(), get_ts_dict_oid(), get_ts_parser_oid(), get_ts_template_oid(), InvalidOid, IsSharedRelation(), LargeObjectExists(), linitial_node, LockDatabaseObject(), LockSharedObject(), LookupFuncWithArgs(), LookupOperWithArgs(), LookupTypeNameOid(), lsecond, lsecond_node, NoLock, OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_AMOP, OBJECT_AMPROC, OBJECT_ATTRIBUTE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DEFACL, OBJECT_DEFAULT, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_PARAMETER_ACL, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PROPGRAPH, OBJECT_PUBLICATION, OBJECT_PUBLICATION_NAMESPACE, OBJECT_PUBLICATION_REL, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_USER_MAPPING, OBJECT_VIEW, ObjectAddress::objectId, ObjectAddress::objectSubId, OidIsValid, oidparse(), SharedInvalidMessageCounter, strVal, UnlockDatabaseObject(), and UnlockSharedObject().

Referenced by CommentObject(), ExecAlterExtensionContentsStmt(), ExecAlterObjectDependsStmt(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecRenameStmt(), ExecSecLabelStmt(), get_object_address_rv(), objectNamesToOids(), pg_get_object_address(), and RemoveObjects().

◆ get_object_address_rv()

ObjectAddress get_object_address_rv ( ObjectType  objtype,
RangeVar rel,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
extern

Definition at line 1319 of file objectaddress.c.

1322{
1323 if (rel)
1324 {
1325 object = lcons(makeString(rel->relname), object);
1326 if (rel->schemaname)
1327 object = lcons(makeString(rel->schemaname), object);
1328 if (rel->catalogname)
1329 object = lcons(makeString(rel->catalogname), object);
1330 }
1331
1332 return get_object_address(objtype, (Node *) object,
1333 relp, lockmode, missing_ok);
1334}
List * lcons(void *datum, List *list)
Definition list.c:495
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
Definition nodes.h:133
char * relname
Definition primnodes.h:84
char * catalogname
Definition primnodes.h:78
char * schemaname
Definition primnodes.h:81
String * makeString(char *str)
Definition value.c:63

References RangeVar::catalogname, fb(), get_object_address(), lcons(), makeString(), RangeVar::relname, and RangeVar::schemaname.

Referenced by ExecAlterObjectDependsStmt(), and ExecAlterOwnerStmt().

◆ get_object_attnum_acl()

AttrNumber get_object_attnum_acl ( Oid  class_id)
extern

Definition at line 2794 of file objectaddress.c.

2795{
2797
2798 return prop->attnum_acl;
2799}
static const ObjectPropertyType * get_object_property_data(Oid class_id)

References ObjectPropertyType::attnum_acl, fb(), and get_object_property_data().

Referenced by AlterObjectOwner_internal(), ExecGrant_common(), object_aclmask_ext(), pg_get_acl(), and recordExtObjInitPriv().

◆ get_object_attnum_name()

◆ get_object_attnum_namespace()

◆ get_object_attnum_oid()

◆ get_object_attnum_owner()

◆ get_object_catcache_name()

SysCacheIdentifier get_object_catcache_name ( Oid  class_id)
extern

Definition at line 2754 of file objectaddress.c.

2755{
2757
2758 return prop->name_catcache_id;
2759}
SysCacheIdentifier name_catcache_id

References fb(), get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

◆ get_object_catcache_oid()

◆ get_object_class_descr()

◆ get_object_namensp_unique()

bool get_object_namensp_unique ( Oid  class_id)
extern

◆ get_object_namespace()

Oid get_object_namespace ( const ObjectAddress address)
extern

Definition at line 2676 of file objectaddress.c.

2677{
2678 SysCacheIdentifier cache;
2679 HeapTuple tuple;
2680 Oid oid;
2682
2683 /* If not owned by a namespace, just return InvalidOid. */
2684 property = get_object_property_data(address->classId);
2685 if (property->attnum_namespace == InvalidAttrNumber)
2686 return InvalidOid;
2687
2688 /* Currently, we can only handle object types with system caches. */
2689 cache = property->oid_catcache_id;
2690 Assert(cache != SYSCACHEID_INVALID);
2691
2692 /* Fetch tuple from syscache and extract namespace attribute. */
2693 tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2694 if (!HeapTupleIsValid(tuple))
2695 elog(ERROR, "cache lookup failed for cache %d oid %u",
2696 cache, address->objectId);
2698 tuple,
2699 property->attnum_namespace));
2700 ReleaseSysCache(tuple);
2701
2702 return oid;
2703}
#define InvalidAttrNumber
Definition attnum.h:23
static Oid DatumGetObjectId(Datum X)
Definition postgres.h:242
Datum SysCacheGetAttrNotNull(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition syscache.c:626

References Assert, ObjectAddress::classId, DatumGetObjectId(), elog, ERROR, fb(), get_object_property_data(), HeapTupleIsValid, InvalidAttrNumber, InvalidOid, ObjectAddress::objectId, ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache1(), and SysCacheGetAttrNotNull().

Referenced by find_temp_object(), and RemoveObjects().

◆ get_object_oid_index()

Oid get_object_oid_index ( Oid  class_id)
extern

◆ get_object_type()

ObjectType get_object_type ( Oid  class_id,
Oid  object_id 
)
extern

Definition at line 2809 of file objectaddress.c.

2810{
2812
2813 if (prop->objtype == OBJECT_TABLE)
2814 {
2815 /*
2816 * If the property data says it's a table, dig a little deeper to get
2817 * the real relation kind, so that callers can produce more precise
2818 * error messages.
2819 */
2820 return get_relkind_objtype(get_rel_relkind(object_id));
2821 }
2822 else
2823 return prop->objtype;
2824}
char get_rel_relkind(Oid relid)
Definition lsyscache.c:2317
ObjectType get_relkind_objtype(char relkind)

References fb(), get_object_property_data(), get_rel_relkind(), get_relkind_objtype(), OBJECT_TABLE, and ObjectPropertyType::objtype.

Referenced by AlterObjectNamespace_internal(), AlterObjectOwner_internal(), AlterObjectRename_internal(), ExecGrant_common(), and object_aclmask_ext().

◆ get_relkind_objtype()

ObjectType get_relkind_objtype ( char  relkind)
extern

Definition at line 6600 of file objectaddress.c.

6601{
6602 switch (relkind)
6603 {
6604 case RELKIND_RELATION:
6606 return OBJECT_TABLE;
6607 case RELKIND_INDEX:
6609 return OBJECT_INDEX;
6610 case RELKIND_SEQUENCE:
6611 return OBJECT_SEQUENCE;
6612 case RELKIND_VIEW:
6613 return OBJECT_VIEW;
6614 case RELKIND_MATVIEW:
6615 return OBJECT_MATVIEW;
6617 return OBJECT_FOREIGN_TABLE;
6618 case RELKIND_PROPGRAPH:
6619 return OBJECT_PROPGRAPH;
6620 case RELKIND_TOASTVALUE:
6621 return OBJECT_TABLE;
6622 default:
6623 /* Per above, don't raise an error */
6624 return OBJECT_TABLE;
6625 }
6626}

References fb(), OBJECT_FOREIGN_TABLE, OBJECT_INDEX, OBJECT_MATVIEW, OBJECT_PROPGRAPH, OBJECT_SEQUENCE, OBJECT_TABLE, and OBJECT_VIEW.

Referenced by AlterTableMoveAll(), ATExecChangeOwner(), ATSimplePermissions(), checkFkeyPermissions(), CreateStatistics(), CreateTriggerFiringOn(), currtid_internal(), DefineQueryRewrite(), EnableDisableRule(), ExecCheckPermissions(), get_object_type(), heap_force_common(), LockViewRecurse_walker(), LogicalRepSyncTableStart(), MergeAttributes(), pg_prewarm(), pgrowlocks(), PublicationAddTables(), RangeVarCallbackForAlterRelation(), RangeVarCallbackForDblink(), RangeVarCallbackForDropRelation(), RangeVarCallbackForLockTable(), RangeVarCallbackForPolicy(), RangeVarCallbackForRenameRule(), RangeVarCallbackForRenameTrigger(), RangeVarCallbackForStats(), RangeVarCallbackMaintainsTable(), RangeVarCallbackOwnsRelation(), RangeVarGetAndCheckCreationNamespace(), renameatt_check(), TargetPrivilegesCheck(), transformTableLikeClause(), and truncate_check_perms().

◆ getObjectDescription()

char * getObjectDescription ( const ObjectAddress object,
bool  missing_ok 
)
extern

Definition at line 3010 of file objectaddress.c.

3011{
3012 StringInfoData buffer;
3013
3014 initStringInfo(&buffer);
3015
3016 switch (object->classId)
3017 {
3018 case RelationRelationId:
3019 if (object->objectSubId == 0)
3020 getRelationDescription(&buffer, object->objectId, missing_ok);
3021 else
3022 {
3023 /* column, not whole relation */
3024 StringInfoData rel;
3025 char *attname = get_attname(object->objectId,
3026 object->objectSubId,
3027 missing_ok);
3028
3029 if (!attname)
3030 break;
3031
3032 initStringInfo(&rel);
3033 getRelationDescription(&rel, object->objectId, missing_ok);
3034 /* translator: second %s is, e.g., "table %s" */
3035 appendStringInfo(&buffer, _("column %s of %s"),
3036 attname, rel.data);
3037 pfree(rel.data);
3038 }
3039 break;
3040
3042 {
3045 flags);
3046
3047 if (proname == NULL)
3048 break;
3049
3050 appendStringInfo(&buffer, _("function %s"), proname);
3051 break;
3052 }
3053
3054 case TypeRelationId:
3055 {
3057 char *typname = format_type_extended(object->objectId, -1,
3058 flags);
3059
3060 if (typname == NULL)
3061 break;
3062
3063 appendStringInfo(&buffer, _("type %s"), typname);
3064 break;
3065 }
3066
3067 case CastRelationId:
3068 {
3070 ScanKeyData skey[1];
3072 HeapTuple tup;
3074
3076
3077 ScanKeyInit(&skey[0],
3080 ObjectIdGetDatum(object->objectId));
3081
3083 NULL, 1, skey);
3084
3086
3087 if (!HeapTupleIsValid(tup))
3088 {
3089 if (!missing_ok)
3090 elog(ERROR, "could not find tuple for cast %u",
3091 object->objectId);
3092
3095 break;
3096 }
3097
3099
3100 appendStringInfo(&buffer, _("cast from %s to %s"),
3101 format_type_be(castForm->castsource),
3102 format_type_be(castForm->casttarget));
3103
3106 break;
3107 }
3108
3110 {
3112 Form_pg_collation coll;
3113 char *nspname;
3114
3116 ObjectIdGetDatum(object->objectId));
3118 {
3119 if (!missing_ok)
3120 elog(ERROR, "cache lookup failed for collation %u",
3121 object->objectId);
3122 break;
3123 }
3124
3126
3127 /* Qualify the name if not visible in search path */
3128 if (CollationIsVisible(object->objectId))
3129 nspname = NULL;
3130 else
3131 nspname = get_namespace_name(coll->collnamespace);
3132
3133 appendStringInfo(&buffer, _("collation %s"),
3135 NameStr(coll->collname)));
3137 break;
3138 }
3139
3141 {
3144
3146 ObjectIdGetDatum(object->objectId));
3148 {
3149 if (!missing_ok)
3150 elog(ERROR, "cache lookup failed for constraint %u",
3151 object->objectId);
3152 break;
3153 }
3154
3156
3157 if (OidIsValid(con->conrelid))
3158 {
3159 StringInfoData rel;
3160
3161 initStringInfo(&rel);
3162 getRelationDescription(&rel, con->conrelid, false);
3163 /* translator: second %s is, e.g., "table %s" */
3164 appendStringInfo(&buffer, _("constraint %s on %s"),
3165 NameStr(con->conname), rel.data);
3166 pfree(rel.data);
3167 }
3168 else
3169 {
3170 appendStringInfo(&buffer, _("constraint %s"),
3171 NameStr(con->conname));
3172 }
3173
3175 break;
3176 }
3177
3179 {
3182 char *nspname;
3183
3185 ObjectIdGetDatum(object->objectId));
3187 {
3188 if (!missing_ok)
3189 elog(ERROR, "cache lookup failed for conversion %u",
3190 object->objectId);
3191 break;
3192 }
3193
3195
3196 /* Qualify the name if not visible in search path */
3197 if (ConversionIsVisible(object->objectId))
3198 nspname = NULL;
3199 else
3200 nspname = get_namespace_name(conv->connamespace);
3201
3202 appendStringInfo(&buffer, _("conversion %s"),
3204 NameStr(conv->conname)));
3206 break;
3207 }
3208
3210 {
3212
3214
3215 if (!OidIsValid(colobject.objectId))
3216 {
3217 if (!missing_ok)
3218 elog(ERROR, "could not find tuple for attrdef %u",
3219 object->objectId);
3220 break;
3221 }
3222
3223 /* translator: %s is typically "column %s of table %s" */
3224 appendStringInfo(&buffer, _("default value for %s"),
3226 break;
3227 }
3228
3229 case LanguageRelationId:
3230 {
3231 char *langname = get_language_name(object->objectId,
3232 missing_ok);
3233
3234 if (langname)
3235 appendStringInfo(&buffer, _("language %s"),
3236 get_language_name(object->objectId, false));
3237 break;
3238 }
3239
3241 if (!LargeObjectExists(object->objectId))
3242 break;
3243 appendStringInfo(&buffer, _("large object %u"),
3244 object->objectId);
3245 break;
3246
3247 case OperatorRelationId:
3248 {
3250 char *oprname = format_operator_extended(object->objectId,
3251 flags);
3252
3253 if (oprname == NULL)
3254 break;
3255
3256 appendStringInfo(&buffer, _("operator %s"), oprname);
3257 break;
3258 }
3259
3261 {
3266 char *nspname;
3267
3269 ObjectIdGetDatum(object->objectId));
3271 {
3272 if (!missing_ok)
3273 elog(ERROR, "cache lookup failed for opclass %u",
3274 object->objectId);
3275 break;
3276 }
3277
3279
3281 ObjectIdGetDatum(opcForm->opcmethod));
3282 if (!HeapTupleIsValid(amTup))
3283 elog(ERROR, "cache lookup failed for access method %u",
3284 opcForm->opcmethod);
3286
3287 /* Qualify the name if not visible in search path */
3288 if (OpclassIsVisible(object->objectId))
3289 nspname = NULL;
3290 else
3291 nspname = get_namespace_name(opcForm->opcnamespace);
3292
3293 appendStringInfo(&buffer, _("operator class %s for access method %s"),
3295 NameStr(opcForm->opcname)),
3296 NameStr(amForm->amname));
3297
3300 break;
3301 }
3302
3304 getOpFamilyDescription(&buffer, object->objectId, missing_ok);
3305 break;
3306
3308 {
3309 HeapTuple tup;
3310
3312 ObjectIdGetDatum(object->objectId));
3313 if (!HeapTupleIsValid(tup))
3314 {
3315 if (!missing_ok)
3316 elog(ERROR, "cache lookup failed for access method %u",
3317 object->objectId);
3318 break;
3319 }
3320
3321 appendStringInfo(&buffer, _("access method %s"),
3322 NameStr(((Form_pg_am) GETSTRUCT(tup))->amname));
3324 break;
3325 }
3326
3328 {
3330 HeapTuple tup;
3331 ScanKeyData skey[1];
3334 StringInfoData opfam;
3335
3338
3339 ScanKeyInit(&skey[0],
3342 ObjectIdGetDatum(object->objectId));
3343
3345 NULL, 1, skey);
3346
3348
3349 if (!HeapTupleIsValid(tup))
3350 {
3351 if (!missing_ok)
3352 elog(ERROR, "could not find tuple for amop entry %u",
3353 object->objectId);
3354
3357 break;
3358 }
3359
3361
3362 initStringInfo(&opfam);
3363 getOpFamilyDescription(&opfam, amopForm->amopfamily, false);
3364
3365 /*
3366 * We use FORMAT_TYPE_ALLOW_INVALID here so as not to fail
3367 * completely if the type links are dangling, which is a form
3368 * of catalog corruption that could occur due to old bugs.
3369 */
3370
3371 /*------
3372 translator: %d is the operator strategy (a number), the
3373 first two %s's are data type names, the third %s is the
3374 description of the operator family, and the last %s is the
3375 textual form of the operator with arguments. */
3376 appendStringInfo(&buffer, _("operator %d (%s, %s) of %s: %s"),
3377 amopForm->amopstrategy,
3378 format_type_extended(amopForm->amoplefttype,
3380 format_type_extended(amopForm->amoprighttype,
3382 opfam.data,
3383 format_operator(amopForm->amopopr));
3384
3385 pfree(opfam.data);
3386
3389 break;
3390 }
3391
3393 {
3395 ScanKeyData skey[1];
3397 HeapTuple tup;
3399 StringInfoData opfam;
3400
3403
3404 ScanKeyInit(&skey[0],
3407 ObjectIdGetDatum(object->objectId));
3408
3410 NULL, 1, skey);
3411
3413
3414 if (!HeapTupleIsValid(tup))
3415 {
3416 if (!missing_ok)
3417 elog(ERROR, "could not find tuple for amproc entry %u",
3418 object->objectId);
3419
3422 break;
3423 }
3424
3426
3427 initStringInfo(&opfam);
3428 getOpFamilyDescription(&opfam, amprocForm->amprocfamily, false);
3429
3430 /*
3431 * We use FORMAT_TYPE_ALLOW_INVALID here so as not to fail
3432 * completely if the type links are dangling, which is a form
3433 * of catalog corruption that could occur due to old bugs.
3434 */
3435
3436 /*------
3437 translator: %d is the function number, the first two %s's
3438 are data type names, the third %s is the description of the
3439 operator family, and the last %s is the textual form of the
3440 function with arguments. */
3441 appendStringInfo(&buffer, _("function %d (%s, %s) of %s: %s"),
3442 amprocForm->amprocnum,
3443 format_type_extended(amprocForm->amproclefttype,
3445 format_type_extended(amprocForm->amprocrighttype,
3447 opfam.data,
3448 format_procedure(amprocForm->amproc));
3449
3450 pfree(opfam.data);
3451
3454 break;
3455 }
3456
3457 case RewriteRelationId:
3458 {
3460 ScanKeyData skey[1];
3462 HeapTuple tup;
3464 StringInfoData rel;
3465
3467
3468 ScanKeyInit(&skey[0],
3471 ObjectIdGetDatum(object->objectId));
3472
3474 NULL, 1, skey);
3475
3477
3478 if (!HeapTupleIsValid(tup))
3479 {
3480 if (!missing_ok)
3481 elog(ERROR, "could not find tuple for rule %u",
3482 object->objectId);
3483
3486 break;
3487 }
3488
3490
3491 initStringInfo(&rel);
3492 getRelationDescription(&rel, rule->ev_class, false);
3493
3494 /* translator: second %s is, e.g., "table %s" */
3495 appendStringInfo(&buffer, _("rule %s on %s"),
3496 NameStr(rule->rulename), rel.data);
3497 pfree(rel.data);
3500 break;
3501 }
3502
3503 case TriggerRelationId:
3504 {
3506 ScanKeyData skey[1];
3508 HeapTuple tup;
3510 StringInfoData rel;
3511
3513
3514 ScanKeyInit(&skey[0],
3517 ObjectIdGetDatum(object->objectId));
3518
3520 NULL, 1, skey);
3521
3523
3524 if (!HeapTupleIsValid(tup))
3525 {
3526 if (!missing_ok)
3527 elog(ERROR, "could not find tuple for trigger %u",
3528 object->objectId);
3529
3532 break;
3533 }
3534
3536
3537 initStringInfo(&rel);
3538 getRelationDescription(&rel, trig->tgrelid, false);
3539
3540 /* translator: second %s is, e.g., "table %s" */
3541 appendStringInfo(&buffer, _("trigger %s on %s"),
3542 NameStr(trig->tgname), rel.data);
3543 pfree(rel.data);
3546 break;
3547 }
3548
3550 {
3551 char *nspname;
3552
3553 nspname = get_namespace_name(object->objectId);
3554 if (!nspname)
3555 {
3556 if (!missing_ok)
3557 elog(ERROR, "cache lookup failed for namespace %u",
3558 object->objectId);
3559 break;
3560 }
3561 appendStringInfo(&buffer, _("schema %s"), nspname);
3562 break;
3563 }
3564
3566 {
3569 char *nspname;
3570
3572 ObjectIdGetDatum(object->objectId));
3574 {
3575 if (!missing_ok)
3576 elog(ERROR, "could not find tuple for statistics object %u",
3577 object->objectId);
3578 break;
3579 }
3580
3582
3583 /* Qualify the name if not visible in search path */
3584 if (StatisticsObjIsVisible(object->objectId))
3585 nspname = NULL;
3586 else
3587 nspname = get_namespace_name(stxForm->stxnamespace);
3588
3589 appendStringInfo(&buffer, _("statistics object %s"),
3591 NameStr(stxForm->stxname)));
3592
3594 break;
3595 }
3596
3597 case TSParserRelationId:
3598 {
3599 HeapTuple tup;
3601 char *nspname;
3602
3604 ObjectIdGetDatum(object->objectId));
3605 if (!HeapTupleIsValid(tup))
3606 {
3607 if (!missing_ok)
3608 elog(ERROR, "cache lookup failed for text search parser %u",
3609 object->objectId);
3610 break;
3611 }
3613
3614 /* Qualify the name if not visible in search path */
3615 if (TSParserIsVisible(object->objectId))
3616 nspname = NULL;
3617 else
3618 nspname = get_namespace_name(prsForm->prsnamespace);
3619
3620 appendStringInfo(&buffer, _("text search parser %s"),
3622 NameStr(prsForm->prsname)));
3624 break;
3625 }
3626
3628 {
3629 HeapTuple tup;
3631 char *nspname;
3632
3634 ObjectIdGetDatum(object->objectId));
3635 if (!HeapTupleIsValid(tup))
3636 {
3637 if (!missing_ok)
3638 elog(ERROR, "cache lookup failed for text search dictionary %u",
3639 object->objectId);
3640 break;
3641 }
3642
3644
3645 /* Qualify the name if not visible in search path */
3646 if (TSDictionaryIsVisible(object->objectId))
3647 nspname = NULL;
3648 else
3649 nspname = get_namespace_name(dictForm->dictnamespace);
3650
3651 appendStringInfo(&buffer, _("text search dictionary %s"),
3653 NameStr(dictForm->dictname)));
3655 break;
3656 }
3657
3659 {
3660 HeapTuple tup;
3662 char *nspname;
3663
3665 ObjectIdGetDatum(object->objectId));
3666 if (!HeapTupleIsValid(tup))
3667 {
3668 if (!missing_ok)
3669 elog(ERROR, "cache lookup failed for text search template %u",
3670 object->objectId);
3671 break;
3672 }
3673
3675
3676 /* Qualify the name if not visible in search path */
3677 if (TSTemplateIsVisible(object->objectId))
3678 nspname = NULL;
3679 else
3680 nspname = get_namespace_name(tmplForm->tmplnamespace);
3681
3682 appendStringInfo(&buffer, _("text search template %s"),
3684 NameStr(tmplForm->tmplname)));
3686 break;
3687 }
3688
3689 case TSConfigRelationId:
3690 {
3691 HeapTuple tup;
3693 char *nspname;
3694
3696 ObjectIdGetDatum(object->objectId));
3697 if (!HeapTupleIsValid(tup))
3698 {
3699 if (!missing_ok)
3700 elog(ERROR, "cache lookup failed for text search configuration %u",
3701 object->objectId);
3702 break;
3703 }
3704
3706
3707 /* Qualify the name if not visible in search path */
3708 if (TSConfigIsVisible(object->objectId))
3709 nspname = NULL;
3710 else
3711 nspname = get_namespace_name(cfgForm->cfgnamespace);
3712
3713 appendStringInfo(&buffer, _("text search configuration %s"),
3715 NameStr(cfgForm->cfgname)));
3717 break;
3718 }
3719
3720 case AuthIdRelationId:
3721 {
3722 char *username = GetUserNameFromId(object->objectId,
3723 missing_ok);
3724
3725 if (username)
3726 appendStringInfo(&buffer, _("role %s"), username);
3727 break;
3728 }
3729
3730 case AuthMemRelationId:
3731 {
3733 ScanKeyData skey[1];
3735 HeapTuple tup;
3737
3739
3740 ScanKeyInit(&skey[0],
3743 ObjectIdGetDatum(object->objectId));
3744
3746 NULL, 1, skey);
3747
3749
3750 if (!HeapTupleIsValid(tup))
3751 {
3752 if (!missing_ok)
3753 elog(ERROR, "could not find tuple for role membership %u",
3754 object->objectId);
3755
3758 break;
3759 }
3760
3762
3763 appendStringInfo(&buffer, _("membership of role %s in role %s"),
3764 GetUserNameFromId(amForm->member, false),
3765 GetUserNameFromId(amForm->roleid, false));
3766
3769 break;
3770 }
3771
3772 case DatabaseRelationId:
3773 {
3774 char *datname;
3775
3777 if (!datname)
3778 {
3779 if (!missing_ok)
3780 elog(ERROR, "cache lookup failed for database %u",
3781 object->objectId);
3782 break;
3783 }
3784 appendStringInfo(&buffer, _("database %s"), datname);
3785 break;
3786 }
3787
3789 {
3790 char *tblspace;
3791
3793 if (!tblspace)
3794 {
3795 if (!missing_ok)
3796 elog(ERROR, "cache lookup failed for tablespace %u",
3797 object->objectId);
3798 break;
3799 }
3800 appendStringInfo(&buffer, _("tablespace %s"), tblspace);
3801 break;
3802 }
3803
3805 {
3807
3809 missing_ok);
3810 if (fdw)
3811 appendStringInfo(&buffer, _("foreign-data wrapper %s"), fdw->fdwname);
3812 break;
3813 }
3814
3816 {
3818
3819 srv = GetForeignServerExtended(object->objectId, missing_ok);
3820 if (srv)
3821 appendStringInfo(&buffer, _("server %s"), srv->servername);
3822 break;
3823 }
3824
3826 {
3827 HeapTuple tup;
3828 Oid useid;
3829 char *usename;
3832
3834 ObjectIdGetDatum(object->objectId));
3835 if (!HeapTupleIsValid(tup))
3836 {
3837 if (!missing_ok)
3838 elog(ERROR, "cache lookup failed for user mapping %u",
3839 object->objectId);
3840 break;
3841 }
3842
3844 useid = umform->umuser;
3845 srv = GetForeignServer(umform->umserver);
3846
3848
3849 if (OidIsValid(useid))
3851 else
3852 usename = "public";
3853
3854 appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
3855 srv->servername);
3856 break;
3857 }
3858
3860 {
3862 ScanKeyData skey[1];
3864 HeapTuple tup;
3866 char *rolename;
3867 char *nspname;
3868
3870
3871 ScanKeyInit(&skey[0],
3874 ObjectIdGetDatum(object->objectId));
3875
3877 true, NULL, 1, skey);
3878
3880
3881 if (!HeapTupleIsValid(tup))
3882 {
3883 if (!missing_ok)
3884 elog(ERROR, "could not find tuple for default ACL %u",
3885 object->objectId);
3886
3889 break;
3890 }
3891
3893
3894 rolename = GetUserNameFromId(defacl->defaclrole, false);
3895
3896 if (OidIsValid(defacl->defaclnamespace))
3897 nspname = get_namespace_name(defacl->defaclnamespace);
3898 else
3899 nspname = NULL;
3900
3901 switch (defacl->defaclobjtype)
3902 {
3903 case DEFACLOBJ_RELATION:
3904 if (nspname)
3905 appendStringInfo(&buffer,
3906 _("default privileges on new relations belonging to role %s in schema %s"),
3907 rolename, nspname);
3908 else
3909 appendStringInfo(&buffer,
3910 _("default privileges on new relations belonging to role %s"),
3911 rolename);
3912 break;
3913 case DEFACLOBJ_SEQUENCE:
3914 if (nspname)
3915 appendStringInfo(&buffer,
3916 _("default privileges on new sequences belonging to role %s in schema %s"),
3917 rolename, nspname);
3918 else
3919 appendStringInfo(&buffer,
3920 _("default privileges on new sequences belonging to role %s"),
3921 rolename);
3922 break;
3923 case DEFACLOBJ_FUNCTION:
3924 if (nspname)
3925 appendStringInfo(&buffer,
3926 _("default privileges on new functions belonging to role %s in schema %s"),
3927 rolename, nspname);
3928 else
3929 appendStringInfo(&buffer,
3930 _("default privileges on new functions belonging to role %s"),
3931 rolename);
3932 break;
3933 case DEFACLOBJ_TYPE:
3934 if (nspname)
3935 appendStringInfo(&buffer,
3936 _("default privileges on new types belonging to role %s in schema %s"),
3937 rolename, nspname);
3938 else
3939 appendStringInfo(&buffer,
3940 _("default privileges on new types belonging to role %s"),
3941 rolename);
3942 break;
3944 Assert(!nspname);
3945 appendStringInfo(&buffer,
3946 _("default privileges on new schemas belonging to role %s"),
3947 rolename);
3948 break;
3950 Assert(!nspname);
3951 appendStringInfo(&buffer,
3952 _("default privileges on new large objects belonging to role %s"),
3953 rolename);
3954 break;
3955 default:
3956 /* shouldn't get here */
3957 if (nspname)
3958 appendStringInfo(&buffer,
3959 _("default privileges belonging to role %s in schema %s"),
3960 rolename, nspname);
3961 else
3962 appendStringInfo(&buffer,
3963 _("default privileges belonging to role %s"),
3964 rolename);
3965 break;
3966 }
3967
3970 break;
3971 }
3972
3974 {
3975 char *extname;
3976
3977 extname = get_extension_name(object->objectId);
3978 if (!extname)
3979 {
3980 if (!missing_ok)
3981 elog(ERROR, "cache lookup failed for extension %u",
3982 object->objectId);
3983 break;
3984 }
3985 appendStringInfo(&buffer, _("extension %s"), extname);
3986 break;
3987 }
3988
3990 {
3991 HeapTuple tup;
3992
3994 ObjectIdGetDatum(object->objectId));
3995 if (!HeapTupleIsValid(tup))
3996 {
3997 if (!missing_ok)
3998 elog(ERROR, "cache lookup failed for event trigger %u",
3999 object->objectId);
4000 break;
4001 }
4002 appendStringInfo(&buffer, _("event trigger %s"),
4005 break;
4006 }
4007
4009 {
4010 HeapTuple tup;
4012 char *parname;
4013
4015 ObjectIdGetDatum(object->objectId));
4016 if (!HeapTupleIsValid(tup))
4017 {
4018 if (!missing_ok)
4019 elog(ERROR, "cache lookup failed for parameter ACL %u",
4020 object->objectId);
4021 break;
4022 }
4026 appendStringInfo(&buffer, _("parameter %s"), parname);
4028 break;
4029 }
4030
4031 case PolicyRelationId:
4032 {
4034 ScanKeyData skey[1];
4036 HeapTuple tuple;
4038 StringInfoData rel;
4039
4041
4042 ScanKeyInit(&skey[0],
4045 ObjectIdGetDatum(object->objectId));
4046
4048 true, NULL, 1, skey);
4049
4050 tuple = systable_getnext(sscan);
4051
4052 if (!HeapTupleIsValid(tuple))
4053 {
4054 if (!missing_ok)
4055 elog(ERROR, "could not find tuple for policy %u",
4056 object->objectId);
4057
4060 break;
4061 }
4062
4064
4065 initStringInfo(&rel);
4066 getRelationDescription(&rel, form_policy->polrelid, false);
4067
4068 /* translator: second %s is, e.g., "table %s" */
4069 appendStringInfo(&buffer, _("policy %s on %s"),
4070 NameStr(form_policy->polname), rel.data);
4071 pfree(rel.data);
4074 break;
4075 }
4076
4078 {
4079 HeapTuple tup;
4081 StringInfoData rel;
4082
4084 if (!HeapTupleIsValid(tup))
4085 {
4086 if (!missing_ok)
4087 elog(ERROR, "cache lookup failed for property graph element %u",
4088 object->objectId);
4089 break;
4090 }
4091
4093
4094 initStringInfo(&rel);
4095 getRelationDescription(&rel, pgeform->pgepgid, false);
4096
4097 if (pgeform->pgekind == PGEKIND_VERTEX)
4098 appendStringInfo(&buffer, _("vertex %s of %s"), NameStr(pgeform->pgealias), rel.data);
4099 else if (pgeform->pgekind == PGEKIND_EDGE)
4100 appendStringInfo(&buffer, _("edge %s of %s"), NameStr(pgeform->pgealias), rel.data);
4101 else
4102 appendStringInfo(&buffer, "??? element %s of %s", NameStr(pgeform->pgealias), rel.data);
4103
4104 pfree(rel.data);
4106 break;
4107 }
4108
4110 {
4111 Relation rel;
4112 HeapTuple tuple;
4115
4117 tuple = get_catalog_object_by_oid(rel,
4119 object->objectId);
4120 if (!HeapTupleIsValid(tuple))
4121 {
4122 if (!missing_ok)
4123 elog(ERROR, "could not find tuple for element label %u", object->objectId);
4124
4126 break;
4127 }
4128
4130
4132 appendStringInfo(&buffer, _("label %s of %s"),
4133 get_propgraph_label_name(pgelform->pgellabelid),
4134 getObjectDescription(&oa, false));
4135
4137 break;
4138 }
4139
4141 {
4142 HeapTuple tuple;
4144 StringInfoData rel;
4145
4147 if (!HeapTupleIsValid(tuple))
4148 {
4149 if (!missing_ok)
4150 elog(ERROR, "could not find tuple for label %u", object->objectId);
4151 break;
4152 }
4153
4155
4156 initStringInfo(&rel);
4157 getRelationDescription(&rel, pglform->pglpgid, false);
4158
4159 appendStringInfo(&buffer, _("label %s of %s"), NameStr(pglform->pgllabel), rel.data);
4160
4161 pfree(rel.data);
4162 ReleaseSysCache(tuple);
4163 break;
4164 }
4165
4167 {
4168 Relation rel;
4169 HeapTuple tuple;
4172
4174 tuple = get_catalog_object_by_oid(rel,
4176 object->objectId);
4177 if (!HeapTupleIsValid(tuple))
4178 {
4179 if (!missing_ok)
4180 elog(ERROR, "could not find tuple for label property %u", object->objectId);
4181
4183 break;
4184 }
4185
4187
4189
4190 appendStringInfo(&buffer, _("property %s of %s"),
4192 getObjectDescription(&oa, false));
4193
4195 break;
4196 }
4197
4199 {
4200 HeapTuple tuple;
4202 StringInfoData rel;
4203
4205 if (!HeapTupleIsValid(tuple))
4206 {
4207 if (!missing_ok)
4208 elog(ERROR, "could not find tuple for property %u", object->objectId);
4209 break;
4210 }
4211
4213
4214 initStringInfo(&rel);
4215 getRelationDescription(&rel, pgpform->pgppgid, false);
4216
4217 appendStringInfo(&buffer, _("property %s of %s"), NameStr(pgpform->pgpname), rel.data);
4218
4219 pfree(rel.data);
4220 ReleaseSysCache(tuple);
4221 break;
4222 }
4223
4225 {
4226 char *pubname = get_publication_name(object->objectId,
4227 missing_ok);
4228
4229 if (pubname)
4230 appendStringInfo(&buffer, _("publication %s"), pubname);
4231 break;
4232 }
4233
4235 {
4236 char *pubname;
4237 char *nspname;
4238
4239 if (!getPublicationSchemaInfo(object, missing_ok,
4240 &pubname, &nspname))
4241 break;
4242
4243 appendStringInfo(&buffer, _("publication of schema %s in publication %s"),
4244 nspname, pubname);
4245 pfree(pubname);
4246 pfree(nspname);
4247 break;
4248 }
4249
4251 {
4252 HeapTuple tup;
4253 char *pubname;
4255 StringInfoData rel;
4256
4258 ObjectIdGetDatum(object->objectId));
4259 if (!HeapTupleIsValid(tup))
4260 {
4261 if (!missing_ok)
4262 elog(ERROR, "cache lookup failed for publication table %u",
4263 object->objectId);
4264 break;
4265 }
4266
4268 pubname = get_publication_name(prform->prpubid, false);
4269
4270 initStringInfo(&rel);
4271 getRelationDescription(&rel, prform->prrelid, false);
4272
4273 /* translator: first %s is, e.g., "table %s" */
4274 appendStringInfo(&buffer, _("publication of %s in publication %s"),
4275 rel.data, pubname);
4276 pfree(rel.data);
4278 break;
4279 }
4280
4282 {
4283 char *subname = get_subscription_name(object->objectId,
4284 missing_ok);
4285
4286 if (subname)
4287 appendStringInfo(&buffer, _("subscription %s"), subname);
4288 break;
4289 }
4290
4292 {
4295
4297 ObjectIdGetDatum(object->objectId));
4299 {
4300 if (!missing_ok)
4301 elog(ERROR, "could not find tuple for transform %u",
4302 object->objectId);
4303 break;
4304 }
4305
4307
4308 appendStringInfo(&buffer, _("transform for %s language %s"),
4309 format_type_be(trfForm->trftype),
4310 get_language_name(trfForm->trflang, false));
4311
4313 break;
4314 }
4315
4316 default:
4317 elog(ERROR, "unsupported object class: %u", object->classId);
4318 }
4319
4320 /* an empty buffer is equivalent to no object found */
4321 if (buffer.len == 0)
4322 return NULL;
4323
4324 return buffer.data;
4325}
char * get_tablespace_name(Oid spc_oid)
#define FORMAT_TYPE_ALLOW_INVALID
Definition builtins.h:126
#define TextDatumGetCString(d)
Definition builtins.h:99
#define FORMAT_TYPE_INVALID_AS_NULL
Definition builtins.h:128
#define NameStr(name)
Definition c.h:894
uint16_t uint16
Definition c.h:682
#define _(x)
Definition elog.c:96
char * get_extension_name(Oid ext_oid)
Definition extension.c:251
ForeignDataWrapper * GetForeignDataWrapperExtended(Oid fdwid, uint16 flags)
Definition foreign.c:51
ForeignServer * GetForeignServer(Oid serverid)
Definition foreign.c:114
ForeignServer * GetForeignServerExtended(Oid serverid, uint16 flags)
Definition foreign.c:126
char * format_type_extended(Oid type_oid, int32 typemod, uint16 flags)
static char * username
Definition initdb.c:153
#define AccessShareLock
Definition lockdefs.h:36
char * get_propgraph_property_name(Oid propoid)
Definition lsyscache.c:4098
char * get_database_name(Oid dbid)
Definition lsyscache.c:1392
char * get_language_name(Oid langoid, bool missing_ok)
Definition lsyscache.c:1413
char * get_propgraph_label_name(Oid labeloid)
Definition lsyscache.c:4080
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition lsyscache.c:1053
char * get_subscription_name(Oid subid, bool missing_ok)
Definition lsyscache.c:4056
char * get_publication_name(Oid pubid, bool missing_ok)
Definition lsyscache.c:4006
char * get_namespace_name(Oid nspid)
Definition lsyscache.c:3682
void pfree(void *pointer)
Definition mcxt.c:1619
bool TSTemplateIsVisible(Oid tmplId)
Definition namespace.c:3137
bool CollationIsVisible(Oid collid)
Definition namespace.c:2476
bool ConversionIsVisible(Oid conid)
Definition namespace.c:2578
bool OpclassIsVisible(Oid opcid)
Definition namespace.c:2223
bool TSParserIsVisible(Oid prsId)
Definition namespace.c:2846
bool TSConfigIsVisible(Oid cfgid)
Definition namespace.c:3282
bool StatisticsObjIsVisible(Oid stxid)
Definition namespace.c:2701
bool TSDictionaryIsVisible(Oid dictId)
Definition namespace.c:2991
static void getRelationDescription(StringInfo buffer, Oid relid, bool missing_ok)
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
static bool getPublicationSchemaInfo(const ObjectAddress *object, bool missing_ok, char **pubname, char **nspname)
static void getOpFamilyDescription(StringInfo buffer, Oid opfid, bool missing_ok)
#define ObjectAddressSet(addr, class_id, object_id)
END_CATALOG_STRUCT typedef FormData_pg_am * Form_pg_am
Definition pg_am.h:52
END_CATALOG_STRUCT typedef FormData_pg_amop * Form_pg_amop
Definition pg_amop.h:92
END_CATALOG_STRUCT typedef FormData_pg_amproc * Form_pg_amproc
Definition pg_amproc.h:72
ObjectAddress GetAttrDefaultColumnAddress(Oid attrdefoid)
Definition pg_attrdef.c:322
NameData attname
END_CATALOG_STRUCT typedef FormData_pg_auth_members * Form_pg_auth_members
END_CATALOG_STRUCT typedef FormData_pg_cast * Form_pg_cast
Definition pg_cast.h:61
END_CATALOG_STRUCT typedef FormData_pg_collation * Form_pg_collation
END_CATALOG_STRUCT typedef FormData_pg_conversion * Form_pg_conversion
NameData datname
Definition pg_database.h:37
END_CATALOG_STRUCT typedef FormData_pg_default_acl * Form_pg_default_acl
END_CATALOG_STRUCT typedef FormData_pg_event_trigger * Form_pg_event_trigger
END_CATALOG_STRUCT typedef FormData_pg_opclass * Form_pg_opclass
Definition pg_opclass.h:87
END_CATALOG_STRUCT typedef FormData_pg_policy * Form_pg_policy
Definition pg_policy.h:55
NameData proname
Definition pg_proc.h:37
END_CATALOG_STRUCT typedef FormData_pg_propgraph_element * Form_pg_propgraph_element
END_CATALOG_STRUCT typedef FormData_pg_propgraph_element_label * Form_pg_propgraph_element_label
END_CATALOG_STRUCT typedef FormData_pg_propgraph_label * Form_pg_propgraph_label
END_CATALOG_STRUCT typedef FormData_pg_propgraph_label_property * Form_pg_propgraph_label_property
END_CATALOG_STRUCT typedef FormData_pg_propgraph_property * Form_pg_propgraph_property
END_CATALOG_STRUCT typedef FormData_pg_publication_rel * Form_pg_publication_rel
END_CATALOG_STRUCT typedef FormData_pg_rewrite * Form_pg_rewrite
Definition pg_rewrite.h:56
END_CATALOG_STRUCT typedef FormData_pg_statistic_ext * Form_pg_statistic_ext
NameData subname
END_CATALOG_STRUCT typedef FormData_pg_transform * Form_pg_transform
END_CATALOG_STRUCT typedef FormData_pg_trigger * Form_pg_trigger
Definition pg_trigger.h:84
END_CATALOG_STRUCT typedef FormData_pg_ts_config * Form_pg_ts_config
END_CATALOG_STRUCT typedef FormData_pg_ts_dict * Form_pg_ts_dict
Definition pg_ts_dict.h:56
END_CATALOG_STRUCT typedef FormData_pg_ts_parser * Form_pg_ts_parser
END_CATALOG_STRUCT typedef FormData_pg_ts_template * Form_pg_ts_template
NameData typname
Definition pg_type.h:43
END_CATALOG_STRUCT typedef FormData_pg_user_mapping * Form_pg_user_mapping
uint64_t Datum
Definition postgres.h:70
char * format_procedure(Oid procedure_oid)
Definition regproc.c:305
char * format_procedure_extended(Oid procedure_oid, uint16 flags)
Definition regproc.c:332
char * format_operator_extended(Oid operator_oid, uint16 flags)
Definition regproc.c:730
char * format_operator(Oid operator_oid)
Definition regproc.c:801
#define FORMAT_OPERATOR_INVALID_AS_NULL
Definition regproc.h:24
#define FORMAT_PROC_INVALID_AS_NULL
Definition regproc.h:19
char * quote_qualified_identifier(const char *qualifier, const char *ident)
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40

References _, AccessShareLock, appendStringInfo(), Assert, attname, BTEqualStrategyNumber, ObjectAddress::classId, CollationIsVisible(), ConversionIsVisible(), StringInfoData::data, datname, elog, ERROR, fb(), Form_pg_am, Form_pg_amop, Form_pg_amproc, Form_pg_auth_members, Form_pg_cast, Form_pg_collation, Form_pg_constraint, Form_pg_conversion, Form_pg_default_acl, Form_pg_event_trigger, Form_pg_opclass, Form_pg_policy, Form_pg_propgraph_element, Form_pg_propgraph_element_label, Form_pg_propgraph_label, Form_pg_propgraph_label_property, Form_pg_propgraph_property, Form_pg_publication_rel, Form_pg_rewrite, Form_pg_statistic_ext, Form_pg_transform, Form_pg_trigger, Form_pg_ts_config, Form_pg_ts_dict, Form_pg_ts_parser, Form_pg_ts_template, Form_pg_user_mapping, format_operator(), format_operator_extended(), FORMAT_OPERATOR_INVALID_AS_NULL, FORMAT_PROC_INVALID_AS_NULL, format_procedure(), format_procedure_extended(), FORMAT_TYPE_ALLOW_INVALID, format_type_be(), format_type_extended(), FORMAT_TYPE_INVALID_AS_NULL, get_attname(), get_catalog_object_by_oid(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name(), get_propgraph_label_name(), get_propgraph_property_name(), get_publication_name(), get_subscription_name(), get_tablespace_name(), GetAttrDefaultColumnAddress(), GetForeignDataWrapperExtended(), GetForeignServer(), GetForeignServerExtended(), getObjectDescription(), getOpFamilyDescription(), getPublicationSchemaInfo(), getRelationDescription(), GETSTRUCT(), GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), LargeObjectExists(), StringInfoData::len, NameStr, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, OidIsValid, OpclassIsVisible(), pfree(), proname, quote_qualified_identifier(), ReleaseSysCache(), ScanKeyInit(), SearchSysCache1(), StatisticsObjIsVisible(), subname, SysCacheGetAttrNotNull(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TextDatumGetCString, TSConfigIsVisible(), TSDictionaryIsVisible(), TSParserIsVisible(), TSTemplateIsVisible(), typname, and username.

Referenced by AlterExtensionNamespace(), ATExecAlterColumnType(), changeDependenciesOn(), check_relation_privileges(), checkMembershipInCurrentExtension(), checkSharedDependencies(), DefineView(), ExecAlterExtensionContentsRecurse(), findDependentObjects(), get_altertable_subcmdinfo(), get_object_address_opf_member(), getObjectDescription(), getObjectDescriptionOids(), pg_describe_object(), ProcedureCreate(), recordDependencyOnCurrentExtension(), RememberAllDependentForRebuilding(), reportDependentObjects(), sepgsql_fmgr_hook(), shdepDropOwned(), shdepReassignOwned(), storeObjectDescription(), and transformCreateTableAsStmt().

◆ getObjectDescriptionOids()

char * getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)
extern

Definition at line 4331 of file objectaddress.c.

4332{
4333 ObjectAddress address;
4334
4335 address.classId = classid;
4336 address.objectId = objid;
4337 address.objectSubId = 0;
4338
4339 return getObjectDescription(&address, false);
4340}

References ObjectAddress::classId, getObjectDescription(), ObjectAddress::objectId, and ObjectAddress::objectSubId.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

◆ getObjectIdentity()

◆ getObjectIdentityParts()

char * getObjectIdentityParts ( const ObjectAddress object,
List **  objname,
List **  objargs,
bool  missing_ok 
)
extern

Definition at line 5111 of file objectaddress.c.

5114{
5115 StringInfoData buffer;
5116
5117 initStringInfo(&buffer);
5118
5119 /*
5120 * Make sure that both objname and objargs were passed, or none was; and
5121 * initialize them to empty lists. For objname this is useless because it
5122 * will be initialized in all cases inside the switch; but we do it anyway
5123 * so that we can test below that no branch leaves it unset.
5124 */
5125 Assert((objname != NULL) == (objargs != NULL));
5126 if (objname)
5127 {
5128 *objname = NIL;
5129 *objargs = NIL;
5130 }
5131
5132 switch (object->classId)
5133 {
5134 case RelationRelationId:
5135 {
5136 char *attr = NULL;
5137
5138 /*
5139 * Check for the attribute first, so as if it is missing we
5140 * can skip the entire relation description.
5141 */
5142 if (object->objectSubId != 0)
5143 {
5144 attr = get_attname(object->objectId,
5145 object->objectSubId,
5146 missing_ok);
5147
5148 if (missing_ok && attr == NULL)
5149 break;
5150 }
5151
5152 getRelationIdentity(&buffer, object->objectId, objname,
5153 missing_ok);
5154 if (objname && *objname == NIL)
5155 break;
5156
5157 if (attr)
5158 {
5159 appendStringInfo(&buffer, ".%s",
5160 quote_identifier(attr));
5161 if (objname)
5162 *objname = lappend(*objname, attr);
5163 }
5164 }
5165 break;
5166
5168 {
5171 flags);
5172
5173 if (proname == NULL)
5174 break;
5175
5177 if (objname)
5178 format_procedure_parts(object->objectId, objname, objargs,
5179 missing_ok);
5180 break;
5181 }
5182
5183 case TypeRelationId:
5184 {
5186 char *typeout;
5187
5188 typeout = format_type_extended(object->objectId, -1, flags);
5189
5190 if (typeout == NULL)
5191 break;
5192
5194 if (objname)
5195 *objname = list_make1(typeout);
5196 }
5197 break;
5198
5199 case CastRelationId:
5200 {
5202 HeapTuple tup;
5204
5206
5208 object->objectId);
5209
5210 if (!HeapTupleIsValid(tup))
5211 {
5212 if (!missing_ok)
5213 elog(ERROR, "could not find tuple for cast %u",
5214 object->objectId);
5215
5217 break;
5218 }
5219
5221
5222 appendStringInfo(&buffer, "(%s AS %s)",
5224 format_type_be_qualified(castForm->casttarget));
5225
5226 if (objname)
5227 {
5228 *objname = list_make1(format_type_be_qualified(castForm->castsource));
5229 *objargs = list_make1(format_type_be_qualified(castForm->casttarget));
5230 }
5231
5233 break;
5234 }
5235
5237 {
5239 Form_pg_collation coll;
5240 char *schema;
5241
5243 ObjectIdGetDatum(object->objectId));
5245 {
5246 if (!missing_ok)
5247 elog(ERROR, "cache lookup failed for collation %u",
5248 object->objectId);
5249 break;
5250 }
5252 schema = get_namespace_name_or_temp(coll->collnamespace);
5253 appendStringInfoString(&buffer,
5255 NameStr(coll->collname)));
5256 if (objname)
5257 *objname = list_make2(schema,
5258 pstrdup(NameStr(coll->collname)));
5260 break;
5261 }
5262
5264 {
5267
5269 ObjectIdGetDatum(object->objectId));
5271 {
5272 if (!missing_ok)
5273 elog(ERROR, "cache lookup failed for constraint %u",
5274 object->objectId);
5275 break;
5276 }
5278
5279 if (OidIsValid(con->conrelid))
5280 {
5281 appendStringInfo(&buffer, "%s on ",
5282 quote_identifier(NameStr(con->conname)));
5283 getRelationIdentity(&buffer, con->conrelid, objname,
5284 false);
5285 if (objname)
5286 *objname = lappend(*objname, pstrdup(NameStr(con->conname)));
5287 }
5288 else
5289 {
5290 ObjectAddress domain;
5291
5292 Assert(OidIsValid(con->contypid));
5293 domain.classId = TypeRelationId;
5294 domain.objectId = con->contypid;
5295 domain.objectSubId = 0;
5296
5297 appendStringInfo(&buffer, "%s on %s",
5298 quote_identifier(NameStr(con->conname)),
5299 getObjectIdentityParts(&domain, objname,
5300 objargs, false));
5301
5302 if (objname)
5303 *objargs = lappend(*objargs, pstrdup(NameStr(con->conname)));
5304 }
5305
5307 break;
5308 }
5309
5311 {
5314 char *schema;
5315
5317 ObjectIdGetDatum(object->objectId));
5319 {
5320 if (!missing_ok)
5321 elog(ERROR, "cache lookup failed for conversion %u",
5322 object->objectId);
5323 break;
5324 }
5326 schema = get_namespace_name_or_temp(conForm->connamespace);
5327 appendStringInfoString(&buffer,
5329 NameStr(conForm->conname)));
5330 if (objname)
5331 *objname = list_make2(schema,
5332 pstrdup(NameStr(conForm->conname)));
5334 break;
5335 }
5336
5338 {
5340
5342
5343 if (!OidIsValid(colobject.objectId))
5344 {
5345 if (!missing_ok)
5346 elog(ERROR, "could not find tuple for attrdef %u",
5347 object->objectId);
5348 break;
5349 }
5350
5351 appendStringInfo(&buffer, "for %s",
5353 objname, objargs,
5354 false));
5355 break;
5356 }
5357
5358 case LanguageRelationId:
5359 {
5362
5364 ObjectIdGetDatum(object->objectId));
5366 {
5367 if (!missing_ok)
5368 elog(ERROR, "cache lookup failed for language %u",
5369 object->objectId);
5370 break;
5371 }
5373 appendStringInfoString(&buffer,
5374 quote_identifier(NameStr(langForm->lanname)));
5375 if (objname)
5376 *objname = list_make1(pstrdup(NameStr(langForm->lanname)));
5378 break;
5379 }
5380
5382 if (!LargeObjectExists(object->objectId))
5383 break;
5384 appendStringInfo(&buffer, "%u",
5385 object->objectId);
5386 if (objname)
5387 *objname = list_make1(psprintf("%u", object->objectId));
5388 break;
5389
5390 case OperatorRelationId:
5391 {
5393 char *oprname = format_operator_extended(object->objectId,
5394 flags);
5395
5396 if (oprname == NULL)
5397 break;
5398
5399 appendStringInfoString(&buffer, oprname);
5400 if (objname)
5401 format_operator_parts(object->objectId, objname, objargs, missing_ok);
5402 break;
5403 }
5404
5406 {
5411 char *schema;
5412
5414 ObjectIdGetDatum(object->objectId));
5416 {
5417 if (!missing_ok)
5418 elog(ERROR, "cache lookup failed for opclass %u",
5419 object->objectId);
5420 break;
5421 }
5423 schema = get_namespace_name_or_temp(opcForm->opcnamespace);
5424
5426 ObjectIdGetDatum(opcForm->opcmethod));
5427 if (!HeapTupleIsValid(amTup))
5428 elog(ERROR, "cache lookup failed for access method %u",
5429 opcForm->opcmethod);
5431
5432 appendStringInfo(&buffer, "%s USING %s",
5434 NameStr(opcForm->opcname)),
5435 quote_identifier(NameStr(amForm->amname)));
5436 if (objname)
5437 *objname = list_make3(pstrdup(NameStr(amForm->amname)),
5438 schema,
5439 pstrdup(NameStr(opcForm->opcname)));
5440
5443 break;
5444 }
5445
5447 getOpFamilyIdentity(&buffer, object->objectId, objname,
5448 missing_ok);
5449 break;
5450
5452 {
5453 char *amname;
5454
5455 amname = get_am_name(object->objectId);
5456 if (!amname)
5457 {
5458 if (!missing_ok)
5459 elog(ERROR, "cache lookup failed for access method %u",
5460 object->objectId);
5461 break;
5462 }
5463 appendStringInfoString(&buffer, quote_identifier(amname));
5464 if (objname)
5465 *objname = list_make1(amname);
5466 }
5467 break;
5468
5470 {
5472 HeapTuple tup;
5473 ScanKeyData skey[1];
5476 StringInfoData opfam;
5477 char *ltype;
5478 char *rtype;
5479
5482
5483 ScanKeyInit(&skey[0],
5486 ObjectIdGetDatum(object->objectId));
5487
5489 NULL, 1, skey);
5490
5492
5493 if (!HeapTupleIsValid(tup))
5494 {
5495 if (!missing_ok)
5496 elog(ERROR, "could not find tuple for amop entry %u",
5497 object->objectId);
5498
5501 break;
5502 }
5503
5505
5506 initStringInfo(&opfam);
5507 getOpFamilyIdentity(&opfam, amopForm->amopfamily, objname,
5508 false);
5509
5510 ltype = format_type_be_qualified(amopForm->amoplefttype);
5511 rtype = format_type_be_qualified(amopForm->amoprighttype);
5512
5513 if (objname)
5514 {
5515 *objname = lappend(*objname,
5516 psprintf("%d", amopForm->amopstrategy));
5517 *objargs = list_make2(ltype, rtype);
5518 }
5519
5520 appendStringInfo(&buffer, "operator %d (%s, %s) of %s",
5521 amopForm->amopstrategy,
5522 ltype, rtype, opfam.data);
5523
5524 pfree(opfam.data);
5525
5528 break;
5529 }
5530
5532 {
5534 ScanKeyData skey[1];
5536 HeapTuple tup;
5538 StringInfoData opfam;
5539 char *ltype;
5540 char *rtype;
5541
5544
5545 ScanKeyInit(&skey[0],
5548 ObjectIdGetDatum(object->objectId));
5549
5551 NULL, 1, skey);
5552
5554
5555 if (!HeapTupleIsValid(tup))
5556 {
5557 if (!missing_ok)
5558 elog(ERROR, "could not find tuple for amproc entry %u",
5559 object->objectId);
5560
5563 break;
5564 }
5565
5567
5568 initStringInfo(&opfam);
5569 getOpFamilyIdentity(&opfam, amprocForm->amprocfamily, objname,
5570 false);
5571
5572 ltype = format_type_be_qualified(amprocForm->amproclefttype);
5573 rtype = format_type_be_qualified(amprocForm->amprocrighttype);
5574
5575 if (objname)
5576 {
5577 *objname = lappend(*objname,
5578 psprintf("%d", amprocForm->amprocnum));
5579 *objargs = list_make2(ltype, rtype);
5580 }
5581
5582 appendStringInfo(&buffer, "function %d (%s, %s) of %s",
5583 amprocForm->amprocnum,
5584 ltype, rtype, opfam.data);
5585
5586 pfree(opfam.data);
5587
5590 break;
5591 }
5592
5593 case RewriteRelationId:
5594 {
5596 HeapTuple tup;
5598
5600
5602 object->objectId);
5603
5604 if (!HeapTupleIsValid(tup))
5605 {
5606 if (!missing_ok)
5607 elog(ERROR, "could not find tuple for rule %u",
5608 object->objectId);
5609
5611 break;
5612 }
5613
5615
5616 appendStringInfo(&buffer, "%s on ",
5617 quote_identifier(NameStr(rule->rulename)));
5618 getRelationIdentity(&buffer, rule->ev_class, objname, false);
5619 if (objname)
5620 *objname = lappend(*objname, pstrdup(NameStr(rule->rulename)));
5621
5623 break;
5624 }
5625
5626 case TriggerRelationId:
5627 {
5629 HeapTuple tup;
5631
5633
5635 object->objectId);
5636
5637 if (!HeapTupleIsValid(tup))
5638 {
5639 if (!missing_ok)
5640 elog(ERROR, "could not find tuple for trigger %u",
5641 object->objectId);
5642
5644 break;
5645 }
5646
5648
5649 appendStringInfo(&buffer, "%s on ",
5650 quote_identifier(NameStr(trig->tgname)));
5651 getRelationIdentity(&buffer, trig->tgrelid, objname, false);
5652 if (objname)
5653 *objname = lappend(*objname, pstrdup(NameStr(trig->tgname)));
5654
5656 break;
5657 }
5658
5660 {
5661 char *nspname;
5662
5663 nspname = get_namespace_name_or_temp(object->objectId);
5664 if (!nspname)
5665 {
5666 if (!missing_ok)
5667 elog(ERROR, "cache lookup failed for namespace %u",
5668 object->objectId);
5669 break;
5670 }
5671 appendStringInfoString(&buffer,
5672 quote_identifier(nspname));
5673 if (objname)
5674 *objname = list_make1(nspname);
5675 break;
5676 }
5677
5679 {
5680 HeapTuple tup;
5682 char *schema;
5683
5685 ObjectIdGetDatum(object->objectId));
5686 if (!HeapTupleIsValid(tup))
5687 {
5688 if (!missing_ok)
5689 elog(ERROR, "cache lookup failed for statistics object %u",
5690 object->objectId);
5691 break;
5692 }
5694 schema = get_namespace_name_or_temp(formStatistic->stxnamespace);
5695 appendStringInfoString(&buffer,
5697 NameStr(formStatistic->stxname)));
5698 if (objname)
5699 *objname = list_make2(schema,
5700 pstrdup(NameStr(formStatistic->stxname)));
5702 }
5703 break;
5704
5705 case TSParserRelationId:
5706 {
5707 HeapTuple tup;
5709 char *schema;
5710
5712 ObjectIdGetDatum(object->objectId));
5713 if (!HeapTupleIsValid(tup))
5714 {
5715 if (!missing_ok)
5716 elog(ERROR, "cache lookup failed for text search parser %u",
5717 object->objectId);
5718 break;
5719 }
5721 schema = get_namespace_name_or_temp(formParser->prsnamespace);
5722 appendStringInfoString(&buffer,
5724 NameStr(formParser->prsname)));
5725 if (objname)
5726 *objname = list_make2(schema,
5727 pstrdup(NameStr(formParser->prsname)));
5729 break;
5730 }
5731
5733 {
5734 HeapTuple tup;
5736 char *schema;
5737
5739 ObjectIdGetDatum(object->objectId));
5740 if (!HeapTupleIsValid(tup))
5741 {
5742 if (!missing_ok)
5743 elog(ERROR, "cache lookup failed for text search dictionary %u",
5744 object->objectId);
5745 break;
5746 }
5748 schema = get_namespace_name_or_temp(formDict->dictnamespace);
5749 appendStringInfoString(&buffer,
5751 NameStr(formDict->dictname)));
5752 if (objname)
5753 *objname = list_make2(schema,
5754 pstrdup(NameStr(formDict->dictname)));
5756 break;
5757 }
5758
5760 {
5761 HeapTuple tup;
5763 char *schema;
5764
5766 ObjectIdGetDatum(object->objectId));
5767 if (!HeapTupleIsValid(tup))
5768 {
5769 if (!missing_ok)
5770 elog(ERROR, "cache lookup failed for text search template %u",
5771 object->objectId);
5772 break;
5773 }
5775 schema = get_namespace_name_or_temp(formTmpl->tmplnamespace);
5776 appendStringInfoString(&buffer,
5778 NameStr(formTmpl->tmplname)));
5779 if (objname)
5780 *objname = list_make2(schema,
5781 pstrdup(NameStr(formTmpl->tmplname)));
5783 break;
5784 }
5785
5786 case TSConfigRelationId:
5787 {
5788 HeapTuple tup;
5790 char *schema;
5791
5793 ObjectIdGetDatum(object->objectId));
5794 if (!HeapTupleIsValid(tup))
5795 {
5796 if (!missing_ok)
5797 elog(ERROR, "cache lookup failed for text search configuration %u",
5798 object->objectId);
5799 break;
5800 }
5802 schema = get_namespace_name_or_temp(formCfg->cfgnamespace);
5803 appendStringInfoString(&buffer,
5805 NameStr(formCfg->cfgname)));
5806 if (objname)
5807 *objname = list_make2(schema,
5808 pstrdup(NameStr(formCfg->cfgname)));
5810 break;
5811 }
5812
5813 case AuthIdRelationId:
5814 {
5815 char *username;
5816
5817 username = GetUserNameFromId(object->objectId, missing_ok);
5818 if (!username)
5819 break;
5820 if (objname)
5821 *objname = list_make1(username);
5822 appendStringInfoString(&buffer,
5824 break;
5825 }
5826
5827 case AuthMemRelationId:
5828 {
5830 ScanKeyData skey[1];
5832 HeapTuple tup;
5834
5837
5838 ScanKeyInit(&skey[0],
5841 ObjectIdGetDatum(object->objectId));
5842
5844 NULL, 1, skey);
5845
5847
5848 if (!HeapTupleIsValid(tup))
5849 {
5850 if (!missing_ok)
5851 elog(ERROR, "could not find tuple for pg_auth_members entry %u",
5852 object->objectId);
5853
5856 break;
5857 }
5858
5860
5861 appendStringInfo(&buffer, "membership of role %s in role %s",
5862 GetUserNameFromId(amForm->member, false),
5863 GetUserNameFromId(amForm->roleid, false));
5864
5867 break;
5868 }
5869
5870 case DatabaseRelationId:
5871 {
5872 char *datname;
5873
5875 if (!datname)
5876 {
5877 if (!missing_ok)
5878 elog(ERROR, "cache lookup failed for database %u",
5879 object->objectId);
5880 break;
5881 }
5882 if (objname)
5883 *objname = list_make1(datname);
5884 appendStringInfoString(&buffer,
5886 break;
5887 }
5888
5890 {
5891 char *tblspace;
5892
5894 if (!tblspace)
5895 {
5896 if (!missing_ok)
5897 elog(ERROR, "cache lookup failed for tablespace %u",
5898 object->objectId);
5899 break;
5900 }
5901 if (objname)
5902 *objname = list_make1(tblspace);
5903 appendStringInfoString(&buffer,
5905 break;
5906 }
5907
5909 {
5911
5913 missing_ok);
5914 if (fdw)
5915 {
5916 appendStringInfoString(&buffer, quote_identifier(fdw->fdwname));
5917 if (objname)
5918 *objname = list_make1(pstrdup(fdw->fdwname));
5919 }
5920 break;
5921 }
5922
5924 {
5926
5928 missing_ok);
5929 if (srv)
5930 {
5931 appendStringInfoString(&buffer,
5932 quote_identifier(srv->servername));
5933 if (objname)
5934 *objname = list_make1(pstrdup(srv->servername));
5935 }
5936 break;
5937 }
5938
5940 {
5941 HeapTuple tup;
5942 Oid useid;
5945 const char *usename;
5946
5948 ObjectIdGetDatum(object->objectId));
5949 if (!HeapTupleIsValid(tup))
5950 {
5951 if (!missing_ok)
5952 elog(ERROR, "cache lookup failed for user mapping %u",
5953 object->objectId);
5954 break;
5955 }
5957 useid = umform->umuser;
5958 srv = GetForeignServer(umform->umserver);
5959
5961
5962 if (OidIsValid(useid))
5964 else
5965 usename = "public";
5966
5967 if (objname)
5968 {
5969 *objname = list_make1(pstrdup(usename));
5970 *objargs = list_make1(pstrdup(srv->servername));
5971 }
5972
5973 appendStringInfo(&buffer, "%s on server %s",
5975 srv->servername);
5976 break;
5977 }
5978
5980 {
5982 ScanKeyData skey[1];
5984 HeapTuple tup;
5986 char *schema;
5987 char *username;
5988
5990
5991 ScanKeyInit(&skey[0],
5994 ObjectIdGetDatum(object->objectId));
5995
5997 true, NULL, 1, skey);
5998
6000
6001 if (!HeapTupleIsValid(tup))
6002 {
6003 if (!missing_ok)
6004 elog(ERROR, "could not find tuple for default ACL %u",
6005 object->objectId);
6006
6009 break;
6010 }
6011
6013
6014 username = GetUserNameFromId(defacl->defaclrole, false);
6015 appendStringInfo(&buffer,
6016 "for role %s",
6018
6019 if (OidIsValid(defacl->defaclnamespace))
6020 {
6021 schema = get_namespace_name_or_temp(defacl->defaclnamespace);
6022 appendStringInfo(&buffer,
6023 " in schema %s",
6024 quote_identifier(schema));
6025 }
6026 else
6027 schema = NULL;
6028
6029 switch (defacl->defaclobjtype)
6030 {
6031 case DEFACLOBJ_RELATION:
6032 appendStringInfoString(&buffer,
6033 " on tables");
6034 break;
6035 case DEFACLOBJ_SEQUENCE:
6036 appendStringInfoString(&buffer,
6037 " on sequences");
6038 break;
6039 case DEFACLOBJ_FUNCTION:
6040 appendStringInfoString(&buffer,
6041 " on functions");
6042 break;
6043 case DEFACLOBJ_TYPE:
6044 appendStringInfoString(&buffer,
6045 " on types");
6046 break;
6048 appendStringInfoString(&buffer,
6049 " on schemas");
6050 break;
6052 appendStringInfoString(&buffer,
6053 " on large objects");
6054 break;
6055 }
6056
6057 if (objname)
6058 {
6059 *objname = list_make1(username);
6060 if (schema)
6061 *objname = lappend(*objname, schema);
6062 *objargs = list_make1(psprintf("%c", defacl->defaclobjtype));
6063 }
6064
6067 break;
6068 }
6069
6071 {
6072 char *extname;
6073
6074 extname = get_extension_name(object->objectId);
6075 if (!extname)
6076 {
6077 if (!missing_ok)
6078 elog(ERROR, "cache lookup failed for extension %u",
6079 object->objectId);
6080 break;
6081 }
6082 appendStringInfoString(&buffer, quote_identifier(extname));
6083 if (objname)
6084 *objname = list_make1(extname);
6085 break;
6086 }
6087
6089 {
6090 HeapTuple tup;
6092 char *evtname;
6093
6095 ObjectIdGetDatum(object->objectId));
6096 if (!HeapTupleIsValid(tup))
6097 {
6098 if (!missing_ok)
6099 elog(ERROR, "cache lookup failed for event trigger %u",
6100 object->objectId);
6101 break;
6102 }
6104 evtname = pstrdup(NameStr(trigForm->evtname));
6105 appendStringInfoString(&buffer, quote_identifier(evtname));
6106 if (objname)
6107 *objname = list_make1(evtname);
6109 break;
6110 }
6111
6113 {
6114 HeapTuple tup;
6116 char *parname;
6117
6119 ObjectIdGetDatum(object->objectId));
6120 if (!HeapTupleIsValid(tup))
6121 {
6122 if (!missing_ok)
6123 elog(ERROR, "cache lookup failed for parameter ACL %u",
6124 object->objectId);
6125 break;
6126 }
6131 if (objname)
6132 *objname = list_make1(parname);
6134 break;
6135 }
6136
6137 case PolicyRelationId:
6138 {
6140 HeapTuple tup;
6142
6144
6146 object->objectId);
6147
6148 if (!HeapTupleIsValid(tup))
6149 {
6150 if (!missing_ok)
6151 elog(ERROR, "could not find tuple for policy %u",
6152 object->objectId);
6153
6155 break;
6156 }
6157
6159
6160 appendStringInfo(&buffer, "%s on ",
6161 quote_identifier(NameStr(policy->polname)));
6162 getRelationIdentity(&buffer, policy->polrelid, objname, false);
6163 if (objname)
6164 *objname = lappend(*objname, pstrdup(NameStr(policy->polname)));
6165
6167 break;
6168 }
6169
6171 {
6172 HeapTuple tup;
6174
6176 if (!HeapTupleIsValid(tup))
6177 {
6178 if (!missing_ok)
6179 elog(ERROR, "cache lookup failed for property graph element %u", object->objectId);
6180 break;
6181 }
6183 appendStringInfo(&buffer, "%s of property graph ", quote_identifier(NameStr(pge->pgealias)));
6184
6185 getRelationIdentity(&buffer, pge->pgepgid, objname, false);
6186 if (objname)
6187 *objname = lappend(*objname, pstrdup(NameStr(pge->pgealias)));
6188
6190 break;
6191 }
6192
6194 {
6195 HeapTuple tup;
6197
6199 if (!HeapTupleIsValid(tup))
6200 {
6201 if (!missing_ok)
6202 elog(ERROR, "cache lookup failed for property graph label %u", object->objectId);
6203 break;
6204 }
6205
6207 appendStringInfo(&buffer, "%s of property graph ", quote_identifier(NameStr(pgl->pgllabel)));
6208 getRelationIdentity(&buffer, pgl->pglpgid, objname, false);
6209 if (objname)
6210 *objname = lappend(*objname, pstrdup(NameStr(pgl->pgllabel)));
6212 break;
6213 }
6214
6216 {
6217 HeapTuple tup;
6219
6221 if (!HeapTupleIsValid(tup))
6222 {
6223 if (!missing_ok)
6224 elog(ERROR, "cache lookup failed for property graph property %u", object->objectId);
6225 break;
6226 }
6227
6229 appendStringInfo(&buffer, "%s of property graph ", quote_identifier(NameStr(pgp->pgpname)));
6230 getRelationIdentity(&buffer, pgp->pgppgid, objname, false);
6231 if (objname)
6232 *objname = lappend(*objname, pstrdup(NameStr(pgp->pgpname)));
6234 break;
6235 }
6236
6238 {
6240 HeapTuple tup;
6243 char *labelname;
6244
6248 object->objectId);
6249 if (!HeapTupleIsValid(tup))
6250 {
6251 if (!missing_ok)
6252 elog(ERROR, "could not find tuple for element label %u",
6253 object->objectId);
6254
6256 break;
6257 }
6258
6260
6262 appendStringInfo(&buffer, "%s of element ", quote_identifier(labelname));
6265 objargs, false));
6266 /* labelname is already pstrdup'ed. */
6267 if (objname)
6268 *objname = lappend(*objname, labelname);
6269
6271 break;
6272 }
6273
6275 {
6277 HeapTuple tup;
6280 char *propname;
6281
6286 object->objectId);
6287 if (!HeapTupleIsValid(tup))
6288 {
6289 if (!missing_ok)
6290 elog(ERROR, "could not find tuple for label property %u",
6291 object->objectId);
6292
6294 break;
6295 }
6296
6298
6300 appendStringInfo(&buffer, "%s of label ", quote_identifier(propname));
6303 objargs, false));
6304 /* propname is already pstrdup'ed. */
6305 if (objname)
6306 *objname = lappend(*objname, propname);
6307
6309 break;
6310 }
6311
6313 {
6314 char *pubname;
6315
6316 pubname = get_publication_name(object->objectId, missing_ok);
6317 if (pubname)
6318 {
6319 appendStringInfoString(&buffer,
6320 quote_identifier(pubname));
6321 if (objname)
6322 *objname = list_make1(pubname);
6323 }
6324 break;
6325 }
6326
6328 {
6329 char *pubname;
6330 char *nspname;
6331
6332 if (!getPublicationSchemaInfo(object, missing_ok, &pubname,
6333 &nspname))
6334 break;
6335 appendStringInfo(&buffer, "%s in publication %s",
6336 nspname, pubname);
6337
6338 if (objargs)
6339 *objargs = list_make1(pubname);
6340 else
6341 pfree(pubname);
6342
6343 if (objname)
6344 *objname = list_make1(nspname);
6345 else
6346 pfree(nspname);
6347
6348 break;
6349 }
6350
6352 {
6353 HeapTuple tup;
6354 char *pubname;
6356
6358 ObjectIdGetDatum(object->objectId));
6359 if (!HeapTupleIsValid(tup))
6360 {
6361 if (!missing_ok)
6362 elog(ERROR, "cache lookup failed for publication table %u",
6363 object->objectId);
6364 break;
6365 }
6366
6368 pubname = get_publication_name(prform->prpubid, false);
6369
6370 getRelationIdentity(&buffer, prform->prrelid, objname, false);
6371 appendStringInfo(&buffer, " in publication %s", pubname);
6372
6373 if (objargs)
6374 *objargs = list_make1(pubname);
6375
6377 break;
6378 }
6379
6381 {
6382 char *subname;
6383
6384 subname = get_subscription_name(object->objectId, missing_ok);
6385 if (subname)
6386 {
6387 appendStringInfoString(&buffer,
6389 if (objname)
6390 *objname = list_make1(subname);
6391 }
6392 break;
6393 }
6394
6396 {
6398 HeapTuple tup;
6399 Form_pg_transform transform;
6400 char *transformLang;
6401 char *transformType;
6402
6404
6407 object->objectId);
6408
6409 if (!HeapTupleIsValid(tup))
6410 {
6411 if (!missing_ok)
6412 elog(ERROR, "could not find tuple for transform %u",
6413 object->objectId);
6414
6416 break;
6417 }
6418
6419 transform = (Form_pg_transform) GETSTRUCT(tup);
6420
6421 transformType = format_type_be_qualified(transform->trftype);
6422 transformLang = get_language_name(transform->trflang, false);
6423
6424 appendStringInfo(&buffer, "for %s language %s",
6427 if (objname)
6428 {
6429 *objname = list_make1(transformType);
6430 *objargs = list_make1(pstrdup(transformLang));
6431 }
6432
6434 }
6435 break;
6436
6437 default:
6438 elog(ERROR, "unsupported object class: %u", object->classId);
6439 }
6440
6441 if (!missing_ok)
6442 {
6443 /*
6444 * If a get_object_address() representation was requested, make sure
6445 * we are providing one. We don't check objargs, because many of the
6446 * cases above leave it as NIL.
6447 */
6448 if (objname && *objname == NIL)
6449 elog(ERROR, "requested object address for unsupported object class %u: text result \"%s\"",
6450 object->classId, buffer.data);
6451 }
6452 else
6453 {
6454 /* an empty buffer is equivalent to no object found */
6455 if (buffer.len == 0)
6456 {
6457 Assert((objname == NULL || *objname == NIL) &&
6458 (objargs == NULL || *objargs == NIL));
6459 return NULL;
6460 }
6461 }
6462
6463 return buffer.data;
6464}
char * get_am_name(Oid amOid)
Definition amcmds.c:192
#define FORMAT_TYPE_FORCE_QUALIFY
Definition builtins.h:127
char * format_type_be_qualified(Oid type_oid)
List * lappend(List *list, void *datum)
Definition list.c:339
char * get_namespace_name_or_temp(Oid nspid)
Definition lsyscache.c:3706
char * pstrdup(const char *in)
Definition mcxt.c:1910
static void getOpFamilyIdentity(StringInfo buffer, Oid opfid, List **object, bool missing_ok)
static void getRelationIdentity(StringInfo buffer, Oid relid, List **object, bool missing_ok)
END_CATALOG_STRUCT typedef FormData_pg_language * Form_pg_language
Definition pg_language.h:69
#define NIL
Definition pg_list.h:68
#define list_make1(x1)
Definition pg_list.h:244
#define list_make3(x1, x2, x3)
Definition pg_list.h:248
#define list_make2(x1, x2)
Definition pg_list.h:246
char * psprintf(const char *fmt,...)
Definition psprintf.c:43
void format_operator_parts(Oid operator_oid, List **objnames, List **objargs, bool missing_ok)
Definition regproc.c:814
void format_procedure_parts(Oid procedure_oid, List **objnames, List **objargs, bool missing_ok)
Definition regproc.c:404
#define FORMAT_OPERATOR_FORCE_QUALIFY
Definition regproc.h:25
#define FORMAT_PROC_FORCE_QUALIFY
Definition regproc.h:20
const char * quote_identifier(const char *ident)
void appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230

References AccessShareLock, appendStringInfo(), appendStringInfoString(), Assert, BTEqualStrategyNumber, ObjectAddress::classId, StringInfoData::data, datname, elog, ERROR, fb(), Form_pg_am, Form_pg_amop, Form_pg_amproc, Form_pg_auth_members, Form_pg_cast, Form_pg_collation, Form_pg_constraint, Form_pg_conversion, Form_pg_default_acl, Form_pg_event_trigger, Form_pg_language, Form_pg_opclass, Form_pg_policy, Form_pg_propgraph_element, Form_pg_propgraph_element_label, Form_pg_propgraph_label, Form_pg_propgraph_label_property, Form_pg_propgraph_property, Form_pg_publication_rel, Form_pg_rewrite, Form_pg_statistic_ext, Form_pg_transform, Form_pg_trigger, Form_pg_ts_config, Form_pg_ts_dict, Form_pg_ts_parser, Form_pg_ts_template, Form_pg_user_mapping, format_operator_extended(), FORMAT_OPERATOR_FORCE_QUALIFY, FORMAT_OPERATOR_INVALID_AS_NULL, format_operator_parts(), FORMAT_PROC_FORCE_QUALIFY, FORMAT_PROC_INVALID_AS_NULL, format_procedure_extended(), format_procedure_parts(), format_type_be_qualified(), format_type_extended(), FORMAT_TYPE_FORCE_QUALIFY, FORMAT_TYPE_INVALID_AS_NULL, get_am_name(), get_attname(), get_catalog_object_by_oid(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name_or_temp(), get_propgraph_label_name(), get_propgraph_property_name(), get_publication_name(), get_subscription_name(), get_tablespace_name(), GetAttrDefaultColumnAddress(), GetForeignDataWrapperExtended(), GetForeignServer(), GetForeignServerExtended(), getObjectIdentityParts(), getOpFamilyIdentity(), getPublicationSchemaInfo(), getRelationIdentity(), GETSTRUCT(), GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), lappend(), LargeObjectExists(), StringInfoData::len, list_make1, list_make2, list_make3, NameStr, NIL, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, OidIsValid, pfree(), proname, psprintf(), pstrdup(), quote_identifier(), quote_qualified_identifier(), ReleaseSysCache(), ScanKeyInit(), SearchSysCache1(), subname, SysCacheGetAttrNotNull(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TextDatumGetCString, and username.

Referenced by EventTriggerSQLDropAddObject(), getObjectIdentity(), getObjectIdentityParts(), and pg_identify_object_as_address().

◆ getObjectTypeDescription()

char * getObjectTypeDescription ( const ObjectAddress object,
bool  missing_ok 
)
extern

Definition at line 4746 of file objectaddress.c.

4747{
4748 StringInfoData buffer;
4749
4750 initStringInfo(&buffer);
4751
4752 switch (object->classId)
4753 {
4754 case RelationRelationId:
4755 getRelationTypeDescription(&buffer, object->objectId,
4756 object->objectSubId,
4757 missing_ok);
4758 break;
4759
4761 getProcedureTypeDescription(&buffer, object->objectId,
4762 missing_ok);
4763 break;
4764
4765 case TypeRelationId:
4766 appendStringInfoString(&buffer, "type");
4767 break;
4768
4769 case CastRelationId:
4770 appendStringInfoString(&buffer, "cast");
4771 break;
4772
4774 appendStringInfoString(&buffer, "collation");
4775 break;
4776
4778 getConstraintTypeDescription(&buffer, object->objectId,
4779 missing_ok);
4780 break;
4781
4783 appendStringInfoString(&buffer, "conversion");
4784 break;
4785
4787 appendStringInfoString(&buffer, "default value");
4788 break;
4789
4790 case LanguageRelationId:
4791 appendStringInfoString(&buffer, "language");
4792 break;
4793
4795 appendStringInfoString(&buffer, "large object");
4796 break;
4797
4798 case OperatorRelationId:
4799 appendStringInfoString(&buffer, "operator");
4800 break;
4801
4803 appendStringInfoString(&buffer, "operator class");
4804 break;
4805
4807 appendStringInfoString(&buffer, "operator family");
4808 break;
4809
4811 appendStringInfoString(&buffer, "access method");
4812 break;
4813
4815 appendStringInfoString(&buffer, "operator of access method");
4816 break;
4817
4819 appendStringInfoString(&buffer, "function of access method");
4820 break;
4821
4822 case RewriteRelationId:
4823 appendStringInfoString(&buffer, "rule");
4824 break;
4825
4826 case TriggerRelationId:
4827 appendStringInfoString(&buffer, "trigger");
4828 break;
4829
4831 appendStringInfoString(&buffer, "schema");
4832 break;
4833
4835 appendStringInfoString(&buffer, "statistics object");
4836 break;
4837
4838 case TSParserRelationId:
4839 appendStringInfoString(&buffer, "text search parser");
4840 break;
4841
4843 appendStringInfoString(&buffer, "text search dictionary");
4844 break;
4845
4847 appendStringInfoString(&buffer, "text search template");
4848 break;
4849
4850 case TSConfigRelationId:
4851 appendStringInfoString(&buffer, "text search configuration");
4852 break;
4853
4854 case AuthIdRelationId:
4855 appendStringInfoString(&buffer, "role");
4856 break;
4857
4858 case AuthMemRelationId:
4859 appendStringInfoString(&buffer, "role membership");
4860 break;
4861
4862 case DatabaseRelationId:
4863 appendStringInfoString(&buffer, "database");
4864 break;
4865
4867 appendStringInfoString(&buffer, "tablespace");
4868 break;
4869
4871 appendStringInfoString(&buffer, "foreign-data wrapper");
4872 break;
4873
4875 appendStringInfoString(&buffer, "server");
4876 break;
4877
4879 appendStringInfoString(&buffer, "user mapping");
4880 break;
4881
4883 appendStringInfoString(&buffer, "default acl");
4884 break;
4885
4887 appendStringInfoString(&buffer, "extension");
4888 break;
4889
4891 appendStringInfoString(&buffer, "event trigger");
4892 break;
4893
4895 appendStringInfoString(&buffer, "parameter ACL");
4896 break;
4897
4898 case PolicyRelationId:
4899 appendStringInfoString(&buffer, "policy");
4900 break;
4901
4903 appendStringInfoString(&buffer, "property graph element");
4904 break;
4905
4907 appendStringInfoString(&buffer, "property graph label");
4908 break;
4909
4911 appendStringInfoString(&buffer, "property graph property");
4912 break;
4913
4915 appendStringInfoString(&buffer, "property graph element label");
4916 break;
4917
4919 appendStringInfoString(&buffer, "property graph label property");
4920 break;
4921
4923 appendStringInfoString(&buffer, "publication");
4924 break;
4925
4927 appendStringInfoString(&buffer, "publication namespace");
4928 break;
4929
4931 appendStringInfoString(&buffer, "publication relation");
4932 break;
4933
4935 appendStringInfoString(&buffer, "subscription");
4936 break;
4937
4939 appendStringInfoString(&buffer, "transform");
4940 break;
4941
4942 default:
4943 elog(ERROR, "unsupported object class: %u", object->classId);
4944 }
4945
4946 /* the result can never be empty */
4947 Assert(buffer.len > 0);
4948
4949 return buffer.data;
4950}
static void getConstraintTypeDescription(StringInfo buffer, Oid constroid, bool missing_ok)
static void getProcedureTypeDescription(StringInfo buffer, Oid procid, bool missing_ok)
static void getRelationTypeDescription(StringInfo buffer, Oid relid, int32 objectSubId, bool missing_ok)

References appendStringInfoString(), Assert, ObjectAddress::classId, StringInfoData::data, elog, ERROR, fb(), getConstraintTypeDescription(), getProcedureTypeDescription(), getRelationTypeDescription(), initStringInfo(), StringInfoData::len, ObjectAddress::objectId, and ObjectAddress::objectSubId.

Referenced by EventTriggerSQLDropAddObject(), pg_event_trigger_ddl_commands(), pg_identify_object(), pg_identify_object_as_address(), and sepgsql_object_relabel().

◆ is_objectclass_supported()

bool is_objectclass_supported ( Oid  class_id)
extern

Definition at line 2839 of file objectaddress.c.

2840{
2841 for (size_t index = 0; index < lengthof(ObjectProperty); index++)
2842 {
2843 if (ObjectProperty[index].class_oid == class_id)
2844 return true;
2845 }
2846
2847 return false;
2848}
#define lengthof(array)
Definition c.h:932
static const ObjectPropertyType ObjectProperty[]
Definition type.h:97

References fb(), lengthof, and ObjectProperty.

Referenced by obtain_object_name_namespace(), pg_event_trigger_ddl_commands(), and pg_identify_object().

◆ read_objtype_from_string()

int read_objtype_from_string ( const char objtype)
extern

Definition at line 2712 of file objectaddress.c.

2713{
2714 for (size_t i = 0; i < lengthof(ObjectTypeMap); i++)
2715 {
2716 if (strcmp(ObjectTypeMap[i].tm_name, objtype) == 0)
2717 return ObjectTypeMap[i].tm_type;
2718 }
2719 ereport(ERROR,
2721 errmsg("unrecognized object type \"%s\"", objtype)));
2722
2723 return -1; /* keep compiler quiet */
2724}
int i
Definition isn.c:77
static const struct object_type_map ObjectTypeMap[]

References ereport, errcode(), errmsg, ERROR, fb(), i, lengthof, and ObjectTypeMap.

Referenced by pg_get_object_address().

◆ strlist_to_textarray()

struct ArrayType * strlist_to_textarray ( List list)
extern

Definition at line 6545 of file objectaddress.c.

6546{
6547 ArrayType *arr;
6548 Datum *datums;
6549 bool *nulls;
6550 int j = 0;
6551 ListCell *cell;
6552 MemoryContext memcxt;
6554 int lb[1];
6555
6556 /* Work in a temp context; easier than individually pfree'ing the Datums */
6558 "strlist to array",
6560 oldcxt = MemoryContextSwitchTo(memcxt);
6561
6562 datums = palloc_array(Datum, list_length(list));
6563 nulls = palloc_array(bool, list_length(list));
6564
6565 foreach(cell, list)
6566 {
6567 char *name = lfirst(cell);
6568
6569 if (name)
6570 {
6571 nulls[j] = false;
6572 datums[j++] = CStringGetTextDatum(name);
6573 }
6574 else
6575 nulls[j] = true;
6576 }
6577
6579
6580 lb[0] = 1;
6581 arr = construct_md_array(datums, nulls, 1, &j,
6582 lb, TEXTOID, -1, false, TYPALIGN_INT);
6583
6584 MemoryContextDelete(memcxt);
6585
6586 return arr;
6587}
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
#define CStringGetTextDatum(s)
Definition builtins.h:98
#define palloc_array(type, count)
Definition fe_memutils.h:91
int j
Definition isn.c:78
MemoryContext CurrentMemoryContext
Definition mcxt.c:161
void MemoryContextDelete(MemoryContext context)
Definition mcxt.c:475
#define AllocSetContextCreate
Definition memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition memutils.h:160
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:138
#define lfirst(lc)
Definition pg_list.h:172
static int list_length(const List *l)
Definition pg_list.h:152
const char * name

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, construct_md_array(), CStringGetTextDatum, CurrentMemoryContext, fb(), j, lfirst, list_length(), MemoryContextDelete(), MemoryContextSwitchTo(), name, and palloc_array.

Referenced by fill_hba_line(), pg_event_trigger_dropped_objects(), and pg_identify_object_as_address().

Variable Documentation

◆ InvalidObjectAddress