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:5444
@ 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:4134
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition aclchk.c:2997
bool has_createrole_privilege(Oid roleid)
Definition aclchk.c:4213
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:182
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 2893 of file objectaddress.c.

2894{
2895 return
2897}
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 2906 of file objectaddress.c.

2910{
2911 HeapTuple tuple;
2912 Oid classId = RelationGetRelid(catalog);
2914
2915 if (oidCacheId >= 0)
2916 {
2917 if (locktup)
2919 ObjectIdGetDatum(objectId));
2920 else
2922 ObjectIdGetDatum(objectId));
2923 if (!HeapTupleIsValid(tuple)) /* should not happen */
2924 return NULL;
2925 }
2926 else
2927 {
2929 SysScanDesc scan;
2931
2933
2935 oidcol,
2937 ObjectIdGetDatum(objectId));
2938
2940 NULL, 1, &skey);
2941 tuple = systable_getnext(scan);
2942 if (!HeapTupleIsValid(tuple))
2943 {
2944 systable_endscan(scan);
2945 return NULL;
2946 }
2947
2948 if (locktup)
2950
2951 tuple = heap_copytuple(tuple);
2952
2953 systable_endscan(scan);
2954 }
2955
2956 return tuple;
2957}
#define Assert(condition)
Definition c.h:943
#define OidIsValid(objectId)
Definition c.h:858
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:625
bool IsSharedRelation(Oid relationId)
Definition catalog.c:304
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:1225
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:135
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 2796 of file objectaddress.c.

2797{
2799
2800 return prop->attnum_acl;
2801}
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 2756 of file objectaddress.c.

2757{
2759
2760 return prop->name_catcache_id;
2761}
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 2811 of file objectaddress.c.

2812{
2814
2815 if (prop->objtype == OBJECT_TABLE)
2816 {
2817 /*
2818 * If the property data says it's a table, dig a little deeper to get
2819 * the real relation kind, so that callers can produce more precise
2820 * error messages.
2821 */
2822 return get_relkind_objtype(get_rel_relkind(object_id));
2823 }
2824 else
2825 return prop->objtype;
2826}
char get_rel_relkind(Oid relid)
Definition lsyscache.c:2309
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 6592 of file objectaddress.c.

6593{
6594 switch (relkind)
6595 {
6596 case RELKIND_RELATION:
6598 return OBJECT_TABLE;
6599 case RELKIND_INDEX:
6601 return OBJECT_INDEX;
6602 case RELKIND_SEQUENCE:
6603 return OBJECT_SEQUENCE;
6604 case RELKIND_VIEW:
6605 return OBJECT_VIEW;
6606 case RELKIND_MATVIEW:
6607 return OBJECT_MATVIEW;
6609 return OBJECT_FOREIGN_TABLE;
6610 case RELKIND_PROPGRAPH:
6611 return OBJECT_PROPGRAPH;
6612 case RELKIND_TOASTVALUE:
6613 return OBJECT_TABLE;
6614 default:
6615 /* Per above, don't raise an error */
6616 return OBJECT_TABLE;
6617 }
6618}

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 3015 of file objectaddress.c.

3016{
3017 StringInfoData buffer;
3018
3019 initStringInfo(&buffer);
3020
3021 switch (object->classId)
3022 {
3023 case RelationRelationId:
3024 if (object->objectSubId == 0)
3025 getRelationDescription(&buffer, object->objectId, missing_ok);
3026 else
3027 {
3028 /* column, not whole relation */
3029 StringInfoData rel;
3030 char *attname = get_attname(object->objectId,
3031 object->objectSubId,
3032 missing_ok);
3033
3034 if (!attname)
3035 break;
3036
3037 initStringInfo(&rel);
3038 getRelationDescription(&rel, object->objectId, missing_ok);
3039 /* translator: second %s is, e.g., "table %s" */
3040 appendStringInfo(&buffer, _("column %s of %s"),
3041 attname, rel.data);
3042 pfree(rel.data);
3043 }
3044 break;
3045
3047 {
3050 flags);
3051
3052 if (proname == NULL)
3053 break;
3054
3055 appendStringInfo(&buffer, _("function %s"), proname);
3056 break;
3057 }
3058
3059 case TypeRelationId:
3060 {
3062 char *typname = format_type_extended(object->objectId, -1,
3063 flags);
3064
3065 if (typname == NULL)
3066 break;
3067
3068 appendStringInfo(&buffer, _("type %s"), typname);
3069 break;
3070 }
3071
3072 case CastRelationId:
3073 {
3075 ScanKeyData skey[1];
3077 HeapTuple tup;
3079
3081
3082 ScanKeyInit(&skey[0],
3085 ObjectIdGetDatum(object->objectId));
3086
3088 NULL, 1, skey);
3089
3091
3092 if (!HeapTupleIsValid(tup))
3093 {
3094 if (!missing_ok)
3095 elog(ERROR, "could not find tuple for cast %u",
3096 object->objectId);
3097
3100 break;
3101 }
3102
3104
3105 appendStringInfo(&buffer, _("cast from %s to %s"),
3106 format_type_be(castForm->castsource),
3107 format_type_be(castForm->casttarget));
3108
3111 break;
3112 }
3113
3115 {
3117 Form_pg_collation coll;
3118 char *nspname;
3119
3121 ObjectIdGetDatum(object->objectId));
3123 {
3124 if (!missing_ok)
3125 elog(ERROR, "cache lookup failed for collation %u",
3126 object->objectId);
3127 break;
3128 }
3129
3131
3132 /* Qualify the name if not visible in search path */
3133 if (CollationIsVisible(object->objectId))
3134 nspname = NULL;
3135 else
3136 nspname = get_namespace_name(coll->collnamespace);
3137
3138 appendStringInfo(&buffer, _("collation %s"),
3140 NameStr(coll->collname)));
3142 break;
3143 }
3144
3146 {
3149
3151 ObjectIdGetDatum(object->objectId));
3153 {
3154 if (!missing_ok)
3155 elog(ERROR, "cache lookup failed for constraint %u",
3156 object->objectId);
3157 break;
3158 }
3159
3161
3162 if (OidIsValid(con->conrelid))
3163 {
3164 StringInfoData rel;
3165
3166 initStringInfo(&rel);
3167 getRelationDescription(&rel, con->conrelid, false);
3168 /* translator: second %s is, e.g., "table %s" */
3169 appendStringInfo(&buffer, _("constraint %s on %s"),
3170 NameStr(con->conname), rel.data);
3171 pfree(rel.data);
3172 }
3173 else
3174 {
3175 appendStringInfo(&buffer, _("constraint %s"),
3176 NameStr(con->conname));
3177 }
3178
3180 break;
3181 }
3182
3184 {
3187 char *nspname;
3188
3190 ObjectIdGetDatum(object->objectId));
3192 {
3193 if (!missing_ok)
3194 elog(ERROR, "cache lookup failed for conversion %u",
3195 object->objectId);
3196 break;
3197 }
3198
3200
3201 /* Qualify the name if not visible in search path */
3202 if (ConversionIsVisible(object->objectId))
3203 nspname = NULL;
3204 else
3205 nspname = get_namespace_name(conv->connamespace);
3206
3207 appendStringInfo(&buffer, _("conversion %s"),
3209 NameStr(conv->conname)));
3211 break;
3212 }
3213
3215 {
3217
3219
3220 if (!OidIsValid(colobject.objectId))
3221 {
3222 if (!missing_ok)
3223 elog(ERROR, "could not find tuple for attrdef %u",
3224 object->objectId);
3225 break;
3226 }
3227
3228 /* translator: %s is typically "column %s of table %s" */
3229 appendStringInfo(&buffer, _("default value for %s"),
3231 break;
3232 }
3233
3234 case LanguageRelationId:
3235 {
3236 char *langname = get_language_name(object->objectId,
3237 missing_ok);
3238
3239 if (langname)
3240 appendStringInfo(&buffer, _("language %s"),
3241 get_language_name(object->objectId, false));
3242 break;
3243 }
3244
3246 if (!LargeObjectExists(object->objectId))
3247 break;
3248 appendStringInfo(&buffer, _("large object %u"),
3249 object->objectId);
3250 break;
3251
3252 case OperatorRelationId:
3253 {
3255 char *oprname = format_operator_extended(object->objectId,
3256 flags);
3257
3258 if (oprname == NULL)
3259 break;
3260
3261 appendStringInfo(&buffer, _("operator %s"), oprname);
3262 break;
3263 }
3264
3266 {
3271 char *nspname;
3272
3274 ObjectIdGetDatum(object->objectId));
3276 {
3277 if (!missing_ok)
3278 elog(ERROR, "cache lookup failed for opclass %u",
3279 object->objectId);
3280 break;
3281 }
3282
3284
3286 ObjectIdGetDatum(opcForm->opcmethod));
3287 if (!HeapTupleIsValid(amTup))
3288 elog(ERROR, "cache lookup failed for access method %u",
3289 opcForm->opcmethod);
3291
3292 /* Qualify the name if not visible in search path */
3293 if (OpclassIsVisible(object->objectId))
3294 nspname = NULL;
3295 else
3296 nspname = get_namespace_name(opcForm->opcnamespace);
3297
3298 appendStringInfo(&buffer, _("operator class %s for access method %s"),
3300 NameStr(opcForm->opcname)),
3301 NameStr(amForm->amname));
3302
3305 break;
3306 }
3307
3309 getOpFamilyDescription(&buffer, object->objectId, missing_ok);
3310 break;
3311
3313 {
3314 HeapTuple tup;
3315
3317 ObjectIdGetDatum(object->objectId));
3318 if (!HeapTupleIsValid(tup))
3319 {
3320 if (!missing_ok)
3321 elog(ERROR, "cache lookup failed for access method %u",
3322 object->objectId);
3323 break;
3324 }
3325
3326 appendStringInfo(&buffer, _("access method %s"),
3327 NameStr(((Form_pg_am) GETSTRUCT(tup))->amname));
3329 break;
3330 }
3331
3333 {
3335 HeapTuple tup;
3336 ScanKeyData skey[1];
3339 StringInfoData opfam;
3340
3343
3344 ScanKeyInit(&skey[0],
3347 ObjectIdGetDatum(object->objectId));
3348
3350 NULL, 1, skey);
3351
3353
3354 if (!HeapTupleIsValid(tup))
3355 {
3356 if (!missing_ok)
3357 elog(ERROR, "could not find tuple for amop entry %u",
3358 object->objectId);
3359
3362 break;
3363 }
3364
3366
3367 initStringInfo(&opfam);
3368 getOpFamilyDescription(&opfam, amopForm->amopfamily, false);
3369
3370 /*
3371 * We use FORMAT_TYPE_ALLOW_INVALID here so as not to fail
3372 * completely if the type links are dangling, which is a form
3373 * of catalog corruption that could occur due to old bugs.
3374 */
3375
3376 /*------
3377 translator: %d is the operator strategy (a number), the
3378 first two %s's are data type names, the third %s is the
3379 description of the operator family, and the last %s is the
3380 textual form of the operator with arguments. */
3381 appendStringInfo(&buffer, _("operator %d (%s, %s) of %s: %s"),
3382 amopForm->amopstrategy,
3383 format_type_extended(amopForm->amoplefttype,
3385 format_type_extended(amopForm->amoprighttype,
3387 opfam.data,
3388 format_operator(amopForm->amopopr));
3389
3390 pfree(opfam.data);
3391
3394 break;
3395 }
3396
3398 {
3400 ScanKeyData skey[1];
3402 HeapTuple tup;
3404 StringInfoData opfam;
3405
3408
3409 ScanKeyInit(&skey[0],
3412 ObjectIdGetDatum(object->objectId));
3413
3415 NULL, 1, skey);
3416
3418
3419 if (!HeapTupleIsValid(tup))
3420 {
3421 if (!missing_ok)
3422 elog(ERROR, "could not find tuple for amproc entry %u",
3423 object->objectId);
3424
3427 break;
3428 }
3429
3431
3432 initStringInfo(&opfam);
3433 getOpFamilyDescription(&opfam, amprocForm->amprocfamily, false);
3434
3435 /*
3436 * We use FORMAT_TYPE_ALLOW_INVALID here so as not to fail
3437 * completely if the type links are dangling, which is a form
3438 * of catalog corruption that could occur due to old bugs.
3439 */
3440
3441 /*------
3442 translator: %d is the function number, the first two %s's
3443 are data type names, the third %s is the description of the
3444 operator family, and the last %s is the textual form of the
3445 function with arguments. */
3446 appendStringInfo(&buffer, _("function %d (%s, %s) of %s: %s"),
3447 amprocForm->amprocnum,
3448 format_type_extended(amprocForm->amproclefttype,
3450 format_type_extended(amprocForm->amprocrighttype,
3452 opfam.data,
3453 format_procedure(amprocForm->amproc));
3454
3455 pfree(opfam.data);
3456
3459 break;
3460 }
3461
3462 case RewriteRelationId:
3463 {
3465 ScanKeyData skey[1];
3467 HeapTuple tup;
3469 StringInfoData rel;
3470
3472
3473 ScanKeyInit(&skey[0],
3476 ObjectIdGetDatum(object->objectId));
3477
3479 NULL, 1, skey);
3480
3482
3483 if (!HeapTupleIsValid(tup))
3484 {
3485 if (!missing_ok)
3486 elog(ERROR, "could not find tuple for rule %u",
3487 object->objectId);
3488
3491 break;
3492 }
3493
3495
3496 initStringInfo(&rel);
3497 getRelationDescription(&rel, rule->ev_class, false);
3498
3499 /* translator: second %s is, e.g., "table %s" */
3500 appendStringInfo(&buffer, _("rule %s on %s"),
3501 NameStr(rule->rulename), rel.data);
3502 pfree(rel.data);
3505 break;
3506 }
3507
3508 case TriggerRelationId:
3509 {
3511 ScanKeyData skey[1];
3513 HeapTuple tup;
3515 StringInfoData rel;
3516
3518
3519 ScanKeyInit(&skey[0],
3522 ObjectIdGetDatum(object->objectId));
3523
3525 NULL, 1, skey);
3526
3528
3529 if (!HeapTupleIsValid(tup))
3530 {
3531 if (!missing_ok)
3532 elog(ERROR, "could not find tuple for trigger %u",
3533 object->objectId);
3534
3537 break;
3538 }
3539
3541
3542 initStringInfo(&rel);
3543 getRelationDescription(&rel, trig->tgrelid, false);
3544
3545 /* translator: second %s is, e.g., "table %s" */
3546 appendStringInfo(&buffer, _("trigger %s on %s"),
3547 NameStr(trig->tgname), rel.data);
3548 pfree(rel.data);
3551 break;
3552 }
3553
3555 {
3556 char *nspname;
3557
3558 nspname = get_namespace_name(object->objectId);
3559 if (!nspname)
3560 {
3561 if (!missing_ok)
3562 elog(ERROR, "cache lookup failed for namespace %u",
3563 object->objectId);
3564 break;
3565 }
3566 appendStringInfo(&buffer, _("schema %s"), nspname);
3567 break;
3568 }
3569
3571 {
3574 char *nspname;
3575
3577 ObjectIdGetDatum(object->objectId));
3579 {
3580 if (!missing_ok)
3581 elog(ERROR, "could not find tuple for statistics object %u",
3582 object->objectId);
3583 break;
3584 }
3585
3587
3588 /* Qualify the name if not visible in search path */
3589 if (StatisticsObjIsVisible(object->objectId))
3590 nspname = NULL;
3591 else
3592 nspname = get_namespace_name(stxForm->stxnamespace);
3593
3594 appendStringInfo(&buffer, _("statistics object %s"),
3596 NameStr(stxForm->stxname)));
3597
3599 break;
3600 }
3601
3602 case TSParserRelationId:
3603 {
3604 HeapTuple tup;
3606 char *nspname;
3607
3609 ObjectIdGetDatum(object->objectId));
3610 if (!HeapTupleIsValid(tup))
3611 {
3612 if (!missing_ok)
3613 elog(ERROR, "cache lookup failed for text search parser %u",
3614 object->objectId);
3615 break;
3616 }
3618
3619 /* Qualify the name if not visible in search path */
3620 if (TSParserIsVisible(object->objectId))
3621 nspname = NULL;
3622 else
3623 nspname = get_namespace_name(prsForm->prsnamespace);
3624
3625 appendStringInfo(&buffer, _("text search parser %s"),
3627 NameStr(prsForm->prsname)));
3629 break;
3630 }
3631
3633 {
3634 HeapTuple tup;
3636 char *nspname;
3637
3639 ObjectIdGetDatum(object->objectId));
3640 if (!HeapTupleIsValid(tup))
3641 {
3642 if (!missing_ok)
3643 elog(ERROR, "cache lookup failed for text search dictionary %u",
3644 object->objectId);
3645 break;
3646 }
3647
3649
3650 /* Qualify the name if not visible in search path */
3651 if (TSDictionaryIsVisible(object->objectId))
3652 nspname = NULL;
3653 else
3654 nspname = get_namespace_name(dictForm->dictnamespace);
3655
3656 appendStringInfo(&buffer, _("text search dictionary %s"),
3658 NameStr(dictForm->dictname)));
3660 break;
3661 }
3662
3664 {
3665 HeapTuple tup;
3667 char *nspname;
3668
3670 ObjectIdGetDatum(object->objectId));
3671 if (!HeapTupleIsValid(tup))
3672 {
3673 if (!missing_ok)
3674 elog(ERROR, "cache lookup failed for text search template %u",
3675 object->objectId);
3676 break;
3677 }
3678
3680
3681 /* Qualify the name if not visible in search path */
3682 if (TSTemplateIsVisible(object->objectId))
3683 nspname = NULL;
3684 else
3685 nspname = get_namespace_name(tmplForm->tmplnamespace);
3686
3687 appendStringInfo(&buffer, _("text search template %s"),
3689 NameStr(tmplForm->tmplname)));
3691 break;
3692 }
3693
3694 case TSConfigRelationId:
3695 {
3696 HeapTuple tup;
3698 char *nspname;
3699
3701 ObjectIdGetDatum(object->objectId));
3702 if (!HeapTupleIsValid(tup))
3703 {
3704 if (!missing_ok)
3705 elog(ERROR, "cache lookup failed for text search configuration %u",
3706 object->objectId);
3707 break;
3708 }
3709
3711
3712 /* Qualify the name if not visible in search path */
3713 if (TSConfigIsVisible(object->objectId))
3714 nspname = NULL;
3715 else
3716 nspname = get_namespace_name(cfgForm->cfgnamespace);
3717
3718 appendStringInfo(&buffer, _("text search configuration %s"),
3720 NameStr(cfgForm->cfgname)));
3722 break;
3723 }
3724
3725 case AuthIdRelationId:
3726 {
3727 char *username = GetUserNameFromId(object->objectId,
3728 missing_ok);
3729
3730 if (username)
3731 appendStringInfo(&buffer, _("role %s"), username);
3732 break;
3733 }
3734
3735 case AuthMemRelationId:
3736 {
3738 ScanKeyData skey[1];
3740 HeapTuple tup;
3742
3744
3745 ScanKeyInit(&skey[0],
3748 ObjectIdGetDatum(object->objectId));
3749
3751 NULL, 1, skey);
3752
3754
3755 if (!HeapTupleIsValid(tup))
3756 {
3757 if (!missing_ok)
3758 elog(ERROR, "could not find tuple for role membership %u",
3759 object->objectId);
3760
3763 break;
3764 }
3765
3767
3768 appendStringInfo(&buffer, _("membership of role %s in role %s"),
3769 GetUserNameFromId(amForm->member, false),
3770 GetUserNameFromId(amForm->roleid, false));
3771
3774 break;
3775 }
3776
3777 case DatabaseRelationId:
3778 {
3779 char *datname;
3780
3782 if (!datname)
3783 {
3784 if (!missing_ok)
3785 elog(ERROR, "cache lookup failed for database %u",
3786 object->objectId);
3787 break;
3788 }
3789 appendStringInfo(&buffer, _("database %s"), datname);
3790 break;
3791 }
3792
3794 {
3795 char *tblspace;
3796
3798 if (!tblspace)
3799 {
3800 if (!missing_ok)
3801 elog(ERROR, "cache lookup failed for tablespace %u",
3802 object->objectId);
3803 break;
3804 }
3805 appendStringInfo(&buffer, _("tablespace %s"), tblspace);
3806 break;
3807 }
3808
3810 {
3812
3814 missing_ok);
3815 if (fdw)
3816 appendStringInfo(&buffer, _("foreign-data wrapper %s"), fdw->fdwname);
3817 break;
3818 }
3819
3821 {
3823
3824 srv = GetForeignServerExtended(object->objectId, missing_ok);
3825 if (srv)
3826 appendStringInfo(&buffer, _("server %s"), srv->servername);
3827 break;
3828 }
3829
3831 {
3832 HeapTuple tup;
3833 Oid useid;
3834 char *usename;
3837
3839 ObjectIdGetDatum(object->objectId));
3840 if (!HeapTupleIsValid(tup))
3841 {
3842 if (!missing_ok)
3843 elog(ERROR, "cache lookup failed for user mapping %u",
3844 object->objectId);
3845 break;
3846 }
3847
3849 useid = umform->umuser;
3850 srv = GetForeignServer(umform->umserver);
3851
3853
3854 if (OidIsValid(useid))
3856 else
3857 usename = "public";
3858
3859 appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
3860 srv->servername);
3861 break;
3862 }
3863
3865 {
3867 ScanKeyData skey[1];
3869 HeapTuple tup;
3871 char *rolename;
3872 char *nspname;
3873
3875
3876 ScanKeyInit(&skey[0],
3879 ObjectIdGetDatum(object->objectId));
3880
3882 true, NULL, 1, skey);
3883
3885
3886 if (!HeapTupleIsValid(tup))
3887 {
3888 if (!missing_ok)
3889 elog(ERROR, "could not find tuple for default ACL %u",
3890 object->objectId);
3891
3894 break;
3895 }
3896
3898
3899 rolename = GetUserNameFromId(defacl->defaclrole, false);
3900
3901 if (OidIsValid(defacl->defaclnamespace))
3902 nspname = get_namespace_name(defacl->defaclnamespace);
3903 else
3904 nspname = NULL;
3905
3906 switch (defacl->defaclobjtype)
3907 {
3908 case DEFACLOBJ_RELATION:
3909 if (nspname)
3910 appendStringInfo(&buffer,
3911 _("default privileges on new relations belonging to role %s in schema %s"),
3912 rolename, nspname);
3913 else
3914 appendStringInfo(&buffer,
3915 _("default privileges on new relations belonging to role %s"),
3916 rolename);
3917 break;
3918 case DEFACLOBJ_SEQUENCE:
3919 if (nspname)
3920 appendStringInfo(&buffer,
3921 _("default privileges on new sequences belonging to role %s in schema %s"),
3922 rolename, nspname);
3923 else
3924 appendStringInfo(&buffer,
3925 _("default privileges on new sequences belonging to role %s"),
3926 rolename);
3927 break;
3928 case DEFACLOBJ_FUNCTION:
3929 if (nspname)
3930 appendStringInfo(&buffer,
3931 _("default privileges on new functions belonging to role %s in schema %s"),
3932 rolename, nspname);
3933 else
3934 appendStringInfo(&buffer,
3935 _("default privileges on new functions belonging to role %s"),
3936 rolename);
3937 break;
3938 case DEFACLOBJ_TYPE:
3939 if (nspname)
3940 appendStringInfo(&buffer,
3941 _("default privileges on new types belonging to role %s in schema %s"),
3942 rolename, nspname);
3943 else
3944 appendStringInfo(&buffer,
3945 _("default privileges on new types belonging to role %s"),
3946 rolename);
3947 break;
3949 Assert(!nspname);
3950 appendStringInfo(&buffer,
3951 _("default privileges on new schemas belonging to role %s"),
3952 rolename);
3953 break;
3955 Assert(!nspname);
3956 appendStringInfo(&buffer,
3957 _("default privileges on new large objects belonging to role %s"),
3958 rolename);
3959 break;
3960 default:
3961 /* shouldn't get here */
3962 if (nspname)
3963 appendStringInfo(&buffer,
3964 _("default privileges belonging to role %s in schema %s"),
3965 rolename, nspname);
3966 else
3967 appendStringInfo(&buffer,
3968 _("default privileges belonging to role %s"),
3969 rolename);
3970 break;
3971 }
3972
3975 break;
3976 }
3977
3979 {
3980 char *extname;
3981
3982 extname = get_extension_name(object->objectId);
3983 if (!extname)
3984 {
3985 if (!missing_ok)
3986 elog(ERROR, "cache lookup failed for extension %u",
3987 object->objectId);
3988 break;
3989 }
3990 appendStringInfo(&buffer, _("extension %s"), extname);
3991 break;
3992 }
3993
3995 {
3996 HeapTuple tup;
3997
3999 ObjectIdGetDatum(object->objectId));
4000 if (!HeapTupleIsValid(tup))
4001 {
4002 if (!missing_ok)
4003 elog(ERROR, "cache lookup failed for event trigger %u",
4004 object->objectId);
4005 break;
4006 }
4007 appendStringInfo(&buffer, _("event trigger %s"),
4010 break;
4011 }
4012
4014 {
4015 HeapTuple tup;
4017 char *parname;
4018
4020 ObjectIdGetDatum(object->objectId));
4021 if (!HeapTupleIsValid(tup))
4022 {
4023 if (!missing_ok)
4024 elog(ERROR, "cache lookup failed for parameter ACL %u",
4025 object->objectId);
4026 break;
4027 }
4031 appendStringInfo(&buffer, _("parameter %s"), parname);
4033 break;
4034 }
4035
4036 case PolicyRelationId:
4037 {
4039 ScanKeyData skey[1];
4041 HeapTuple tuple;
4043 StringInfoData rel;
4044
4046
4047 ScanKeyInit(&skey[0],
4050 ObjectIdGetDatum(object->objectId));
4051
4053 true, NULL, 1, skey);
4054
4055 tuple = systable_getnext(sscan);
4056
4057 if (!HeapTupleIsValid(tuple))
4058 {
4059 if (!missing_ok)
4060 elog(ERROR, "could not find tuple for policy %u",
4061 object->objectId);
4062
4065 break;
4066 }
4067
4069
4070 initStringInfo(&rel);
4071 getRelationDescription(&rel, form_policy->polrelid, false);
4072
4073 /* translator: second %s is, e.g., "table %s" */
4074 appendStringInfo(&buffer, _("policy %s on %s"),
4075 NameStr(form_policy->polname), rel.data);
4076 pfree(rel.data);
4079 break;
4080 }
4081
4083 {
4084 HeapTuple tup;
4086
4088 if (!HeapTupleIsValid(tup))
4089 {
4090 if (!missing_ok)
4091 elog(ERROR, "cache lookup failed for property graph element %u",
4092 object->objectId);
4093 break;
4094 }
4095
4097
4098 if (pgeform->pgekind == PGEKIND_VERTEX)
4099 /* translator: followed by, e.g., "property graph %s" */
4100 appendStringInfo(&buffer, _("vertex %s of "), NameStr(pgeform->pgealias));
4101 else if (pgeform->pgekind == PGEKIND_EDGE)
4102 /* translator: followed by, e.g., "property graph %s" */
4103 appendStringInfo(&buffer, _("edge %s of "), NameStr(pgeform->pgealias));
4104 else
4105 appendStringInfo(&buffer, "??? element %s of ", NameStr(pgeform->pgealias));
4106 getRelationDescription(&buffer, pgeform->pgepgid, false);
4107
4109 break;
4110 }
4111
4113 {
4114 Relation rel;
4115 HeapTuple tuple;
4118
4120 tuple = get_catalog_object_by_oid(rel,
4122 object->objectId);
4123 if (!HeapTupleIsValid(tuple))
4124 {
4125 if (!missing_ok)
4126 elog(ERROR, "could not find tuple for element label %u", object->objectId);
4127
4129 break;
4130 }
4131
4133
4134 appendStringInfo(&buffer, _("label %s of "), get_propgraph_label_name(pgelform->pgellabelid));
4137
4139 break;
4140 }
4141
4143 {
4144 HeapTuple tuple;
4146
4148 if (!HeapTupleIsValid(tuple))
4149 {
4150 if (!missing_ok)
4151 elog(ERROR, "could not find tuple for label %u", object->objectId);
4152 break;
4153 }
4154
4156
4157 /* translator: followed by, e.g., "property graph %s" */
4158 appendStringInfo(&buffer, _("label %s of "), NameStr(pglform->pgllabel));
4159 getRelationDescription(&buffer, pglform->pglpgid, false);
4160 ReleaseSysCache(tuple);
4161 break;
4162 }
4163
4165 {
4166 Relation rel;
4167 HeapTuple tuple;
4170
4172 tuple = get_catalog_object_by_oid(rel,
4174 object->objectId);
4175 if (!HeapTupleIsValid(tuple))
4176 {
4177 if (!missing_ok)
4178 elog(ERROR, "could not find tuple for label property %u", object->objectId);
4179
4181 break;
4182 }
4183
4185
4186 appendStringInfo(&buffer, _("property %s of "), get_propgraph_property_name(plpform->plppropid));
4189
4191 break;
4192 }
4193
4195 {
4196 HeapTuple tuple;
4198
4200 if (!HeapTupleIsValid(tuple))
4201 {
4202 if (!missing_ok)
4203 elog(ERROR, "could not find tuple for property %u", object->objectId);
4204 break;
4205 }
4206
4208
4209 /* translator: followed by, e.g., "property graph %s" */
4210 appendStringInfo(&buffer, _("property %s of "), NameStr(pgpform->pgpname));
4211 getRelationDescription(&buffer, pgpform->pgppgid, false);
4212 ReleaseSysCache(tuple);
4213 break;
4214 }
4215
4217 {
4218 char *pubname = get_publication_name(object->objectId,
4219 missing_ok);
4220
4221 if (pubname)
4222 appendStringInfo(&buffer, _("publication %s"), pubname);
4223 break;
4224 }
4225
4227 {
4228 char *pubname;
4229 char *nspname;
4230
4231 if (!getPublicationSchemaInfo(object, missing_ok,
4232 &pubname, &nspname))
4233 break;
4234
4235 appendStringInfo(&buffer, _("publication of schema %s in publication %s"),
4236 nspname, pubname);
4237 pfree(pubname);
4238 pfree(nspname);
4239 break;
4240 }
4241
4243 {
4244 HeapTuple tup;
4245 char *pubname;
4247 StringInfoData rel;
4248
4250 ObjectIdGetDatum(object->objectId));
4251 if (!HeapTupleIsValid(tup))
4252 {
4253 if (!missing_ok)
4254 elog(ERROR, "cache lookup failed for publication table %u",
4255 object->objectId);
4256 break;
4257 }
4258
4260 pubname = get_publication_name(prform->prpubid, false);
4261
4262 initStringInfo(&rel);
4263 getRelationDescription(&rel, prform->prrelid, false);
4264
4265 /* translator: first %s is, e.g., "table %s" */
4266 appendStringInfo(&buffer, _("publication of %s in publication %s"),
4267 rel.data, pubname);
4268 pfree(rel.data);
4270 break;
4271 }
4272
4274 {
4275 char *subname = get_subscription_name(object->objectId,
4276 missing_ok);
4277
4278 if (subname)
4279 appendStringInfo(&buffer, _("subscription %s"), subname);
4280 break;
4281 }
4282
4284 {
4287
4289 ObjectIdGetDatum(object->objectId));
4291 {
4292 if (!missing_ok)
4293 elog(ERROR, "could not find tuple for transform %u",
4294 object->objectId);
4295 break;
4296 }
4297
4299
4300 appendStringInfo(&buffer, _("transform for %s language %s"),
4301 format_type_be(trfForm->trftype),
4302 get_language_name(trfForm->trflang, false));
4303
4305 break;
4306 }
4307
4308 default:
4309 elog(ERROR, "unsupported object class: %u", object->classId);
4310 }
4311
4312 /* an empty buffer is equivalent to no object found */
4313 if (buffer.len == 0)
4314 return NULL;
4315
4316 return buffer.data;
4317}
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:835
uint16_t uint16
Definition c.h:623
#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:4090
char * get_database_name(Oid dbid)
Definition lsyscache.c:1384
char * get_language_name(Oid langoid, bool missing_ok)
Definition lsyscache.c:1405
char * get_propgraph_label_name(Oid labeloid)
Definition lsyscache.c:4072
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition lsyscache.c:1045
char * get_subscription_name(Oid subid, bool missing_ok)
Definition lsyscache.c:4048
char * get_publication_name(Oid pubid, bool missing_ok)
Definition lsyscache.c:3998
char * get_namespace_name(Oid nspid)
Definition lsyscache.c:3674
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 appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230
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(), appendStringInfoString(), 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 4323 of file objectaddress.c.

4324{
4325 ObjectAddress address;
4326
4327 address.classId = classid;
4328 address.objectId = objid;
4329 address.objectSubId = 0;
4330
4331 return getObjectDescription(&address, false);
4332}

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 5103 of file objectaddress.c.

5106{
5107 StringInfoData buffer;
5108
5109 initStringInfo(&buffer);
5110
5111 /*
5112 * Make sure that both objname and objargs were passed, or none was; and
5113 * initialize them to empty lists. For objname this is useless because it
5114 * will be initialized in all cases inside the switch; but we do it anyway
5115 * so that we can test below that no branch leaves it unset.
5116 */
5117 Assert((objname != NULL) == (objargs != NULL));
5118 if (objname)
5119 {
5120 *objname = NIL;
5121 *objargs = NIL;
5122 }
5123
5124 switch (object->classId)
5125 {
5126 case RelationRelationId:
5127 {
5128 char *attr = NULL;
5129
5130 /*
5131 * Check for the attribute first, so as if it is missing we
5132 * can skip the entire relation description.
5133 */
5134 if (object->objectSubId != 0)
5135 {
5136 attr = get_attname(object->objectId,
5137 object->objectSubId,
5138 missing_ok);
5139
5140 if (missing_ok && attr == NULL)
5141 break;
5142 }
5143
5144 getRelationIdentity(&buffer, object->objectId, objname,
5145 missing_ok);
5146 if (objname && *objname == NIL)
5147 break;
5148
5149 if (attr)
5150 {
5151 appendStringInfo(&buffer, ".%s",
5152 quote_identifier(attr));
5153 if (objname)
5154 *objname = lappend(*objname, attr);
5155 }
5156 }
5157 break;
5158
5160 {
5163 flags);
5164
5165 if (proname == NULL)
5166 break;
5167
5169 if (objname)
5170 format_procedure_parts(object->objectId, objname, objargs,
5171 missing_ok);
5172 break;
5173 }
5174
5175 case TypeRelationId:
5176 {
5178 char *typeout;
5179
5180 typeout = format_type_extended(object->objectId, -1, flags);
5181
5182 if (typeout == NULL)
5183 break;
5184
5186 if (objname)
5187 *objname = list_make1(typeout);
5188 }
5189 break;
5190
5191 case CastRelationId:
5192 {
5194 HeapTuple tup;
5196
5198
5200 object->objectId);
5201
5202 if (!HeapTupleIsValid(tup))
5203 {
5204 if (!missing_ok)
5205 elog(ERROR, "could not find tuple for cast %u",
5206 object->objectId);
5207
5209 break;
5210 }
5211
5213
5214 appendStringInfo(&buffer, "(%s AS %s)",
5216 format_type_be_qualified(castForm->casttarget));
5217
5218 if (objname)
5219 {
5220 *objname = list_make1(format_type_be_qualified(castForm->castsource));
5221 *objargs = list_make1(format_type_be_qualified(castForm->casttarget));
5222 }
5223
5225 break;
5226 }
5227
5229 {
5231 Form_pg_collation coll;
5232 char *schema;
5233
5235 ObjectIdGetDatum(object->objectId));
5237 {
5238 if (!missing_ok)
5239 elog(ERROR, "cache lookup failed for collation %u",
5240 object->objectId);
5241 break;
5242 }
5244 schema = get_namespace_name_or_temp(coll->collnamespace);
5245 appendStringInfoString(&buffer,
5247 NameStr(coll->collname)));
5248 if (objname)
5249 *objname = list_make2(schema,
5250 pstrdup(NameStr(coll->collname)));
5252 break;
5253 }
5254
5256 {
5259
5261 ObjectIdGetDatum(object->objectId));
5263 {
5264 if (!missing_ok)
5265 elog(ERROR, "cache lookup failed for constraint %u",
5266 object->objectId);
5267 break;
5268 }
5270
5271 if (OidIsValid(con->conrelid))
5272 {
5273 appendStringInfo(&buffer, "%s on ",
5274 quote_identifier(NameStr(con->conname)));
5275 getRelationIdentity(&buffer, con->conrelid, objname,
5276 false);
5277 if (objname)
5278 *objname = lappend(*objname, pstrdup(NameStr(con->conname)));
5279 }
5280 else
5281 {
5282 ObjectAddress domain;
5283
5284 Assert(OidIsValid(con->contypid));
5285 domain.classId = TypeRelationId;
5286 domain.objectId = con->contypid;
5287 domain.objectSubId = 0;
5288
5289 appendStringInfo(&buffer, "%s on %s",
5290 quote_identifier(NameStr(con->conname)),
5291 getObjectIdentityParts(&domain, objname,
5292 objargs, false));
5293
5294 if (objname)
5295 *objargs = lappend(*objargs, pstrdup(NameStr(con->conname)));
5296 }
5297
5299 break;
5300 }
5301
5303 {
5306 char *schema;
5307
5309 ObjectIdGetDatum(object->objectId));
5311 {
5312 if (!missing_ok)
5313 elog(ERROR, "cache lookup failed for conversion %u",
5314 object->objectId);
5315 break;
5316 }
5318 schema = get_namespace_name_or_temp(conForm->connamespace);
5319 appendStringInfoString(&buffer,
5321 NameStr(conForm->conname)));
5322 if (objname)
5323 *objname = list_make2(schema,
5324 pstrdup(NameStr(conForm->conname)));
5326 break;
5327 }
5328
5330 {
5332
5334
5335 if (!OidIsValid(colobject.objectId))
5336 {
5337 if (!missing_ok)
5338 elog(ERROR, "could not find tuple for attrdef %u",
5339 object->objectId);
5340 break;
5341 }
5342
5343 appendStringInfo(&buffer, "for %s",
5345 objname, objargs,
5346 false));
5347 break;
5348 }
5349
5350 case LanguageRelationId:
5351 {
5354
5356 ObjectIdGetDatum(object->objectId));
5358 {
5359 if (!missing_ok)
5360 elog(ERROR, "cache lookup failed for language %u",
5361 object->objectId);
5362 break;
5363 }
5365 appendStringInfoString(&buffer,
5366 quote_identifier(NameStr(langForm->lanname)));
5367 if (objname)
5368 *objname = list_make1(pstrdup(NameStr(langForm->lanname)));
5370 break;
5371 }
5372
5374 if (!LargeObjectExists(object->objectId))
5375 break;
5376 appendStringInfo(&buffer, "%u",
5377 object->objectId);
5378 if (objname)
5379 *objname = list_make1(psprintf("%u", object->objectId));
5380 break;
5381
5382 case OperatorRelationId:
5383 {
5385 char *oprname = format_operator_extended(object->objectId,
5386 flags);
5387
5388 if (oprname == NULL)
5389 break;
5390
5391 appendStringInfoString(&buffer, oprname);
5392 if (objname)
5393 format_operator_parts(object->objectId, objname, objargs, missing_ok);
5394 break;
5395 }
5396
5398 {
5403 char *schema;
5404
5406 ObjectIdGetDatum(object->objectId));
5408 {
5409 if (!missing_ok)
5410 elog(ERROR, "cache lookup failed for opclass %u",
5411 object->objectId);
5412 break;
5413 }
5415 schema = get_namespace_name_or_temp(opcForm->opcnamespace);
5416
5418 ObjectIdGetDatum(opcForm->opcmethod));
5419 if (!HeapTupleIsValid(amTup))
5420 elog(ERROR, "cache lookup failed for access method %u",
5421 opcForm->opcmethod);
5423
5424 appendStringInfo(&buffer, "%s USING %s",
5426 NameStr(opcForm->opcname)),
5427 quote_identifier(NameStr(amForm->amname)));
5428 if (objname)
5429 *objname = list_make3(pstrdup(NameStr(amForm->amname)),
5430 schema,
5431 pstrdup(NameStr(opcForm->opcname)));
5432
5435 break;
5436 }
5437
5439 getOpFamilyIdentity(&buffer, object->objectId, objname,
5440 missing_ok);
5441 break;
5442
5444 {
5445 char *amname;
5446
5447 amname = get_am_name(object->objectId);
5448 if (!amname)
5449 {
5450 if (!missing_ok)
5451 elog(ERROR, "cache lookup failed for access method %u",
5452 object->objectId);
5453 break;
5454 }
5455 appendStringInfoString(&buffer, quote_identifier(amname));
5456 if (objname)
5457 *objname = list_make1(amname);
5458 }
5459 break;
5460
5462 {
5464 HeapTuple tup;
5465 ScanKeyData skey[1];
5468 StringInfoData opfam;
5469 char *ltype;
5470 char *rtype;
5471
5474
5475 ScanKeyInit(&skey[0],
5478 ObjectIdGetDatum(object->objectId));
5479
5481 NULL, 1, skey);
5482
5484
5485 if (!HeapTupleIsValid(tup))
5486 {
5487 if (!missing_ok)
5488 elog(ERROR, "could not find tuple for amop entry %u",
5489 object->objectId);
5490
5493 break;
5494 }
5495
5497
5498 initStringInfo(&opfam);
5499 getOpFamilyIdentity(&opfam, amopForm->amopfamily, objname,
5500 false);
5501
5502 ltype = format_type_be_qualified(amopForm->amoplefttype);
5503 rtype = format_type_be_qualified(amopForm->amoprighttype);
5504
5505 if (objname)
5506 {
5507 *objname = lappend(*objname,
5508 psprintf("%d", amopForm->amopstrategy));
5509 *objargs = list_make2(ltype, rtype);
5510 }
5511
5512 appendStringInfo(&buffer, "operator %d (%s, %s) of %s",
5513 amopForm->amopstrategy,
5514 ltype, rtype, opfam.data);
5515
5516 pfree(opfam.data);
5517
5520 break;
5521 }
5522
5524 {
5526 ScanKeyData skey[1];
5528 HeapTuple tup;
5530 StringInfoData opfam;
5531 char *ltype;
5532 char *rtype;
5533
5536
5537 ScanKeyInit(&skey[0],
5540 ObjectIdGetDatum(object->objectId));
5541
5543 NULL, 1, skey);
5544
5546
5547 if (!HeapTupleIsValid(tup))
5548 {
5549 if (!missing_ok)
5550 elog(ERROR, "could not find tuple for amproc entry %u",
5551 object->objectId);
5552
5555 break;
5556 }
5557
5559
5560 initStringInfo(&opfam);
5561 getOpFamilyIdentity(&opfam, amprocForm->amprocfamily, objname,
5562 false);
5563
5564 ltype = format_type_be_qualified(amprocForm->amproclefttype);
5565 rtype = format_type_be_qualified(amprocForm->amprocrighttype);
5566
5567 if (objname)
5568 {
5569 *objname = lappend(*objname,
5570 psprintf("%d", amprocForm->amprocnum));
5571 *objargs = list_make2(ltype, rtype);
5572 }
5573
5574 appendStringInfo(&buffer, "function %d (%s, %s) of %s",
5575 amprocForm->amprocnum,
5576 ltype, rtype, opfam.data);
5577
5578 pfree(opfam.data);
5579
5582 break;
5583 }
5584
5585 case RewriteRelationId:
5586 {
5588 HeapTuple tup;
5590
5592
5594 object->objectId);
5595
5596 if (!HeapTupleIsValid(tup))
5597 {
5598 if (!missing_ok)
5599 elog(ERROR, "could not find tuple for rule %u",
5600 object->objectId);
5601
5603 break;
5604 }
5605
5607
5608 appendStringInfo(&buffer, "%s on ",
5609 quote_identifier(NameStr(rule->rulename)));
5610 getRelationIdentity(&buffer, rule->ev_class, objname, false);
5611 if (objname)
5612 *objname = lappend(*objname, pstrdup(NameStr(rule->rulename)));
5613
5615 break;
5616 }
5617
5618 case TriggerRelationId:
5619 {
5621 HeapTuple tup;
5623
5625
5627 object->objectId);
5628
5629 if (!HeapTupleIsValid(tup))
5630 {
5631 if (!missing_ok)
5632 elog(ERROR, "could not find tuple for trigger %u",
5633 object->objectId);
5634
5636 break;
5637 }
5638
5640
5641 appendStringInfo(&buffer, "%s on ",
5642 quote_identifier(NameStr(trig->tgname)));
5643 getRelationIdentity(&buffer, trig->tgrelid, objname, false);
5644 if (objname)
5645 *objname = lappend(*objname, pstrdup(NameStr(trig->tgname)));
5646
5648 break;
5649 }
5650
5652 {
5653 char *nspname;
5654
5655 nspname = get_namespace_name_or_temp(object->objectId);
5656 if (!nspname)
5657 {
5658 if (!missing_ok)
5659 elog(ERROR, "cache lookup failed for namespace %u",
5660 object->objectId);
5661 break;
5662 }
5663 appendStringInfoString(&buffer,
5664 quote_identifier(nspname));
5665 if (objname)
5666 *objname = list_make1(nspname);
5667 break;
5668 }
5669
5671 {
5672 HeapTuple tup;
5674 char *schema;
5675
5677 ObjectIdGetDatum(object->objectId));
5678 if (!HeapTupleIsValid(tup))
5679 {
5680 if (!missing_ok)
5681 elog(ERROR, "cache lookup failed for statistics object %u",
5682 object->objectId);
5683 break;
5684 }
5686 schema = get_namespace_name_or_temp(formStatistic->stxnamespace);
5687 appendStringInfoString(&buffer,
5689 NameStr(formStatistic->stxname)));
5690 if (objname)
5691 *objname = list_make2(schema,
5692 pstrdup(NameStr(formStatistic->stxname)));
5694 }
5695 break;
5696
5697 case TSParserRelationId:
5698 {
5699 HeapTuple tup;
5701 char *schema;
5702
5704 ObjectIdGetDatum(object->objectId));
5705 if (!HeapTupleIsValid(tup))
5706 {
5707 if (!missing_ok)
5708 elog(ERROR, "cache lookup failed for text search parser %u",
5709 object->objectId);
5710 break;
5711 }
5713 schema = get_namespace_name_or_temp(formParser->prsnamespace);
5714 appendStringInfoString(&buffer,
5716 NameStr(formParser->prsname)));
5717 if (objname)
5718 *objname = list_make2(schema,
5719 pstrdup(NameStr(formParser->prsname)));
5721 break;
5722 }
5723
5725 {
5726 HeapTuple tup;
5728 char *schema;
5729
5731 ObjectIdGetDatum(object->objectId));
5732 if (!HeapTupleIsValid(tup))
5733 {
5734 if (!missing_ok)
5735 elog(ERROR, "cache lookup failed for text search dictionary %u",
5736 object->objectId);
5737 break;
5738 }
5740 schema = get_namespace_name_or_temp(formDict->dictnamespace);
5741 appendStringInfoString(&buffer,
5743 NameStr(formDict->dictname)));
5744 if (objname)
5745 *objname = list_make2(schema,
5746 pstrdup(NameStr(formDict->dictname)));
5748 break;
5749 }
5750
5752 {
5753 HeapTuple tup;
5755 char *schema;
5756
5758 ObjectIdGetDatum(object->objectId));
5759 if (!HeapTupleIsValid(tup))
5760 {
5761 if (!missing_ok)
5762 elog(ERROR, "cache lookup failed for text search template %u",
5763 object->objectId);
5764 break;
5765 }
5767 schema = get_namespace_name_or_temp(formTmpl->tmplnamespace);
5768 appendStringInfoString(&buffer,
5770 NameStr(formTmpl->tmplname)));
5771 if (objname)
5772 *objname = list_make2(schema,
5773 pstrdup(NameStr(formTmpl->tmplname)));
5775 break;
5776 }
5777
5778 case TSConfigRelationId:
5779 {
5780 HeapTuple tup;
5782 char *schema;
5783
5785 ObjectIdGetDatum(object->objectId));
5786 if (!HeapTupleIsValid(tup))
5787 {
5788 if (!missing_ok)
5789 elog(ERROR, "cache lookup failed for text search configuration %u",
5790 object->objectId);
5791 break;
5792 }
5794 schema = get_namespace_name_or_temp(formCfg->cfgnamespace);
5795 appendStringInfoString(&buffer,
5797 NameStr(formCfg->cfgname)));
5798 if (objname)
5799 *objname = list_make2(schema,
5800 pstrdup(NameStr(formCfg->cfgname)));
5802 break;
5803 }
5804
5805 case AuthIdRelationId:
5806 {
5807 char *username;
5808
5809 username = GetUserNameFromId(object->objectId, missing_ok);
5810 if (!username)
5811 break;
5812 if (objname)
5813 *objname = list_make1(username);
5814 appendStringInfoString(&buffer,
5816 break;
5817 }
5818
5819 case AuthMemRelationId:
5820 {
5822 ScanKeyData skey[1];
5824 HeapTuple tup;
5826
5829
5830 ScanKeyInit(&skey[0],
5833 ObjectIdGetDatum(object->objectId));
5834
5836 NULL, 1, skey);
5837
5839
5840 if (!HeapTupleIsValid(tup))
5841 {
5842 if (!missing_ok)
5843 elog(ERROR, "could not find tuple for pg_auth_members entry %u",
5844 object->objectId);
5845
5848 break;
5849 }
5850
5852
5853 appendStringInfo(&buffer, "membership of role %s in role %s",
5854 GetUserNameFromId(amForm->member, false),
5855 GetUserNameFromId(amForm->roleid, false));
5856
5859 break;
5860 }
5861
5862 case DatabaseRelationId:
5863 {
5864 char *datname;
5865
5867 if (!datname)
5868 {
5869 if (!missing_ok)
5870 elog(ERROR, "cache lookup failed for database %u",
5871 object->objectId);
5872 break;
5873 }
5874 if (objname)
5875 *objname = list_make1(datname);
5876 appendStringInfoString(&buffer,
5878 break;
5879 }
5880
5882 {
5883 char *tblspace;
5884
5886 if (!tblspace)
5887 {
5888 if (!missing_ok)
5889 elog(ERROR, "cache lookup failed for tablespace %u",
5890 object->objectId);
5891 break;
5892 }
5893 if (objname)
5894 *objname = list_make1(tblspace);
5895 appendStringInfoString(&buffer,
5897 break;
5898 }
5899
5901 {
5903
5905 missing_ok);
5906 if (fdw)
5907 {
5908 appendStringInfoString(&buffer, quote_identifier(fdw->fdwname));
5909 if (objname)
5910 *objname = list_make1(pstrdup(fdw->fdwname));
5911 }
5912 break;
5913 }
5914
5916 {
5918
5920 missing_ok);
5921 if (srv)
5922 {
5923 appendStringInfoString(&buffer,
5924 quote_identifier(srv->servername));
5925 if (objname)
5926 *objname = list_make1(pstrdup(srv->servername));
5927 }
5928 break;
5929 }
5930
5932 {
5933 HeapTuple tup;
5934 Oid useid;
5937 const char *usename;
5938
5940 ObjectIdGetDatum(object->objectId));
5941 if (!HeapTupleIsValid(tup))
5942 {
5943 if (!missing_ok)
5944 elog(ERROR, "cache lookup failed for user mapping %u",
5945 object->objectId);
5946 break;
5947 }
5949 useid = umform->umuser;
5950 srv = GetForeignServer(umform->umserver);
5951
5953
5954 if (OidIsValid(useid))
5956 else
5957 usename = "public";
5958
5959 if (objname)
5960 {
5961 *objname = list_make1(pstrdup(usename));
5962 *objargs = list_make1(pstrdup(srv->servername));
5963 }
5964
5965 appendStringInfo(&buffer, "%s on server %s",
5967 srv->servername);
5968 break;
5969 }
5970
5972 {
5974 ScanKeyData skey[1];
5976 HeapTuple tup;
5978 char *schema;
5979 char *username;
5980
5982
5983 ScanKeyInit(&skey[0],
5986 ObjectIdGetDatum(object->objectId));
5987
5989 true, NULL, 1, skey);
5990
5992
5993 if (!HeapTupleIsValid(tup))
5994 {
5995 if (!missing_ok)
5996 elog(ERROR, "could not find tuple for default ACL %u",
5997 object->objectId);
5998
6001 break;
6002 }
6003
6005
6006 username = GetUserNameFromId(defacl->defaclrole, false);
6007 appendStringInfo(&buffer,
6008 "for role %s",
6010
6011 if (OidIsValid(defacl->defaclnamespace))
6012 {
6013 schema = get_namespace_name_or_temp(defacl->defaclnamespace);
6014 appendStringInfo(&buffer,
6015 " in schema %s",
6016 quote_identifier(schema));
6017 }
6018 else
6019 schema = NULL;
6020
6021 switch (defacl->defaclobjtype)
6022 {
6023 case DEFACLOBJ_RELATION:
6024 appendStringInfoString(&buffer,
6025 " on tables");
6026 break;
6027 case DEFACLOBJ_SEQUENCE:
6028 appendStringInfoString(&buffer,
6029 " on sequences");
6030 break;
6031 case DEFACLOBJ_FUNCTION:
6032 appendStringInfoString(&buffer,
6033 " on functions");
6034 break;
6035 case DEFACLOBJ_TYPE:
6036 appendStringInfoString(&buffer,
6037 " on types");
6038 break;
6040 appendStringInfoString(&buffer,
6041 " on schemas");
6042 break;
6044 appendStringInfoString(&buffer,
6045 " on large objects");
6046 break;
6047 }
6048
6049 if (objname)
6050 {
6051 *objname = list_make1(username);
6052 if (schema)
6053 *objname = lappend(*objname, schema);
6054 *objargs = list_make1(psprintf("%c", defacl->defaclobjtype));
6055 }
6056
6059 break;
6060 }
6061
6063 {
6064 char *extname;
6065
6066 extname = get_extension_name(object->objectId);
6067 if (!extname)
6068 {
6069 if (!missing_ok)
6070 elog(ERROR, "cache lookup failed for extension %u",
6071 object->objectId);
6072 break;
6073 }
6074 appendStringInfoString(&buffer, quote_identifier(extname));
6075 if (objname)
6076 *objname = list_make1(extname);
6077 break;
6078 }
6079
6081 {
6082 HeapTuple tup;
6084 char *evtname;
6085
6087 ObjectIdGetDatum(object->objectId));
6088 if (!HeapTupleIsValid(tup))
6089 {
6090 if (!missing_ok)
6091 elog(ERROR, "cache lookup failed for event trigger %u",
6092 object->objectId);
6093 break;
6094 }
6096 evtname = pstrdup(NameStr(trigForm->evtname));
6097 appendStringInfoString(&buffer, quote_identifier(evtname));
6098 if (objname)
6099 *objname = list_make1(evtname);
6101 break;
6102 }
6103
6105 {
6106 HeapTuple tup;
6108 char *parname;
6109
6111 ObjectIdGetDatum(object->objectId));
6112 if (!HeapTupleIsValid(tup))
6113 {
6114 if (!missing_ok)
6115 elog(ERROR, "cache lookup failed for parameter ACL %u",
6116 object->objectId);
6117 break;
6118 }
6123 if (objname)
6124 *objname = list_make1(parname);
6126 break;
6127 }
6128
6129 case PolicyRelationId:
6130 {
6132 HeapTuple tup;
6134
6136
6138 object->objectId);
6139
6140 if (!HeapTupleIsValid(tup))
6141 {
6142 if (!missing_ok)
6143 elog(ERROR, "could not find tuple for policy %u",
6144 object->objectId);
6145
6147 break;
6148 }
6149
6151
6152 appendStringInfo(&buffer, "%s on ",
6153 quote_identifier(NameStr(policy->polname)));
6154 getRelationIdentity(&buffer, policy->polrelid, objname, false);
6155 if (objname)
6156 *objname = lappend(*objname, pstrdup(NameStr(policy->polname)));
6157
6159 break;
6160 }
6161
6163 {
6164 HeapTuple tup;
6166
6168 if (!HeapTupleIsValid(tup))
6169 {
6170 if (!missing_ok)
6171 elog(ERROR, "cache lookup failed for property graph element %u", object->objectId);
6172 break;
6173 }
6175 appendStringInfo(&buffer, "%s of ", quote_identifier(NameStr(pge->pgealias)));
6176
6177 getRelationIdentity(&buffer, pge->pgepgid, objname, false);
6178 if (objname)
6179 *objname = lappend(*objname, pstrdup(NameStr(pge->pgealias)));
6180
6182 break;
6183 }
6184
6186 {
6187 HeapTuple tup;
6189
6191 if (!HeapTupleIsValid(tup))
6192 {
6193 if (!missing_ok)
6194 elog(ERROR, "cache lookup failed for property graph label %u", object->objectId);
6195 break;
6196 }
6197
6199 appendStringInfo(&buffer, "%s of ", quote_identifier(NameStr(pgl->pgllabel)));
6200 getRelationIdentity(&buffer, pgl->pglpgid, objname, false);
6201 if (objname)
6202 *objname = lappend(*objname, pstrdup(NameStr(pgl->pgllabel)));
6204 break;
6205 }
6206
6208 {
6209 HeapTuple tup;
6211
6213 if (!HeapTupleIsValid(tup))
6214 {
6215 if (!missing_ok)
6216 elog(ERROR, "cache lookup failed for property graph property %u", object->objectId);
6217 break;
6218 }
6219
6221 appendStringInfo(&buffer, "%s of ", quote_identifier(NameStr(pgp->pgpname)));
6222 getRelationIdentity(&buffer, pgp->pgppgid, objname, false);
6223 if (objname)
6224 *objname = lappend(*objname, pstrdup(NameStr(pgp->pgpname)));
6226 break;
6227 }
6228
6230 {
6232 HeapTuple tup;
6235 char *labelname;
6236
6240 object->objectId);
6241 if (!HeapTupleIsValid(tup))
6242 {
6243 if (!missing_ok)
6244 elog(ERROR, "could not find tuple for element label %u",
6245 object->objectId);
6246
6248 break;
6249 }
6250
6252
6254 appendStringInfo(&buffer, "%s of ", quote_identifier(labelname));
6257 objargs, false));
6258 /* labelname is already pstrdup'ed. */
6259 if (objname)
6260 *objname = lappend(*objname, labelname);
6261
6263 break;
6264 }
6265
6267 {
6269 HeapTuple tup;
6272 char *propname;
6273
6278 object->objectId);
6279 if (!HeapTupleIsValid(tup))
6280 {
6281 if (!missing_ok)
6282 elog(ERROR, "could not find tuple for label property %u",
6283 object->objectId);
6284
6286 break;
6287 }
6288
6290
6292 appendStringInfo(&buffer, "%s of ", quote_identifier(propname));
6295 objargs, false));
6296 /* propname is already pstrdup'ed. */
6297 if (objname)
6298 *objname = lappend(*objname, propname);
6299
6301 break;
6302 }
6303
6305 {
6306 char *pubname;
6307
6308 pubname = get_publication_name(object->objectId, missing_ok);
6309 if (pubname)
6310 {
6311 appendStringInfoString(&buffer,
6312 quote_identifier(pubname));
6313 if (objname)
6314 *objname = list_make1(pubname);
6315 }
6316 break;
6317 }
6318
6320 {
6321 char *pubname;
6322 char *nspname;
6323
6324 if (!getPublicationSchemaInfo(object, missing_ok, &pubname,
6325 &nspname))
6326 break;
6327 appendStringInfo(&buffer, "%s in publication %s",
6328 nspname, pubname);
6329
6330 if (objargs)
6331 *objargs = list_make1(pubname);
6332 else
6333 pfree(pubname);
6334
6335 if (objname)
6336 *objname = list_make1(nspname);
6337 else
6338 pfree(nspname);
6339
6340 break;
6341 }
6342
6344 {
6345 HeapTuple tup;
6346 char *pubname;
6348
6350 ObjectIdGetDatum(object->objectId));
6351 if (!HeapTupleIsValid(tup))
6352 {
6353 if (!missing_ok)
6354 elog(ERROR, "cache lookup failed for publication table %u",
6355 object->objectId);
6356 break;
6357 }
6358
6360 pubname = get_publication_name(prform->prpubid, false);
6361
6362 getRelationIdentity(&buffer, prform->prrelid, objname, false);
6363 appendStringInfo(&buffer, " in publication %s", pubname);
6364
6365 if (objargs)
6366 *objargs = list_make1(pubname);
6367
6369 break;
6370 }
6371
6373 {
6374 char *subname;
6375
6376 subname = get_subscription_name(object->objectId, missing_ok);
6377 if (subname)
6378 {
6379 appendStringInfoString(&buffer,
6381 if (objname)
6382 *objname = list_make1(subname);
6383 }
6384 break;
6385 }
6386
6388 {
6390 HeapTuple tup;
6391 Form_pg_transform transform;
6392 char *transformLang;
6393 char *transformType;
6394
6396
6399 object->objectId);
6400
6401 if (!HeapTupleIsValid(tup))
6402 {
6403 if (!missing_ok)
6404 elog(ERROR, "could not find tuple for transform %u",
6405 object->objectId);
6406
6408 break;
6409 }
6410
6411 transform = (Form_pg_transform) GETSTRUCT(tup);
6412
6413 transformType = format_type_be_qualified(transform->trftype);
6414 transformLang = get_language_name(transform->trflang, false);
6415
6416 appendStringInfo(&buffer, "for %s language %s",
6419 if (objname)
6420 {
6421 *objname = list_make1(transformType);
6422 *objargs = list_make1(pstrdup(transformLang));
6423 }
6424
6426 }
6427 break;
6428
6429 default:
6430 elog(ERROR, "unsupported object class: %u", object->classId);
6431 }
6432
6433 if (!missing_ok)
6434 {
6435 /*
6436 * If a get_object_address() representation was requested, make sure
6437 * we are providing one. We don't check objargs, because many of the
6438 * cases above leave it as NIL.
6439 */
6440 if (objname && *objname == NIL)
6441 elog(ERROR, "requested object address for unsupported object class %u: text result \"%s\"",
6442 object->classId, buffer.data);
6443 }
6444 else
6445 {
6446 /* an empty buffer is equivalent to no object found */
6447 if (buffer.len == 0)
6448 {
6449 Assert((objname == NULL || *objname == NIL) &&
6450 (objargs == NULL || *objargs == NIL));
6451 return NULL;
6452 }
6453 }
6454
6455 return buffer.data;
6456}
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:3698
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)

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 4738 of file objectaddress.c.

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

2842{
2843 int index;
2844
2845 for (index = 0; index < lengthof(ObjectProperty); index++)
2846 {
2847 if (ObjectProperty[index].class_oid == class_id)
2848 return true;
2849 }
2850
2851 return false;
2852}
#define lengthof(array)
Definition c.h:873
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 int i;
2715
2716 for (i = 0; i < lengthof(ObjectTypeMap); i++)
2717 {
2718 if (strcmp(ObjectTypeMap[i].tm_name, objtype) == 0)
2719 return ObjectTypeMap[i].tm_type;
2720 }
2721 ereport(ERROR,
2723 errmsg("unrecognized object type \"%s\"", objtype)));
2724
2725 return -1; /* keep compiler quiet */
2726}
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 6537 of file objectaddress.c.

6538{
6539 ArrayType *arr;
6540 Datum *datums;
6541 bool *nulls;
6542 int j = 0;
6543 ListCell *cell;
6544 MemoryContext memcxt;
6546 int lb[1];
6547
6548 /* Work in a temp context; easier than individually pfree'ing the Datums */
6550 "strlist to array",
6552 oldcxt = MemoryContextSwitchTo(memcxt);
6553
6554 datums = palloc_array(Datum, list_length(list));
6555 nulls = palloc_array(bool, list_length(list));
6556
6557 foreach(cell, list)
6558 {
6559 char *name = lfirst(cell);
6560
6561 if (name)
6562 {
6563 nulls[j] = false;
6564 datums[j++] = CStringGetTextDatum(name);
6565 }
6566 else
6567 nulls[j] = true;
6568 }
6569
6571
6572 lb[0] = 1;
6573 arr = construct_md_array(datums, nulls, 1, &j,
6574 lb, TEXTOID, -1, false, TYPALIGN_INT);
6575
6576 MemoryContextDelete(memcxt);
6577
6578 return arr;
6579}
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