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

2489{
2490 switch (objtype)
2491 {
2492 case OBJECT_INDEX:
2493 case OBJECT_SEQUENCE:
2494 case OBJECT_TABLE:
2495 case OBJECT_VIEW:
2496 case OBJECT_MATVIEW:
2498 case OBJECT_PROPGRAPH:
2499 case OBJECT_COLUMN:
2500 case OBJECT_RULE:
2501 case OBJECT_TRIGGER:
2502 case OBJECT_POLICY:
2504 if (!object_ownercheck(RelationRelationId, RelationGetRelid(relation), roleid))
2506 RelationGetRelationName(relation));
2507 break;
2508 case OBJECT_TYPE:
2509 case OBJECT_DOMAIN:
2510 case OBJECT_ATTRIBUTE:
2511 if (!object_ownercheck(address.classId, address.objectId, roleid))
2513 break;
2515 {
2516 HeapTuple tuple;
2517 Oid contypid;
2518
2519 tuple = SearchSysCache1(CONSTROID,
2520 ObjectIdGetDatum(address.objectId));
2521 if (!HeapTupleIsValid(tuple))
2522 elog(ERROR, "constraint with OID %u does not exist",
2523 address.objectId);
2524
2526
2527 ReleaseSysCache(tuple);
2528
2529 /*
2530 * Fallback to type ownership check in this case as this is
2531 * what domain constraints rely on.
2532 */
2535 }
2536 break;
2537 case OBJECT_AGGREGATE:
2538 case OBJECT_FUNCTION:
2539 case OBJECT_PROCEDURE:
2540 case OBJECT_ROUTINE:
2541 case OBJECT_OPERATOR:
2542 if (!object_ownercheck(address.classId, address.objectId, roleid))
2544 NameListToString((castNode(ObjectWithArgs, object))->objname));
2545 break;
2546 case OBJECT_DATABASE:
2548 case OBJECT_EXTENSION:
2549 case OBJECT_FDW:
2551 case OBJECT_LANGUAGE:
2552 case OBJECT_PUBLICATION:
2553 case OBJECT_SCHEMA:
2555 case OBJECT_TABLESPACE:
2556 if (!object_ownercheck(address.classId, address.objectId, roleid))
2558 strVal(object));
2559 break;
2560 case OBJECT_COLLATION:
2561 case OBJECT_CONVERSION:
2562 case OBJECT_OPCLASS:
2563 case OBJECT_OPFAMILY:
2567 if (!object_ownercheck(address.classId, address.objectId, roleid))
2569 NameListToString(castNode(List, object)));
2570 break;
2571 case OBJECT_LARGEOBJECT:
2572 if (!lo_compat_privileges &&
2573 !object_ownercheck(address.classId, address.objectId, roleid))
2574 ereport(ERROR,
2576 errmsg("must be owner of large object %u",
2577 address.objectId)));
2578 break;
2579 case OBJECT_CAST:
2580 {
2581 /* We can only check permissions on the source/target types */
2582 TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2583 TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2584 Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2585 Oid targettypeid = typenameTypeId(NULL, targettype);
2586
2589 ereport(ERROR,
2591 errmsg("must be owner of type %s or type %s",
2594 }
2595 break;
2596 case OBJECT_TRANSFORM:
2597 {
2598 TypeName *typename = linitial_node(TypeName, castNode(List, object));
2599 Oid typeid = typenameTypeId(NULL, typename);
2600
2601 if (!object_ownercheck(TypeRelationId, typeid, roleid))
2603 }
2604 break;
2605 case OBJECT_ROLE:
2606
2607 /*
2608 * We treat roles as being "owned" by those with CREATEROLE priv,
2609 * provided that they also have admin option on the role.
2610 *
2611 * However, superusers are only owned by superusers.
2612 */
2613 if (superuser_arg(address.objectId))
2614 {
2615 if (!superuser_arg(roleid))
2616 ereport(ERROR,
2618 errmsg("permission denied"),
2619 errdetail("The current user must have the %s attribute.",
2620 "SUPERUSER")));
2621 }
2622 else
2623 {
2624 if (!has_createrole_privilege(roleid))
2625 ereport(ERROR,
2627 errmsg("permission denied"),
2628 errdetail("The current user must have the %s attribute.",
2629 "CREATEROLE")));
2630 if (!is_admin_of_role(roleid, address.objectId))
2631 ereport(ERROR,
2633 errmsg("permission denied"),
2634 errdetail("The current user must have the %s option on role \"%s\".",
2635 "ADMIN",
2637 true))));
2638 }
2639 break;
2640 case OBJECT_TSPARSER:
2641 case OBJECT_TSTEMPLATE:
2644 /* We treat these object types as being owned by superusers */
2645 if (!superuser_arg(roleid))
2646 ereport(ERROR,
2648 errmsg("must be superuser")));
2649 break;
2650 case OBJECT_AMOP:
2651 case OBJECT_AMPROC:
2652 case OBJECT_DEFAULT:
2653 case OBJECT_DEFACL:
2657 /* These are currently not supported or don't make sense here. */
2658 elog(ERROR, "unsupported object type: %d", (int) objtype);
2659 break;
2660 }
2661}
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 2887 of file objectaddress.c.

2888{
2889 return
2891}
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 2900 of file objectaddress.c.

2904{
2905 HeapTuple tuple;
2906 Oid classId = RelationGetRelid(catalog);
2908
2909 if (oidCacheId >= 0)
2910 {
2911 if (locktup)
2913 ObjectIdGetDatum(objectId));
2914 else
2916 ObjectIdGetDatum(objectId));
2917 if (!HeapTupleIsValid(tuple)) /* should not happen */
2918 return NULL;
2919 }
2920 else
2921 {
2923 SysScanDesc scan;
2925
2927
2929 oidcol,
2931 ObjectIdGetDatum(objectId));
2932
2934 NULL, 1, &skey);
2935 tuple = systable_getnext(scan);
2936 if (!HeapTupleIsValid(tuple))
2937 {
2938 systable_endscan(scan);
2939 return NULL;
2940 }
2941
2942 if (locktup)
2944
2945 tuple = heap_copytuple(tuple);
2946
2947 systable_endscan(scan);
2948 }
2949
2950 return tuple;
2951}
#define Assert(condition)
Definition c.h:943
#define OidIsValid(objectId)
Definition c.h:858
void systable_endscan(SysScanDesc sysscan)
Definition genam.c:612
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition genam.c:523
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 1010 of file objectaddress.c.

1012{
1013 ObjectAddress address = {InvalidOid, InvalidOid, 0};
1015 Relation relation = NULL;
1017
1018 /* Some kind of lock must be taken. */
1019 Assert(lockmode != NoLock);
1020
1021 for (;;)
1022 {
1023 /*
1024 * Remember this value, so that, after looking up the object name and
1025 * locking it, we can check whether any invalidation messages have
1026 * been processed that might require a do-over.
1027 */
1029
1030 /* Look up object address. */
1031 switch (objtype)
1032 {
1033 case OBJECT_INDEX:
1034 case OBJECT_SEQUENCE:
1035 case OBJECT_TABLE:
1036 case OBJECT_VIEW:
1037 case OBJECT_MATVIEW:
1039 case OBJECT_PROPGRAPH:
1040 address =
1042 &relation, lockmode,
1043 missing_ok);
1044 break;
1045 case OBJECT_ATTRIBUTE:
1046 case OBJECT_COLUMN:
1047 address =
1048 get_object_address_attribute(objtype, castNode(List, object),
1049 &relation, lockmode,
1050 missing_ok);
1051 break;
1052 case OBJECT_DEFAULT:
1053 address =
1054 get_object_address_attrdef(objtype, castNode(List, object),
1055 &relation, lockmode,
1056 missing_ok);
1057 break;
1058 case OBJECT_RULE:
1059 case OBJECT_TRIGGER:
1061 case OBJECT_POLICY:
1062 address = get_object_address_relobject(objtype, castNode(List, object),
1063 &relation, missing_ok);
1064 break;
1066 {
1067 List *objlist;
1069 char *constrname;
1070
1071 objlist = castNode(List, object);
1074 missing_ok);
1076
1077 address.classId = ConstraintRelationId;
1078 address.objectId = get_domain_constraint_oid(domaddr.objectId,
1079 constrname, missing_ok);
1080 address.objectSubId = 0;
1081 }
1082 break;
1083 case OBJECT_DATABASE:
1084 case OBJECT_EXTENSION:
1085 case OBJECT_TABLESPACE:
1086 case OBJECT_ROLE:
1087 case OBJECT_SCHEMA:
1088 case OBJECT_LANGUAGE:
1089 case OBJECT_FDW:
1094 case OBJECT_PUBLICATION:
1096 address = get_object_address_unqualified(objtype,
1097 castNode(String, object), missing_ok);
1098 break;
1099 case OBJECT_TYPE:
1100 case OBJECT_DOMAIN:
1101 address = get_object_address_type(objtype, castNode(TypeName, object), missing_ok);
1102 break;
1103 case OBJECT_AGGREGATE:
1104 case OBJECT_FUNCTION:
1105 case OBJECT_PROCEDURE:
1106 case OBJECT_ROUTINE:
1107 address.classId = ProcedureRelationId;
1108 address.objectId = LookupFuncWithArgs(objtype, castNode(ObjectWithArgs, object), missing_ok);
1109 address.objectSubId = 0;
1110 break;
1111 case OBJECT_OPERATOR:
1112 address.classId = OperatorRelationId;
1113 address.objectId = LookupOperWithArgs(castNode(ObjectWithArgs, object), missing_ok);
1114 address.objectSubId = 0;
1115 break;
1116 case OBJECT_COLLATION:
1117 address.classId = CollationRelationId;
1118 address.objectId = get_collation_oid(castNode(List, object), missing_ok);
1119 address.objectSubId = 0;
1120 break;
1121 case OBJECT_CONVERSION:
1122 address.classId = ConversionRelationId;
1123 address.objectId = get_conversion_oid(castNode(List, object), missing_ok);
1124 address.objectSubId = 0;
1125 break;
1126 case OBJECT_OPCLASS:
1127 case OBJECT_OPFAMILY:
1128 address = get_object_address_opcf(objtype, castNode(List, object), missing_ok);
1129 break;
1130 case OBJECT_AMOP:
1131 case OBJECT_AMPROC:
1132 address = get_object_address_opf_member(objtype, castNode(List, object), missing_ok);
1133 break;
1134 case OBJECT_LARGEOBJECT:
1136 address.objectId = oidparse(object);
1137 address.objectSubId = 0;
1138 if (!LargeObjectExists(address.objectId))
1139 {
1140 if (!missing_ok)
1141 ereport(ERROR,
1143 errmsg("large object %u does not exist",
1144 address.objectId)));
1145 }
1146 break;
1147 case OBJECT_CAST:
1148 {
1149 TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
1150 TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
1153
1154 sourcetypeid = LookupTypeNameOid(NULL, sourcetype, missing_ok);
1155 targettypeid = LookupTypeNameOid(NULL, targettype, missing_ok);
1156 address.classId = CastRelationId;
1157 address.objectId =
1159 address.objectSubId = 0;
1160 }
1161 break;
1162 case OBJECT_TRANSFORM:
1163 {
1164 TypeName *typename = linitial_node(TypeName, castNode(List, object));
1165 char *langname = strVal(lsecond(castNode(List, object)));
1166 Oid type_id = LookupTypeNameOid(NULL, typename, missing_ok);
1167 Oid lang_id = get_language_oid(langname, missing_ok);
1168
1169 address.classId = TransformRelationId;
1170 address.objectId =
1171 get_transform_oid(type_id, lang_id, missing_ok);
1172 address.objectSubId = 0;
1173 }
1174 break;
1175 case OBJECT_TSPARSER:
1176 address.classId = TSParserRelationId;
1177 address.objectId = get_ts_parser_oid(castNode(List, object), missing_ok);
1178 address.objectSubId = 0;
1179 break;
1182 address.objectId = get_ts_dict_oid(castNode(List, object), missing_ok);
1183 address.objectSubId = 0;
1184 break;
1185 case OBJECT_TSTEMPLATE:
1186 address.classId = TSTemplateRelationId;
1187 address.objectId = get_ts_template_oid(castNode(List, object), missing_ok);
1188 address.objectSubId = 0;
1189 break;
1191 address.classId = TSConfigRelationId;
1192 address.objectId = get_ts_config_oid(castNode(List, object), missing_ok);
1193 address.objectSubId = 0;
1194 break;
1196 address = get_object_address_usermapping(castNode(List, object),
1197 missing_ok);
1198 break;
1201 missing_ok);
1202 break;
1205 &relation,
1206 missing_ok);
1207 break;
1208 case OBJECT_DEFACL:
1209 address = get_object_address_defacl(castNode(List, object),
1210 missing_ok);
1211 break;
1215 missing_ok);
1216 address.objectSubId = 0;
1217 break;
1218 /* no default, to let compiler warn about missing case */
1219 }
1220
1221 if (!address.classId)
1222 elog(ERROR, "unrecognized object type: %d", (int) objtype);
1223
1224 /*
1225 * If we could not find the supplied object, return without locking.
1226 */
1227 if (!OidIsValid(address.objectId))
1228 {
1229 Assert(missing_ok);
1230 return address;
1231 }
1232
1233 /*
1234 * If we're retrying, see if we got the same answer as last time. If
1235 * so, we're done; if not, we locked the wrong thing, so give up our
1236 * lock.
1237 */
1238 if (OidIsValid(old_address.classId))
1239 {
1240 if (old_address.classId == address.classId
1241 && old_address.objectId == address.objectId
1242 && old_address.objectSubId == address.objectSubId)
1243 break;
1244 if (old_address.classId != RelationRelationId)
1245 {
1246 if (IsSharedRelation(old_address.classId))
1248 old_address.objectId,
1249 0, lockmode);
1250 else
1252 old_address.objectId,
1253 0, lockmode);
1254 }
1255 }
1256
1257 /*
1258 * If we're dealing with a relation or attribute, then the relation is
1259 * already locked. Otherwise, we lock it now.
1260 */
1261 if (address.classId != RelationRelationId)
1262 {
1263 if (IsSharedRelation(address.classId))
1264 LockSharedObject(address.classId, address.objectId, 0,
1265 lockmode);
1266 else
1267 LockDatabaseObject(address.classId, address.objectId, 0,
1268 lockmode);
1269 }
1270
1271 /*
1272 * At this point, we've resolved the name to an OID and locked the
1273 * corresponding database object. However, it's possible that by the
1274 * time we acquire the lock on the object, concurrent DDL has modified
1275 * the database in such a way that the name we originally looked up no
1276 * longer resolves to that OID.
1277 *
1278 * We can be certain that this isn't an issue if (a) no shared
1279 * invalidation messages have been processed or (b) we've locked a
1280 * relation somewhere along the line. All the relation name lookups
1281 * in this module ultimately use RangeVarGetRelid() to acquire a
1282 * relation lock, and that function protects against the same kinds of
1283 * races we're worried about here. Even when operating on a
1284 * constraint, rule, or trigger, we still acquire AccessShareLock on
1285 * the relation, which is enough to freeze out any concurrent DDL.
1286 *
1287 * In all other cases, however, it's possible that the name we looked
1288 * up no longer refers to the object we locked, so we retry the lookup
1289 * and see whether we get the same answer.
1290 */
1291 if (inval_count == SharedInvalidMessageCounter || relation != NULL)
1292 break;
1293 old_address = address;
1294 }
1295
1296 /* relp must be given if it's a relation */
1297 Assert(!relation || relp);
1298
1299 /* Return the object address and the relation. */
1300 if (relp)
1301 *relp = relation;
1302 return address;
1303}
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:1164
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 1313 of file objectaddress.c.

1316{
1317 if (rel)
1318 {
1319 object = lcons(makeString(rel->relname), object);
1320 if (rel->schemaname)
1321 object = lcons(makeString(rel->schemaname), object);
1322 if (rel->catalogname)
1323 object = lcons(makeString(rel->catalogname), object);
1324 }
1325
1326 return get_object_address(objtype, (Node *) object,
1327 relp, lockmode, missing_ok);
1328}
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 2790 of file objectaddress.c.

2791{
2793
2794 return prop->attnum_acl;
2795}
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 2750 of file objectaddress.c.

2751{
2753
2754 return prop->name_catcache_id;
2755}
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()

const char * get_object_class_descr ( Oid  class_id)
extern

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

2671{
2672 SysCacheIdentifier cache;
2673 HeapTuple tuple;
2674 Oid oid;
2676
2677 /* If not owned by a namespace, just return InvalidOid. */
2678 property = get_object_property_data(address->classId);
2679 if (property->attnum_namespace == InvalidAttrNumber)
2680 return InvalidOid;
2681
2682 /* Currently, we can only handle object types with system caches. */
2683 cache = property->oid_catcache_id;
2684 Assert(cache != SYSCACHEID_INVALID);
2685
2686 /* Fetch tuple from syscache and extract namespace attribute. */
2687 tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2688 if (!HeapTupleIsValid(tuple))
2689 elog(ERROR, "cache lookup failed for cache %d oid %u",
2690 cache, address->objectId);
2692 tuple,
2693 property->attnum_namespace));
2694 ReleaseSysCache(tuple);
2695
2696 return oid;
2697}
#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 2805 of file objectaddress.c.

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

6504{
6505 switch (relkind)
6506 {
6507 case RELKIND_RELATION:
6509 return OBJECT_TABLE;
6510 case RELKIND_INDEX:
6512 return OBJECT_INDEX;
6513 case RELKIND_SEQUENCE:
6514 return OBJECT_SEQUENCE;
6515 case RELKIND_VIEW:
6516 return OBJECT_VIEW;
6517 case RELKIND_MATVIEW:
6518 return OBJECT_MATVIEW;
6520 return OBJECT_FOREIGN_TABLE;
6521 case RELKIND_PROPGRAPH:
6522 return OBJECT_PROPGRAPH;
6523 case RELKIND_TOASTVALUE:
6524 return OBJECT_TABLE;
6525 default:
6526 /* Per above, don't raise an error */
6527 return OBJECT_TABLE;
6528 }
6529}

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

3010{
3011 StringInfoData buffer;
3012
3013 initStringInfo(&buffer);
3014
3015 switch (object->classId)
3016 {
3017 case RelationRelationId:
3018 if (object->objectSubId == 0)
3019 getRelationDescription(&buffer, object->objectId, missing_ok);
3020 else
3021 {
3022 /* column, not whole relation */
3023 StringInfoData rel;
3024 char *attname = get_attname(object->objectId,
3025 object->objectSubId,
3026 missing_ok);
3027
3028 if (!attname)
3029 break;
3030
3031 initStringInfo(&rel);
3032 getRelationDescription(&rel, object->objectId, missing_ok);
3033 /* translator: second %s is, e.g., "table %s" */
3034 appendStringInfo(&buffer, _("column %s of %s"),
3035 attname, rel.data);
3036 pfree(rel.data);
3037 }
3038 break;
3039
3041 {
3044 flags);
3045
3046 if (proname == NULL)
3047 break;
3048
3049 appendStringInfo(&buffer, _("function %s"), proname);
3050 break;
3051 }
3052
3053 case TypeRelationId:
3054 {
3056 char *typname = format_type_extended(object->objectId, -1,
3057 flags);
3058
3059 if (typname == NULL)
3060 break;
3061
3062 appendStringInfo(&buffer, _("type %s"), typname);
3063 break;
3064 }
3065
3066 case CastRelationId:
3067 {
3069 ScanKeyData skey[1];
3071 HeapTuple tup;
3073
3075
3076 ScanKeyInit(&skey[0],
3079 ObjectIdGetDatum(object->objectId));
3080
3082 NULL, 1, skey);
3083
3085
3086 if (!HeapTupleIsValid(tup))
3087 {
3088 if (!missing_ok)
3089 elog(ERROR, "could not find tuple for cast %u",
3090 object->objectId);
3091
3094 break;
3095 }
3096
3098
3099 appendStringInfo(&buffer, _("cast from %s to %s"),
3100 format_type_be(castForm->castsource),
3101 format_type_be(castForm->casttarget));
3102
3105 break;
3106 }
3107
3109 {
3111 Form_pg_collation coll;
3112 char *nspname;
3113
3115 ObjectIdGetDatum(object->objectId));
3117 {
3118 if (!missing_ok)
3119 elog(ERROR, "cache lookup failed for collation %u",
3120 object->objectId);
3121 break;
3122 }
3123
3125
3126 /* Qualify the name if not visible in search path */
3127 if (CollationIsVisible(object->objectId))
3128 nspname = NULL;
3129 else
3130 nspname = get_namespace_name(coll->collnamespace);
3131
3132 appendStringInfo(&buffer, _("collation %s"),
3134 NameStr(coll->collname)));
3136 break;
3137 }
3138
3140 {
3143
3145 ObjectIdGetDatum(object->objectId));
3147 {
3148 if (!missing_ok)
3149 elog(ERROR, "cache lookup failed for constraint %u",
3150 object->objectId);
3151 break;
3152 }
3153
3155
3156 if (OidIsValid(con->conrelid))
3157 {
3158 StringInfoData rel;
3159
3160 initStringInfo(&rel);
3161 getRelationDescription(&rel, con->conrelid, false);
3162 /* translator: second %s is, e.g., "table %s" */
3163 appendStringInfo(&buffer, _("constraint %s on %s"),
3164 NameStr(con->conname), rel.data);
3165 pfree(rel.data);
3166 }
3167 else
3168 {
3169 appendStringInfo(&buffer, _("constraint %s"),
3170 NameStr(con->conname));
3171 }
3172
3174 break;
3175 }
3176
3178 {
3181 char *nspname;
3182
3184 ObjectIdGetDatum(object->objectId));
3186 {
3187 if (!missing_ok)
3188 elog(ERROR, "cache lookup failed for conversion %u",
3189 object->objectId);
3190 break;
3191 }
3192
3194
3195 /* Qualify the name if not visible in search path */
3196 if (ConversionIsVisible(object->objectId))
3197 nspname = NULL;
3198 else
3199 nspname = get_namespace_name(conv->connamespace);
3200
3201 appendStringInfo(&buffer, _("conversion %s"),
3203 NameStr(conv->conname)));
3205 break;
3206 }
3207
3209 {
3211
3213
3214 if (!OidIsValid(colobject.objectId))
3215 {
3216 if (!missing_ok)
3217 elog(ERROR, "could not find tuple for attrdef %u",
3218 object->objectId);
3219 break;
3220 }
3221
3222 /* translator: %s is typically "column %s of table %s" */
3223 appendStringInfo(&buffer, _("default value for %s"),
3225 break;
3226 }
3227
3228 case LanguageRelationId:
3229 {
3230 char *langname = get_language_name(object->objectId,
3231 missing_ok);
3232
3233 if (langname)
3234 appendStringInfo(&buffer, _("language %s"),
3235 get_language_name(object->objectId, false));
3236 break;
3237 }
3238
3240 if (!LargeObjectExists(object->objectId))
3241 break;
3242 appendStringInfo(&buffer, _("large object %u"),
3243 object->objectId);
3244 break;
3245
3246 case OperatorRelationId:
3247 {
3249 char *oprname = format_operator_extended(object->objectId,
3250 flags);
3251
3252 if (oprname == NULL)
3253 break;
3254
3255 appendStringInfo(&buffer, _("operator %s"), oprname);
3256 break;
3257 }
3258
3260 {
3265 char *nspname;
3266
3268 ObjectIdGetDatum(object->objectId));
3270 {
3271 if (!missing_ok)
3272 elog(ERROR, "cache lookup failed for opclass %u",
3273 object->objectId);
3274 break;
3275 }
3276
3278
3280 ObjectIdGetDatum(opcForm->opcmethod));
3281 if (!HeapTupleIsValid(amTup))
3282 elog(ERROR, "cache lookup failed for access method %u",
3283 opcForm->opcmethod);
3285
3286 /* Qualify the name if not visible in search path */
3287 if (OpclassIsVisible(object->objectId))
3288 nspname = NULL;
3289 else
3290 nspname = get_namespace_name(opcForm->opcnamespace);
3291
3292 appendStringInfo(&buffer, _("operator class %s for access method %s"),
3294 NameStr(opcForm->opcname)),
3295 NameStr(amForm->amname));
3296
3299 break;
3300 }
3301
3303 getOpFamilyDescription(&buffer, object->objectId, missing_ok);
3304 break;
3305
3307 {
3308 HeapTuple tup;
3309
3311 ObjectIdGetDatum(object->objectId));
3312 if (!HeapTupleIsValid(tup))
3313 {
3314 if (!missing_ok)
3315 elog(ERROR, "cache lookup failed for access method %u",
3316 object->objectId);
3317 break;
3318 }
3319
3320 appendStringInfo(&buffer, _("access method %s"),
3321 NameStr(((Form_pg_am) GETSTRUCT(tup))->amname));
3323 break;
3324 }
3325
3327 {
3329 HeapTuple tup;
3330 ScanKeyData skey[1];
3333 StringInfoData opfam;
3334
3337
3338 ScanKeyInit(&skey[0],
3341 ObjectIdGetDatum(object->objectId));
3342
3344 NULL, 1, skey);
3345
3347
3348 if (!HeapTupleIsValid(tup))
3349 {
3350 if (!missing_ok)
3351 elog(ERROR, "could not find tuple for amop entry %u",
3352 object->objectId);
3353
3356 break;
3357 }
3358
3360
3361 initStringInfo(&opfam);
3362 getOpFamilyDescription(&opfam, amopForm->amopfamily, false);
3363
3364 /*
3365 * We use FORMAT_TYPE_ALLOW_INVALID here so as not to fail
3366 * completely if the type links are dangling, which is a form
3367 * of catalog corruption that could occur due to old bugs.
3368 */
3369
3370 /*------
3371 translator: %d is the operator strategy (a number), the
3372 first two %s's are data type names, the third %s is the
3373 description of the operator family, and the last %s is the
3374 textual form of the operator with arguments. */
3375 appendStringInfo(&buffer, _("operator %d (%s, %s) of %s: %s"),
3376 amopForm->amopstrategy,
3377 format_type_extended(amopForm->amoplefttype,
3379 format_type_extended(amopForm->amoprighttype,
3381 opfam.data,
3382 format_operator(amopForm->amopopr));
3383
3384 pfree(opfam.data);
3385
3388 break;
3389 }
3390
3392 {
3394 ScanKeyData skey[1];
3396 HeapTuple tup;
3398 StringInfoData opfam;
3399
3402
3403 ScanKeyInit(&skey[0],
3406 ObjectIdGetDatum(object->objectId));
3407
3409 NULL, 1, skey);
3410
3412
3413 if (!HeapTupleIsValid(tup))
3414 {
3415 if (!missing_ok)
3416 elog(ERROR, "could not find tuple for amproc entry %u",
3417 object->objectId);
3418
3421 break;
3422 }
3423
3425
3426 initStringInfo(&opfam);
3427 getOpFamilyDescription(&opfam, amprocForm->amprocfamily, false);
3428
3429 /*
3430 * We use FORMAT_TYPE_ALLOW_INVALID here so as not to fail
3431 * completely if the type links are dangling, which is a form
3432 * of catalog corruption that could occur due to old bugs.
3433 */
3434
3435 /*------
3436 translator: %d is the function number, the first two %s's
3437 are data type names, the third %s is the description of the
3438 operator family, and the last %s is the textual form of the
3439 function with arguments. */
3440 appendStringInfo(&buffer, _("function %d (%s, %s) of %s: %s"),
3441 amprocForm->amprocnum,
3442 format_type_extended(amprocForm->amproclefttype,
3444 format_type_extended(amprocForm->amprocrighttype,
3446 opfam.data,
3447 format_procedure(amprocForm->amproc));
3448
3449 pfree(opfam.data);
3450
3453 break;
3454 }
3455
3456 case RewriteRelationId:
3457 {
3459 ScanKeyData skey[1];
3461 HeapTuple tup;
3463 StringInfoData rel;
3464
3466
3467 ScanKeyInit(&skey[0],
3470 ObjectIdGetDatum(object->objectId));
3471
3473 NULL, 1, skey);
3474
3476
3477 if (!HeapTupleIsValid(tup))
3478 {
3479 if (!missing_ok)
3480 elog(ERROR, "could not find tuple for rule %u",
3481 object->objectId);
3482
3485 break;
3486 }
3487
3489
3490 initStringInfo(&rel);
3491 getRelationDescription(&rel, rule->ev_class, false);
3492
3493 /* translator: second %s is, e.g., "table %s" */
3494 appendStringInfo(&buffer, _("rule %s on %s"),
3495 NameStr(rule->rulename), rel.data);
3496 pfree(rel.data);
3499 break;
3500 }
3501
3502 case TriggerRelationId:
3503 {
3505 ScanKeyData skey[1];
3507 HeapTuple tup;
3509 StringInfoData rel;
3510
3512
3513 ScanKeyInit(&skey[0],
3516 ObjectIdGetDatum(object->objectId));
3517
3519 NULL, 1, skey);
3520
3522
3523 if (!HeapTupleIsValid(tup))
3524 {
3525 if (!missing_ok)
3526 elog(ERROR, "could not find tuple for trigger %u",
3527 object->objectId);
3528
3531 break;
3532 }
3533
3535
3536 initStringInfo(&rel);
3537 getRelationDescription(&rel, trig->tgrelid, false);
3538
3539 /* translator: second %s is, e.g., "table %s" */
3540 appendStringInfo(&buffer, _("trigger %s on %s"),
3541 NameStr(trig->tgname), rel.data);
3542 pfree(rel.data);
3545 break;
3546 }
3547
3549 {
3550 char *nspname;
3551
3552 nspname = get_namespace_name(object->objectId);
3553 if (!nspname)
3554 {
3555 if (!missing_ok)
3556 elog(ERROR, "cache lookup failed for namespace %u",
3557 object->objectId);
3558 break;
3559 }
3560 appendStringInfo(&buffer, _("schema %s"), nspname);
3561 break;
3562 }
3563
3565 {
3568 char *nspname;
3569
3571 ObjectIdGetDatum(object->objectId));
3573 {
3574 if (!missing_ok)
3575 elog(ERROR, "could not find tuple for statistics object %u",
3576 object->objectId);
3577 break;
3578 }
3579
3581
3582 /* Qualify the name if not visible in search path */
3583 if (StatisticsObjIsVisible(object->objectId))
3584 nspname = NULL;
3585 else
3586 nspname = get_namespace_name(stxForm->stxnamespace);
3587
3588 appendStringInfo(&buffer, _("statistics object %s"),
3590 NameStr(stxForm->stxname)));
3591
3593 break;
3594 }
3595
3596 case TSParserRelationId:
3597 {
3598 HeapTuple tup;
3600 char *nspname;
3601
3603 ObjectIdGetDatum(object->objectId));
3604 if (!HeapTupleIsValid(tup))
3605 {
3606 if (!missing_ok)
3607 elog(ERROR, "cache lookup failed for text search parser %u",
3608 object->objectId);
3609 break;
3610 }
3612
3613 /* Qualify the name if not visible in search path */
3614 if (TSParserIsVisible(object->objectId))
3615 nspname = NULL;
3616 else
3617 nspname = get_namespace_name(prsForm->prsnamespace);
3618
3619 appendStringInfo(&buffer, _("text search parser %s"),
3621 NameStr(prsForm->prsname)));
3623 break;
3624 }
3625
3627 {
3628 HeapTuple tup;
3630 char *nspname;
3631
3633 ObjectIdGetDatum(object->objectId));
3634 if (!HeapTupleIsValid(tup))
3635 {
3636 if (!missing_ok)
3637 elog(ERROR, "cache lookup failed for text search dictionary %u",
3638 object->objectId);
3639 break;
3640 }
3641
3643
3644 /* Qualify the name if not visible in search path */
3645 if (TSDictionaryIsVisible(object->objectId))
3646 nspname = NULL;
3647 else
3648 nspname = get_namespace_name(dictForm->dictnamespace);
3649
3650 appendStringInfo(&buffer, _("text search dictionary %s"),
3652 NameStr(dictForm->dictname)));
3654 break;
3655 }
3656
3658 {
3659 HeapTuple tup;
3661 char *nspname;
3662
3664 ObjectIdGetDatum(object->objectId));
3665 if (!HeapTupleIsValid(tup))
3666 {
3667 if (!missing_ok)
3668 elog(ERROR, "cache lookup failed for text search template %u",
3669 object->objectId);
3670 break;
3671 }
3672
3674
3675 /* Qualify the name if not visible in search path */
3676 if (TSTemplateIsVisible(object->objectId))
3677 nspname = NULL;
3678 else
3679 nspname = get_namespace_name(tmplForm->tmplnamespace);
3680
3681 appendStringInfo(&buffer, _("text search template %s"),
3683 NameStr(tmplForm->tmplname)));
3685 break;
3686 }
3687
3688 case TSConfigRelationId:
3689 {
3690 HeapTuple tup;
3692 char *nspname;
3693
3695 ObjectIdGetDatum(object->objectId));
3696 if (!HeapTupleIsValid(tup))
3697 {
3698 if (!missing_ok)
3699 elog(ERROR, "cache lookup failed for text search configuration %u",
3700 object->objectId);
3701 break;
3702 }
3703
3705
3706 /* Qualify the name if not visible in search path */
3707 if (TSConfigIsVisible(object->objectId))
3708 nspname = NULL;
3709 else
3710 nspname = get_namespace_name(cfgForm->cfgnamespace);
3711
3712 appendStringInfo(&buffer, _("text search configuration %s"),
3714 NameStr(cfgForm->cfgname)));
3716 break;
3717 }
3718
3719 case AuthIdRelationId:
3720 {
3721 char *username = GetUserNameFromId(object->objectId,
3722 missing_ok);
3723
3724 if (username)
3725 appendStringInfo(&buffer, _("role %s"), username);
3726 break;
3727 }
3728
3729 case AuthMemRelationId:
3730 {
3732 ScanKeyData skey[1];
3734 HeapTuple tup;
3736
3738
3739 ScanKeyInit(&skey[0],
3742 ObjectIdGetDatum(object->objectId));
3743
3745 NULL, 1, skey);
3746
3748
3749 if (!HeapTupleIsValid(tup))
3750 {
3751 if (!missing_ok)
3752 elog(ERROR, "could not find tuple for role membership %u",
3753 object->objectId);
3754
3757 break;
3758 }
3759
3761
3762 appendStringInfo(&buffer, _("membership of role %s in role %s"),
3763 GetUserNameFromId(amForm->member, false),
3764 GetUserNameFromId(amForm->roleid, false));
3765
3768 break;
3769 }
3770
3771 case DatabaseRelationId:
3772 {
3773 char *datname;
3774
3776 if (!datname)
3777 {
3778 if (!missing_ok)
3779 elog(ERROR, "cache lookup failed for database %u",
3780 object->objectId);
3781 break;
3782 }
3783 appendStringInfo(&buffer, _("database %s"), datname);
3784 break;
3785 }
3786
3788 {
3789 char *tblspace;
3790
3792 if (!tblspace)
3793 {
3794 if (!missing_ok)
3795 elog(ERROR, "cache lookup failed for tablespace %u",
3796 object->objectId);
3797 break;
3798 }
3799 appendStringInfo(&buffer, _("tablespace %s"), tblspace);
3800 break;
3801 }
3802
3804 {
3806
3808 missing_ok);
3809 if (fdw)
3810 appendStringInfo(&buffer, _("foreign-data wrapper %s"), fdw->fdwname);
3811 break;
3812 }
3813
3815 {
3817
3818 srv = GetForeignServerExtended(object->objectId, missing_ok);
3819 if (srv)
3820 appendStringInfo(&buffer, _("server %s"), srv->servername);
3821 break;
3822 }
3823
3825 {
3826 HeapTuple tup;
3827 Oid useid;
3828 char *usename;
3831
3833 ObjectIdGetDatum(object->objectId));
3834 if (!HeapTupleIsValid(tup))
3835 {
3836 if (!missing_ok)
3837 elog(ERROR, "cache lookup failed for user mapping %u",
3838 object->objectId);
3839 break;
3840 }
3841
3843 useid = umform->umuser;
3844 srv = GetForeignServer(umform->umserver);
3845
3847
3848 if (OidIsValid(useid))
3850 else
3851 usename = "public";
3852
3853 appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
3854 srv->servername);
3855 break;
3856 }
3857
3859 {
3861 ScanKeyData skey[1];
3863 HeapTuple tup;
3865 char *rolename;
3866 char *nspname;
3867
3869
3870 ScanKeyInit(&skey[0],
3873 ObjectIdGetDatum(object->objectId));
3874
3876 true, NULL, 1, skey);
3877
3879
3880 if (!HeapTupleIsValid(tup))
3881 {
3882 if (!missing_ok)
3883 elog(ERROR, "could not find tuple for default ACL %u",
3884 object->objectId);
3885
3888 break;
3889 }
3890
3892
3893 rolename = GetUserNameFromId(defacl->defaclrole, false);
3894
3895 if (OidIsValid(defacl->defaclnamespace))
3896 nspname = get_namespace_name(defacl->defaclnamespace);
3897 else
3898 nspname = NULL;
3899
3900 switch (defacl->defaclobjtype)
3901 {
3902 case DEFACLOBJ_RELATION:
3903 if (nspname)
3904 appendStringInfo(&buffer,
3905 _("default privileges on new relations belonging to role %s in schema %s"),
3906 rolename, nspname);
3907 else
3908 appendStringInfo(&buffer,
3909 _("default privileges on new relations belonging to role %s"),
3910 rolename);
3911 break;
3912 case DEFACLOBJ_SEQUENCE:
3913 if (nspname)
3914 appendStringInfo(&buffer,
3915 _("default privileges on new sequences belonging to role %s in schema %s"),
3916 rolename, nspname);
3917 else
3918 appendStringInfo(&buffer,
3919 _("default privileges on new sequences belonging to role %s"),
3920 rolename);
3921 break;
3922 case DEFACLOBJ_FUNCTION:
3923 if (nspname)
3924 appendStringInfo(&buffer,
3925 _("default privileges on new functions belonging to role %s in schema %s"),
3926 rolename, nspname);
3927 else
3928 appendStringInfo(&buffer,
3929 _("default privileges on new functions belonging to role %s"),
3930 rolename);
3931 break;
3932 case DEFACLOBJ_TYPE:
3933 if (nspname)
3934 appendStringInfo(&buffer,
3935 _("default privileges on new types belonging to role %s in schema %s"),
3936 rolename, nspname);
3937 else
3938 appendStringInfo(&buffer,
3939 _("default privileges on new types belonging to role %s"),
3940 rolename);
3941 break;
3943 Assert(!nspname);
3944 appendStringInfo(&buffer,
3945 _("default privileges on new schemas belonging to role %s"),
3946 rolename);
3947 break;
3949 Assert(!nspname);
3950 appendStringInfo(&buffer,
3951 _("default privileges on new large objects belonging to role %s"),
3952 rolename);
3953 break;
3954 default:
3955 /* shouldn't get here */
3956 if (nspname)
3957 appendStringInfo(&buffer,
3958 _("default privileges belonging to role %s in schema %s"),
3959 rolename, nspname);
3960 else
3961 appendStringInfo(&buffer,
3962 _("default privileges belonging to role %s"),
3963 rolename);
3964 break;
3965 }
3966
3969 break;
3970 }
3971
3973 {
3974 char *extname;
3975
3976 extname = get_extension_name(object->objectId);
3977 if (!extname)
3978 {
3979 if (!missing_ok)
3980 elog(ERROR, "cache lookup failed for extension %u",
3981 object->objectId);
3982 break;
3983 }
3984 appendStringInfo(&buffer, _("extension %s"), extname);
3985 break;
3986 }
3987
3989 {
3990 HeapTuple tup;
3991
3993 ObjectIdGetDatum(object->objectId));
3994 if (!HeapTupleIsValid(tup))
3995 {
3996 if (!missing_ok)
3997 elog(ERROR, "cache lookup failed for event trigger %u",
3998 object->objectId);
3999 break;
4000 }
4001 appendStringInfo(&buffer, _("event trigger %s"),
4004 break;
4005 }
4006
4008 {
4009 HeapTuple tup;
4011 char *parname;
4012
4014 ObjectIdGetDatum(object->objectId));
4015 if (!HeapTupleIsValid(tup))
4016 {
4017 if (!missing_ok)
4018 elog(ERROR, "cache lookup failed for parameter ACL %u",
4019 object->objectId);
4020 break;
4021 }
4025 appendStringInfo(&buffer, _("parameter %s"), parname);
4027 break;
4028 }
4029
4030 case PolicyRelationId:
4031 {
4033 ScanKeyData skey[1];
4035 HeapTuple tuple;
4037 StringInfoData rel;
4038
4040
4041 ScanKeyInit(&skey[0],
4044 ObjectIdGetDatum(object->objectId));
4045
4047 true, NULL, 1, skey);
4048
4049 tuple = systable_getnext(sscan);
4050
4051 if (!HeapTupleIsValid(tuple))
4052 {
4053 if (!missing_ok)
4054 elog(ERROR, "could not find tuple for policy %u",
4055 object->objectId);
4056
4059 break;
4060 }
4061
4063
4064 initStringInfo(&rel);
4065 getRelationDescription(&rel, form_policy->polrelid, false);
4066
4067 /* translator: second %s is, e.g., "table %s" */
4068 appendStringInfo(&buffer, _("policy %s on %s"),
4069 NameStr(form_policy->polname), rel.data);
4070 pfree(rel.data);
4073 break;
4074 }
4075
4077 {
4078 HeapTuple tup;
4080
4082 if (!HeapTupleIsValid(tup))
4083 {
4084 if (!missing_ok)
4085 elog(ERROR, "cache lookup failed for property graph element %u",
4086 object->objectId);
4087 break;
4088 }
4089
4091
4092 if (pgeform->pgekind == PGEKIND_VERTEX)
4093 /* translator: followed by, e.g., "property graph %s" */
4094 appendStringInfo(&buffer, _("vertex %s of "), NameStr(pgeform->pgealias));
4095 else if (pgeform->pgekind == PGEKIND_EDGE)
4096 /* translator: followed by, e.g., "property graph %s" */
4097 appendStringInfo(&buffer, _("edge %s of "), NameStr(pgeform->pgealias));
4098 else
4099 appendStringInfo(&buffer, "??? element %s of ", NameStr(pgeform->pgealias));
4100 getRelationDescription(&buffer, pgeform->pgepgid, false);
4101
4103 break;
4104 }
4105
4107 {
4108 Relation rel;
4109 HeapTuple tuple;
4112
4114 tuple = get_catalog_object_by_oid(rel,
4116 object->objectId);
4117 if (!HeapTupleIsValid(tuple))
4118 {
4119 if (!missing_ok)
4120 elog(ERROR, "could not find tuple for element label %u", object->objectId);
4121
4123 break;
4124 }
4125
4127
4128 appendStringInfo(&buffer, _("label %s of "), get_propgraph_label_name(pgelform->pgellabelid));
4131
4133 break;
4134 }
4135
4137 {
4138 HeapTuple tuple;
4140
4142 if (!HeapTupleIsValid(tuple))
4143 {
4144 if (!missing_ok)
4145 elog(ERROR, "could not find tuple for label %u", object->objectId);
4146 break;
4147 }
4148
4150
4151 /* translator: followed by, e.g., "property graph %s" */
4152 appendStringInfo(&buffer, _("label %s of "), NameStr(pglform->pgllabel));
4153 getRelationDescription(&buffer, pglform->pglpgid, false);
4154 ReleaseSysCache(tuple);
4155 break;
4156 }
4157
4159 {
4160 Relation rel;
4161 HeapTuple tuple;
4164
4166 tuple = get_catalog_object_by_oid(rel,
4168 object->objectId);
4169 if (!HeapTupleIsValid(tuple))
4170 {
4171 if (!missing_ok)
4172 elog(ERROR, "could not find tuple for label property %u", object->objectId);
4173
4175 break;
4176 }
4177
4179
4180 appendStringInfo(&buffer, _("property %s of "), get_propgraph_property_name(plpform->plppropid));
4183
4185 break;
4186 }
4187
4189 {
4190 HeapTuple tuple;
4192
4194 if (!HeapTupleIsValid(tuple))
4195 {
4196 if (!missing_ok)
4197 elog(ERROR, "could not find tuple for property %u", object->objectId);
4198 break;
4199 }
4200
4202
4203 /* translator: followed by, e.g., "property graph %s" */
4204 appendStringInfo(&buffer, _("property %s of "), NameStr(pgpform->pgpname));
4205 getRelationDescription(&buffer, pgpform->pgppgid, false);
4206 ReleaseSysCache(tuple);
4207 break;
4208 }
4209
4211 {
4212 char *pubname = get_publication_name(object->objectId,
4213 missing_ok);
4214
4215 if (pubname)
4216 appendStringInfo(&buffer, _("publication %s"), pubname);
4217 break;
4218 }
4219
4221 {
4222 char *pubname;
4223 char *nspname;
4224
4225 if (!getPublicationSchemaInfo(object, missing_ok,
4226 &pubname, &nspname))
4227 break;
4228
4229 appendStringInfo(&buffer, _("publication of schema %s in publication %s"),
4230 nspname, pubname);
4231 pfree(pubname);
4232 pfree(nspname);
4233 break;
4234 }
4235
4237 {
4238 HeapTuple tup;
4239 char *pubname;
4241 StringInfoData rel;
4242
4244 ObjectIdGetDatum(object->objectId));
4245 if (!HeapTupleIsValid(tup))
4246 {
4247 if (!missing_ok)
4248 elog(ERROR, "cache lookup failed for publication table %u",
4249 object->objectId);
4250 break;
4251 }
4252
4254 pubname = get_publication_name(prform->prpubid, false);
4255
4256 initStringInfo(&rel);
4257 getRelationDescription(&rel, prform->prrelid, false);
4258
4259 /* translator: first %s is, e.g., "table %s" */
4260 appendStringInfo(&buffer, _("publication of %s in publication %s"),
4261 rel.data, pubname);
4262 pfree(rel.data);
4264 break;
4265 }
4266
4268 {
4269 char *subname = get_subscription_name(object->objectId,
4270 missing_ok);
4271
4272 if (subname)
4273 appendStringInfo(&buffer, _("subscription %s"), subname);
4274 break;
4275 }
4276
4278 {
4281
4283 ObjectIdGetDatum(object->objectId));
4285 {
4286 if (!missing_ok)
4287 elog(ERROR, "could not find tuple for transform %u",
4288 object->objectId);
4289 break;
4290 }
4291
4293
4294 appendStringInfo(&buffer, _("transform for %s language %s"),
4295 format_type_be(trfForm->trftype),
4296 get_language_name(trfForm->trflang, false));
4297
4299 break;
4300 }
4301
4302 default:
4303 elog(ERROR, "unsupported object class: %u", object->classId);
4304 }
4305
4306 /* an empty buffer is equivalent to no object found */
4307 if (buffer.len == 0)
4308 return NULL;
4309
4310 return buffer.data;
4311}
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:4015
char * get_database_name(Oid dbid)
Definition lsyscache.c:1323
char * get_language_name(Oid langoid, bool missing_ok)
Definition lsyscache.c:1344
char * get_propgraph_label_name(Oid labeloid)
Definition lsyscache.c:3997
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition lsyscache.c:984
char * get_subscription_name(Oid subid, bool missing_ok)
Definition lsyscache.c:3973
char * get_publication_name(Oid pubid, bool missing_ok)
Definition lsyscache.c:3923
char * get_namespace_name(Oid nspid)
Definition lsyscache.c:3599
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 4317 of file objectaddress.c.

4318{
4319 ObjectAddress address;
4320
4321 address.classId = classid;
4322 address.objectId = objid;
4323 address.objectSubId = 0;
4324
4325 return getObjectDescription(&address, false);
4326}

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

5092{
5093 StringInfoData buffer;
5094
5095 initStringInfo(&buffer);
5096
5097 /*
5098 * Make sure that both objname and objargs were passed, or none was; and
5099 * initialize them to empty lists. For objname this is useless because it
5100 * will be initialized in all cases inside the switch; but we do it anyway
5101 * so that we can test below that no branch leaves it unset.
5102 */
5103 Assert((objname != NULL) == (objargs != NULL));
5104 if (objname)
5105 {
5106 *objname = NIL;
5107 *objargs = NIL;
5108 }
5109
5110 switch (object->classId)
5111 {
5112 case RelationRelationId:
5113 {
5114 char *attr = NULL;
5115
5116 /*
5117 * Check for the attribute first, so as if it is missing we
5118 * can skip the entire relation description.
5119 */
5120 if (object->objectSubId != 0)
5121 {
5122 attr = get_attname(object->objectId,
5123 object->objectSubId,
5124 missing_ok);
5125
5126 if (missing_ok && attr == NULL)
5127 break;
5128 }
5129
5130 getRelationIdentity(&buffer, object->objectId, objname,
5131 missing_ok);
5132 if (objname && *objname == NIL)
5133 break;
5134
5135 if (attr)
5136 {
5137 appendStringInfo(&buffer, ".%s",
5138 quote_identifier(attr));
5139 if (objname)
5140 *objname = lappend(*objname, attr);
5141 }
5142 }
5143 break;
5144
5146 {
5149 flags);
5150
5151 if (proname == NULL)
5152 break;
5153
5155 if (objname)
5156 format_procedure_parts(object->objectId, objname, objargs,
5157 missing_ok);
5158 break;
5159 }
5160
5161 case TypeRelationId:
5162 {
5164 char *typeout;
5165
5166 typeout = format_type_extended(object->objectId, -1, flags);
5167
5168 if (typeout == NULL)
5169 break;
5170
5172 if (objname)
5173 *objname = list_make1(typeout);
5174 }
5175 break;
5176
5177 case CastRelationId:
5178 {
5180 HeapTuple tup;
5182
5184
5186 object->objectId);
5187
5188 if (!HeapTupleIsValid(tup))
5189 {
5190 if (!missing_ok)
5191 elog(ERROR, "could not find tuple for cast %u",
5192 object->objectId);
5193
5195 break;
5196 }
5197
5199
5200 appendStringInfo(&buffer, "(%s AS %s)",
5202 format_type_be_qualified(castForm->casttarget));
5203
5204 if (objname)
5205 {
5206 *objname = list_make1(format_type_be_qualified(castForm->castsource));
5207 *objargs = list_make1(format_type_be_qualified(castForm->casttarget));
5208 }
5209
5211 break;
5212 }
5213
5215 {
5217 Form_pg_collation coll;
5218 char *schema;
5219
5221 ObjectIdGetDatum(object->objectId));
5223 {
5224 if (!missing_ok)
5225 elog(ERROR, "cache lookup failed for collation %u",
5226 object->objectId);
5227 break;
5228 }
5230 schema = get_namespace_name_or_temp(coll->collnamespace);
5231 appendStringInfoString(&buffer,
5233 NameStr(coll->collname)));
5234 if (objname)
5235 *objname = list_make2(schema,
5236 pstrdup(NameStr(coll->collname)));
5238 break;
5239 }
5240
5242 {
5245
5247 ObjectIdGetDatum(object->objectId));
5249 {
5250 if (!missing_ok)
5251 elog(ERROR, "cache lookup failed for constraint %u",
5252 object->objectId);
5253 break;
5254 }
5256
5257 if (OidIsValid(con->conrelid))
5258 {
5259 appendStringInfo(&buffer, "%s on ",
5260 quote_identifier(NameStr(con->conname)));
5261 getRelationIdentity(&buffer, con->conrelid, objname,
5262 false);
5263 if (objname)
5264 *objname = lappend(*objname, pstrdup(NameStr(con->conname)));
5265 }
5266 else
5267 {
5268 ObjectAddress domain;
5269
5270 Assert(OidIsValid(con->contypid));
5271 domain.classId = TypeRelationId;
5272 domain.objectId = con->contypid;
5273 domain.objectSubId = 0;
5274
5275 appendStringInfo(&buffer, "%s on %s",
5276 quote_identifier(NameStr(con->conname)),
5277 getObjectIdentityParts(&domain, objname,
5278 objargs, false));
5279
5280 if (objname)
5281 *objargs = lappend(*objargs, pstrdup(NameStr(con->conname)));
5282 }
5283
5285 break;
5286 }
5287
5289 {
5292 char *schema;
5293
5295 ObjectIdGetDatum(object->objectId));
5297 {
5298 if (!missing_ok)
5299 elog(ERROR, "cache lookup failed for conversion %u",
5300 object->objectId);
5301 break;
5302 }
5304 schema = get_namespace_name_or_temp(conForm->connamespace);
5305 appendStringInfoString(&buffer,
5307 NameStr(conForm->conname)));
5308 if (objname)
5309 *objname = list_make2(schema,
5310 pstrdup(NameStr(conForm->conname)));
5312 break;
5313 }
5314
5316 {
5318
5320
5321 if (!OidIsValid(colobject.objectId))
5322 {
5323 if (!missing_ok)
5324 elog(ERROR, "could not find tuple for attrdef %u",
5325 object->objectId);
5326 break;
5327 }
5328
5329 appendStringInfo(&buffer, "for %s",
5331 objname, objargs,
5332 false));
5333 break;
5334 }
5335
5336 case LanguageRelationId:
5337 {
5340
5342 ObjectIdGetDatum(object->objectId));
5344 {
5345 if (!missing_ok)
5346 elog(ERROR, "cache lookup failed for language %u",
5347 object->objectId);
5348 break;
5349 }
5351 appendStringInfoString(&buffer,
5352 quote_identifier(NameStr(langForm->lanname)));
5353 if (objname)
5354 *objname = list_make1(pstrdup(NameStr(langForm->lanname)));
5356 break;
5357 }
5358
5360 if (!LargeObjectExists(object->objectId))
5361 break;
5362 appendStringInfo(&buffer, "%u",
5363 object->objectId);
5364 if (objname)
5365 *objname = list_make1(psprintf("%u", object->objectId));
5366 break;
5367
5368 case OperatorRelationId:
5369 {
5371 char *oprname = format_operator_extended(object->objectId,
5372 flags);
5373
5374 if (oprname == NULL)
5375 break;
5376
5377 appendStringInfoString(&buffer, oprname);
5378 if (objname)
5379 format_operator_parts(object->objectId, objname, objargs, missing_ok);
5380 break;
5381 }
5382
5384 {
5389 char *schema;
5390
5392 ObjectIdGetDatum(object->objectId));
5394 {
5395 if (!missing_ok)
5396 elog(ERROR, "cache lookup failed for opclass %u",
5397 object->objectId);
5398 break;
5399 }
5401 schema = get_namespace_name_or_temp(opcForm->opcnamespace);
5402
5404 ObjectIdGetDatum(opcForm->opcmethod));
5405 if (!HeapTupleIsValid(amTup))
5406 elog(ERROR, "cache lookup failed for access method %u",
5407 opcForm->opcmethod);
5409
5410 appendStringInfo(&buffer, "%s USING %s",
5412 NameStr(opcForm->opcname)),
5413 quote_identifier(NameStr(amForm->amname)));
5414 if (objname)
5415 *objname = list_make3(pstrdup(NameStr(amForm->amname)),
5416 schema,
5417 pstrdup(NameStr(opcForm->opcname)));
5418
5421 break;
5422 }
5423
5425 getOpFamilyIdentity(&buffer, object->objectId, objname,
5426 missing_ok);
5427 break;
5428
5430 {
5431 char *amname;
5432
5433 amname = get_am_name(object->objectId);
5434 if (!amname)
5435 {
5436 if (!missing_ok)
5437 elog(ERROR, "cache lookup failed for access method %u",
5438 object->objectId);
5439 break;
5440 }
5441 appendStringInfoString(&buffer, quote_identifier(amname));
5442 if (objname)
5443 *objname = list_make1(amname);
5444 }
5445 break;
5446
5448 {
5450 HeapTuple tup;
5451 ScanKeyData skey[1];
5454 StringInfoData opfam;
5455 char *ltype;
5456 char *rtype;
5457
5460
5461 ScanKeyInit(&skey[0],
5464 ObjectIdGetDatum(object->objectId));
5465
5467 NULL, 1, skey);
5468
5470
5471 if (!HeapTupleIsValid(tup))
5472 {
5473 if (!missing_ok)
5474 elog(ERROR, "could not find tuple for amop entry %u",
5475 object->objectId);
5476
5479 break;
5480 }
5481
5483
5484 initStringInfo(&opfam);
5485 getOpFamilyIdentity(&opfam, amopForm->amopfamily, objname,
5486 false);
5487
5488 ltype = format_type_be_qualified(amopForm->amoplefttype);
5489 rtype = format_type_be_qualified(amopForm->amoprighttype);
5490
5491 if (objname)
5492 {
5493 *objname = lappend(*objname,
5494 psprintf("%d", amopForm->amopstrategy));
5495 *objargs = list_make2(ltype, rtype);
5496 }
5497
5498 appendStringInfo(&buffer, "operator %d (%s, %s) of %s",
5499 amopForm->amopstrategy,
5500 ltype, rtype, opfam.data);
5501
5502 pfree(opfam.data);
5503
5506 break;
5507 }
5508
5510 {
5512 ScanKeyData skey[1];
5514 HeapTuple tup;
5516 StringInfoData opfam;
5517 char *ltype;
5518 char *rtype;
5519
5522
5523 ScanKeyInit(&skey[0],
5526 ObjectIdGetDatum(object->objectId));
5527
5529 NULL, 1, skey);
5530
5532
5533 if (!HeapTupleIsValid(tup))
5534 {
5535 if (!missing_ok)
5536 elog(ERROR, "could not find tuple for amproc entry %u",
5537 object->objectId);
5538
5541 break;
5542 }
5543
5545
5546 initStringInfo(&opfam);
5547 getOpFamilyIdentity(&opfam, amprocForm->amprocfamily, objname,
5548 false);
5549
5550 ltype = format_type_be_qualified(amprocForm->amproclefttype);
5551 rtype = format_type_be_qualified(amprocForm->amprocrighttype);
5552
5553 if (objname)
5554 {
5555 *objname = lappend(*objname,
5556 psprintf("%d", amprocForm->amprocnum));
5557 *objargs = list_make2(ltype, rtype);
5558 }
5559
5560 appendStringInfo(&buffer, "function %d (%s, %s) of %s",
5561 amprocForm->amprocnum,
5562 ltype, rtype, opfam.data);
5563
5564 pfree(opfam.data);
5565
5568 break;
5569 }
5570
5571 case RewriteRelationId:
5572 {
5574 HeapTuple tup;
5576
5578
5580 object->objectId);
5581
5582 if (!HeapTupleIsValid(tup))
5583 {
5584 if (!missing_ok)
5585 elog(ERROR, "could not find tuple for rule %u",
5586 object->objectId);
5587
5589 break;
5590 }
5591
5593
5594 appendStringInfo(&buffer, "%s on ",
5595 quote_identifier(NameStr(rule->rulename)));
5596 getRelationIdentity(&buffer, rule->ev_class, objname, false);
5597 if (objname)
5598 *objname = lappend(*objname, pstrdup(NameStr(rule->rulename)));
5599
5601 break;
5602 }
5603
5604 case TriggerRelationId:
5605 {
5607 HeapTuple tup;
5609
5611
5613 object->objectId);
5614
5615 if (!HeapTupleIsValid(tup))
5616 {
5617 if (!missing_ok)
5618 elog(ERROR, "could not find tuple for trigger %u",
5619 object->objectId);
5620
5622 break;
5623 }
5624
5626
5627 appendStringInfo(&buffer, "%s on ",
5628 quote_identifier(NameStr(trig->tgname)));
5629 getRelationIdentity(&buffer, trig->tgrelid, objname, false);
5630 if (objname)
5631 *objname = lappend(*objname, pstrdup(NameStr(trig->tgname)));
5632
5634 break;
5635 }
5636
5638 {
5639 char *nspname;
5640
5641 nspname = get_namespace_name_or_temp(object->objectId);
5642 if (!nspname)
5643 {
5644 if (!missing_ok)
5645 elog(ERROR, "cache lookup failed for namespace %u",
5646 object->objectId);
5647 break;
5648 }
5649 appendStringInfoString(&buffer,
5650 quote_identifier(nspname));
5651 if (objname)
5652 *objname = list_make1(nspname);
5653 break;
5654 }
5655
5657 {
5658 HeapTuple tup;
5660 char *schema;
5661
5663 ObjectIdGetDatum(object->objectId));
5664 if (!HeapTupleIsValid(tup))
5665 {
5666 if (!missing_ok)
5667 elog(ERROR, "cache lookup failed for statistics object %u",
5668 object->objectId);
5669 break;
5670 }
5672 schema = get_namespace_name_or_temp(formStatistic->stxnamespace);
5673 appendStringInfoString(&buffer,
5675 NameStr(formStatistic->stxname)));
5676 if (objname)
5677 *objname = list_make2(schema,
5678 pstrdup(NameStr(formStatistic->stxname)));
5680 }
5681 break;
5682
5683 case TSParserRelationId:
5684 {
5685 HeapTuple tup;
5687 char *schema;
5688
5690 ObjectIdGetDatum(object->objectId));
5691 if (!HeapTupleIsValid(tup))
5692 {
5693 if (!missing_ok)
5694 elog(ERROR, "cache lookup failed for text search parser %u",
5695 object->objectId);
5696 break;
5697 }
5699 schema = get_namespace_name_or_temp(formParser->prsnamespace);
5700 appendStringInfoString(&buffer,
5702 NameStr(formParser->prsname)));
5703 if (objname)
5704 *objname = list_make2(schema,
5705 pstrdup(NameStr(formParser->prsname)));
5707 break;
5708 }
5709
5711 {
5712 HeapTuple tup;
5714 char *schema;
5715
5717 ObjectIdGetDatum(object->objectId));
5718 if (!HeapTupleIsValid(tup))
5719 {
5720 if (!missing_ok)
5721 elog(ERROR, "cache lookup failed for text search dictionary %u",
5722 object->objectId);
5723 break;
5724 }
5726 schema = get_namespace_name_or_temp(formDict->dictnamespace);
5727 appendStringInfoString(&buffer,
5729 NameStr(formDict->dictname)));
5730 if (objname)
5731 *objname = list_make2(schema,
5732 pstrdup(NameStr(formDict->dictname)));
5734 break;
5735 }
5736
5738 {
5739 HeapTuple tup;
5741 char *schema;
5742
5744 ObjectIdGetDatum(object->objectId));
5745 if (!HeapTupleIsValid(tup))
5746 {
5747 if (!missing_ok)
5748 elog(ERROR, "cache lookup failed for text search template %u",
5749 object->objectId);
5750 break;
5751 }
5753 schema = get_namespace_name_or_temp(formTmpl->tmplnamespace);
5754 appendStringInfoString(&buffer,
5756 NameStr(formTmpl->tmplname)));
5757 if (objname)
5758 *objname = list_make2(schema,
5759 pstrdup(NameStr(formTmpl->tmplname)));
5761 break;
5762 }
5763
5764 case TSConfigRelationId:
5765 {
5766 HeapTuple tup;
5768 char *schema;
5769
5771 ObjectIdGetDatum(object->objectId));
5772 if (!HeapTupleIsValid(tup))
5773 {
5774 if (!missing_ok)
5775 elog(ERROR, "cache lookup failed for text search configuration %u",
5776 object->objectId);
5777 break;
5778 }
5780 schema = get_namespace_name_or_temp(formCfg->cfgnamespace);
5781 appendStringInfoString(&buffer,
5783 NameStr(formCfg->cfgname)));
5784 if (objname)
5785 *objname = list_make2(schema,
5786 pstrdup(NameStr(formCfg->cfgname)));
5788 break;
5789 }
5790
5791 case AuthIdRelationId:
5792 {
5793 char *username;
5794
5795 username = GetUserNameFromId(object->objectId, missing_ok);
5796 if (!username)
5797 break;
5798 if (objname)
5799 *objname = list_make1(username);
5800 appendStringInfoString(&buffer,
5802 break;
5803 }
5804
5805 case AuthMemRelationId:
5806 {
5808 ScanKeyData skey[1];
5810 HeapTuple tup;
5812
5815
5816 ScanKeyInit(&skey[0],
5819 ObjectIdGetDatum(object->objectId));
5820
5822 NULL, 1, skey);
5823
5825
5826 if (!HeapTupleIsValid(tup))
5827 {
5828 if (!missing_ok)
5829 elog(ERROR, "could not find tuple for pg_auth_members entry %u",
5830 object->objectId);
5831
5834 break;
5835 }
5836
5838
5839 appendStringInfo(&buffer, _("membership of role %s in role %s"),
5840 GetUserNameFromId(amForm->member, false),
5841 GetUserNameFromId(amForm->roleid, false));
5842
5845 break;
5846 }
5847
5848 case DatabaseRelationId:
5849 {
5850 char *datname;
5851
5853 if (!datname)
5854 {
5855 if (!missing_ok)
5856 elog(ERROR, "cache lookup failed for database %u",
5857 object->objectId);
5858 break;
5859 }
5860 if (objname)
5861 *objname = list_make1(datname);
5862 appendStringInfoString(&buffer,
5864 break;
5865 }
5866
5868 {
5869 char *tblspace;
5870
5872 if (!tblspace)
5873 {
5874 if (!missing_ok)
5875 elog(ERROR, "cache lookup failed for tablespace %u",
5876 object->objectId);
5877 break;
5878 }
5879 if (objname)
5880 *objname = list_make1(tblspace);
5881 appendStringInfoString(&buffer,
5883 break;
5884 }
5885
5887 {
5889
5891 missing_ok);
5892 if (fdw)
5893 {
5894 appendStringInfoString(&buffer, quote_identifier(fdw->fdwname));
5895 if (objname)
5896 *objname = list_make1(pstrdup(fdw->fdwname));
5897 }
5898 break;
5899 }
5900
5902 {
5904
5906 missing_ok);
5907 if (srv)
5908 {
5909 appendStringInfoString(&buffer,
5910 quote_identifier(srv->servername));
5911 if (objname)
5912 *objname = list_make1(pstrdup(srv->servername));
5913 }
5914 break;
5915 }
5916
5918 {
5919 HeapTuple tup;
5920 Oid useid;
5923 const char *usename;
5924
5926 ObjectIdGetDatum(object->objectId));
5927 if (!HeapTupleIsValid(tup))
5928 {
5929 if (!missing_ok)
5930 elog(ERROR, "cache lookup failed for user mapping %u",
5931 object->objectId);
5932 break;
5933 }
5935 useid = umform->umuser;
5936 srv = GetForeignServer(umform->umserver);
5937
5939
5940 if (OidIsValid(useid))
5942 else
5943 usename = "public";
5944
5945 if (objname)
5946 {
5947 *objname = list_make1(pstrdup(usename));
5948 *objargs = list_make1(pstrdup(srv->servername));
5949 }
5950
5951 appendStringInfo(&buffer, "%s on server %s",
5953 srv->servername);
5954 break;
5955 }
5956
5958 {
5960 ScanKeyData skey[1];
5962 HeapTuple tup;
5964 char *schema;
5965 char *username;
5966
5968
5969 ScanKeyInit(&skey[0],
5972 ObjectIdGetDatum(object->objectId));
5973
5975 true, NULL, 1, skey);
5976
5978
5979 if (!HeapTupleIsValid(tup))
5980 {
5981 if (!missing_ok)
5982 elog(ERROR, "could not find tuple for default ACL %u",
5983 object->objectId);
5984
5987 break;
5988 }
5989
5991
5992 username = GetUserNameFromId(defacl->defaclrole, false);
5993 appendStringInfo(&buffer,
5994 "for role %s",
5996
5997 if (OidIsValid(defacl->defaclnamespace))
5998 {
5999 schema = get_namespace_name_or_temp(defacl->defaclnamespace);
6000 appendStringInfo(&buffer,
6001 " in schema %s",
6002 quote_identifier(schema));
6003 }
6004 else
6005 schema = NULL;
6006
6007 switch (defacl->defaclobjtype)
6008 {
6009 case DEFACLOBJ_RELATION:
6010 appendStringInfoString(&buffer,
6011 " on tables");
6012 break;
6013 case DEFACLOBJ_SEQUENCE:
6014 appendStringInfoString(&buffer,
6015 " on sequences");
6016 break;
6017 case DEFACLOBJ_FUNCTION:
6018 appendStringInfoString(&buffer,
6019 " on functions");
6020 break;
6021 case DEFACLOBJ_TYPE:
6022 appendStringInfoString(&buffer,
6023 " on types");
6024 break;
6026 appendStringInfoString(&buffer,
6027 " on schemas");
6028 break;
6030 appendStringInfoString(&buffer,
6031 " on large objects");
6032 break;
6033 }
6034
6035 if (objname)
6036 {
6037 *objname = list_make1(username);
6038 if (schema)
6039 *objname = lappend(*objname, schema);
6040 *objargs = list_make1(psprintf("%c", defacl->defaclobjtype));
6041 }
6042
6045 break;
6046 }
6047
6049 {
6050 char *extname;
6051
6052 extname = get_extension_name(object->objectId);
6053 if (!extname)
6054 {
6055 if (!missing_ok)
6056 elog(ERROR, "cache lookup failed for extension %u",
6057 object->objectId);
6058 break;
6059 }
6060 appendStringInfoString(&buffer, quote_identifier(extname));
6061 if (objname)
6062 *objname = list_make1(extname);
6063 break;
6064 }
6065
6067 {
6068 HeapTuple tup;
6070 char *evtname;
6071
6073 ObjectIdGetDatum(object->objectId));
6074 if (!HeapTupleIsValid(tup))
6075 {
6076 if (!missing_ok)
6077 elog(ERROR, "cache lookup failed for event trigger %u",
6078 object->objectId);
6079 break;
6080 }
6082 evtname = pstrdup(NameStr(trigForm->evtname));
6083 appendStringInfoString(&buffer, quote_identifier(evtname));
6084 if (objname)
6085 *objname = list_make1(evtname);
6087 break;
6088 }
6089
6091 {
6092 HeapTuple tup;
6094 char *parname;
6095
6097 ObjectIdGetDatum(object->objectId));
6098 if (!HeapTupleIsValid(tup))
6099 {
6100 if (!missing_ok)
6101 elog(ERROR, "cache lookup failed for parameter ACL %u",
6102 object->objectId);
6103 break;
6104 }
6109 if (objname)
6110 *objname = list_make1(parname);
6112 break;
6113 }
6114
6115 case PolicyRelationId:
6116 {
6118 HeapTuple tup;
6120
6122
6124 object->objectId);
6125
6126 if (!HeapTupleIsValid(tup))
6127 {
6128 if (!missing_ok)
6129 elog(ERROR, "could not find tuple for policy %u",
6130 object->objectId);
6131
6133 break;
6134 }
6135
6137
6138 appendStringInfo(&buffer, "%s on ",
6139 quote_identifier(NameStr(policy->polname)));
6140 getRelationIdentity(&buffer, policy->polrelid, objname, false);
6141 if (objname)
6142 *objname = lappend(*objname, pstrdup(NameStr(policy->polname)));
6143
6145 break;
6146 }
6147
6149 {
6150 HeapTuple tup;
6152
6154 if (!HeapTupleIsValid(tup))
6155 {
6156 if (!missing_ok)
6157 elog(ERROR, "cache lookup failed for property graph element %u", object->objectId);
6158 break;
6159 }
6161 appendStringInfo(&buffer, "%s of ", quote_identifier(NameStr(pge->pgealias)));
6162
6163 getRelationIdentity(&buffer, pge->pgepgid, objname, false);
6164 if (objname)
6165 *objname = lappend(*objname, pstrdup(NameStr(pge->pgealias)));
6166
6168 break;
6169 }
6170
6172 {
6173 HeapTuple tup;
6175
6177 if (!HeapTupleIsValid(tup))
6178 {
6179 if (!missing_ok)
6180 elog(ERROR, "cache lookup failed for property graph label %u", object->objectId);
6181 break;
6182 }
6183
6185 appendStringInfo(&buffer, "%s of ", quote_identifier(NameStr(pgl->pgllabel)));
6186 getRelationIdentity(&buffer, pgl->pglpgid, objname, false);
6187 if (objname)
6188 *objname = lappend(*objname, pstrdup(NameStr(pgl->pgllabel)));
6190 break;
6191 }
6192
6194 {
6195 HeapTuple tup;
6197
6199 if (!HeapTupleIsValid(tup))
6200 {
6201 if (!missing_ok)
6202 elog(ERROR, "cache lookup failed for property graph property %u", object->objectId);
6203 break;
6204 }
6205
6207 appendStringInfo(&buffer, "%s of ", quote_identifier(NameStr(pgp->pgpname)));
6208 getRelationIdentity(&buffer, pgp->pgppgid, objname, false);
6209 if (objname)
6210 *objname = lappend(*objname, pstrdup(NameStr(pgp->pgpname)));
6212 break;
6213 }
6214
6216 {
6217 char *pubname;
6218
6219 pubname = get_publication_name(object->objectId, missing_ok);
6220 if (pubname)
6221 {
6222 appendStringInfoString(&buffer,
6223 quote_identifier(pubname));
6224 if (objname)
6225 *objname = list_make1(pubname);
6226 }
6227 break;
6228 }
6229
6231 {
6232 char *pubname;
6233 char *nspname;
6234
6235 if (!getPublicationSchemaInfo(object, missing_ok, &pubname,
6236 &nspname))
6237 break;
6238 appendStringInfo(&buffer, "%s in publication %s",
6239 nspname, pubname);
6240
6241 if (objargs)
6242 *objargs = list_make1(pubname);
6243 else
6244 pfree(pubname);
6245
6246 if (objname)
6247 *objname = list_make1(nspname);
6248 else
6249 pfree(nspname);
6250
6251 break;
6252 }
6253
6255 {
6256 HeapTuple tup;
6257 char *pubname;
6259
6261 ObjectIdGetDatum(object->objectId));
6262 if (!HeapTupleIsValid(tup))
6263 {
6264 if (!missing_ok)
6265 elog(ERROR, "cache lookup failed for publication table %u",
6266 object->objectId);
6267 break;
6268 }
6269
6271 pubname = get_publication_name(prform->prpubid, false);
6272
6273 getRelationIdentity(&buffer, prform->prrelid, objname, false);
6274 appendStringInfo(&buffer, " in publication %s", pubname);
6275
6276 if (objargs)
6277 *objargs = list_make1(pubname);
6278
6280 break;
6281 }
6282
6284 {
6285 char *subname;
6286
6287 subname = get_subscription_name(object->objectId, missing_ok);
6288 if (subname)
6289 {
6290 appendStringInfoString(&buffer,
6292 if (objname)
6293 *objname = list_make1(subname);
6294 }
6295 break;
6296 }
6297
6299 {
6301 HeapTuple tup;
6302 Form_pg_transform transform;
6303 char *transformLang;
6304 char *transformType;
6305
6307
6310 object->objectId);
6311
6312 if (!HeapTupleIsValid(tup))
6313 {
6314 if (!missing_ok)
6315 elog(ERROR, "could not find tuple for transform %u",
6316 object->objectId);
6317
6319 break;
6320 }
6321
6322 transform = (Form_pg_transform) GETSTRUCT(tup);
6323
6324 transformType = format_type_be_qualified(transform->trftype);
6325 transformLang = get_language_name(transform->trflang, false);
6326
6327 appendStringInfo(&buffer, "for %s language %s",
6330 if (objname)
6331 {
6332 *objname = list_make1(transformType);
6333 *objargs = list_make1(pstrdup(transformLang));
6334 }
6335
6337 }
6338 break;
6339
6340 default:
6341 elog(ERROR, "unsupported object class: %u", object->classId);
6342 }
6343
6344 if (!missing_ok)
6345 {
6346 /*
6347 * If a get_object_address() representation was requested, make sure
6348 * we are providing one. We don't check objargs, because many of the
6349 * cases above leave it as NIL.
6350 */
6351 if (objname && *objname == NIL)
6352 elog(ERROR, "requested object address for unsupported object class %u: text result \"%s\"",
6353 object->classId, buffer.data);
6354 }
6355 else
6356 {
6357 /* an empty buffer is equivalent to no object found */
6358 if (buffer.len == 0)
6359 {
6360 Assert((objname == NULL || *objname == NIL) &&
6361 (objargs == NULL || *objargs == NIL));
6362 return NULL;
6363 }
6364 }
6365
6366 return buffer.data;
6367}
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:3623
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_label, 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_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, 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 4732 of file objectaddress.c.

4733{
4734 StringInfoData buffer;
4735
4736 initStringInfo(&buffer);
4737
4738 switch (object->classId)
4739 {
4740 case RelationRelationId:
4741 getRelationTypeDescription(&buffer, object->objectId,
4742 object->objectSubId,
4743 missing_ok);
4744 break;
4745
4747 getProcedureTypeDescription(&buffer, object->objectId,
4748 missing_ok);
4749 break;
4750
4751 case TypeRelationId:
4752 appendStringInfoString(&buffer, "type");
4753 break;
4754
4755 case CastRelationId:
4756 appendStringInfoString(&buffer, "cast");
4757 break;
4758
4760 appendStringInfoString(&buffer, "collation");
4761 break;
4762
4764 getConstraintTypeDescription(&buffer, object->objectId,
4765 missing_ok);
4766 break;
4767
4769 appendStringInfoString(&buffer, "conversion");
4770 break;
4771
4773 appendStringInfoString(&buffer, "default value");
4774 break;
4775
4776 case LanguageRelationId:
4777 appendStringInfoString(&buffer, "language");
4778 break;
4779
4781 appendStringInfoString(&buffer, "large object");
4782 break;
4783
4784 case OperatorRelationId:
4785 appendStringInfoString(&buffer, "operator");
4786 break;
4787
4789 appendStringInfoString(&buffer, "operator class");
4790 break;
4791
4793 appendStringInfoString(&buffer, "operator family");
4794 break;
4795
4797 appendStringInfoString(&buffer, "access method");
4798 break;
4799
4801 appendStringInfoString(&buffer, "operator of access method");
4802 break;
4803
4805 appendStringInfoString(&buffer, "function of access method");
4806 break;
4807
4808 case RewriteRelationId:
4809 appendStringInfoString(&buffer, "rule");
4810 break;
4811
4812 case TriggerRelationId:
4813 appendStringInfoString(&buffer, "trigger");
4814 break;
4815
4817 appendStringInfoString(&buffer, "schema");
4818 break;
4819
4821 appendStringInfoString(&buffer, "statistics object");
4822 break;
4823
4824 case TSParserRelationId:
4825 appendStringInfoString(&buffer, "text search parser");
4826 break;
4827
4829 appendStringInfoString(&buffer, "text search dictionary");
4830 break;
4831
4833 appendStringInfoString(&buffer, "text search template");
4834 break;
4835
4836 case TSConfigRelationId:
4837 appendStringInfoString(&buffer, "text search configuration");
4838 break;
4839
4840 case AuthIdRelationId:
4841 appendStringInfoString(&buffer, "role");
4842 break;
4843
4844 case AuthMemRelationId:
4845 appendStringInfoString(&buffer, "role membership");
4846 break;
4847
4848 case DatabaseRelationId:
4849 appendStringInfoString(&buffer, "database");
4850 break;
4851
4853 appendStringInfoString(&buffer, "tablespace");
4854 break;
4855
4857 appendStringInfoString(&buffer, "foreign-data wrapper");
4858 break;
4859
4861 appendStringInfoString(&buffer, "server");
4862 break;
4863
4865 appendStringInfoString(&buffer, "user mapping");
4866 break;
4867
4869 appendStringInfoString(&buffer, "default acl");
4870 break;
4871
4873 appendStringInfoString(&buffer, "extension");
4874 break;
4875
4877 appendStringInfoString(&buffer, "event trigger");
4878 break;
4879
4881 appendStringInfoString(&buffer, "parameter ACL");
4882 break;
4883
4884 case PolicyRelationId:
4885 appendStringInfoString(&buffer, "policy");
4886 break;
4887
4889 appendStringInfoString(&buffer, "property graph element");
4890 break;
4891
4893 appendStringInfoString(&buffer, "property graph label");
4894 break;
4895
4897 appendStringInfoString(&buffer, "property graph property");
4898 break;
4899
4901 appendStringInfoString(&buffer, "publication");
4902 break;
4903
4905 appendStringInfoString(&buffer, "publication namespace");
4906 break;
4907
4909 appendStringInfoString(&buffer, "publication relation");
4910 break;
4911
4913 appendStringInfoString(&buffer, "subscription");
4914 break;
4915
4917 appendStringInfoString(&buffer, "transform");
4918 break;
4919
4920 default:
4921 elog(ERROR, "unsupported object class: %u", object->classId);
4922 }
4923
4924 /* the result can never be empty */
4925 Assert(buffer.len > 0);
4926
4927 return buffer.data;
4928}
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 2835 of file objectaddress.c.

2836{
2837 int index;
2838
2839 for (index = 0; index < lengthof(ObjectProperty); index++)
2840 {
2841 if (ObjectProperty[index].class_oid == class_id)
2842 return true;
2843 }
2844
2845 return false;
2846}
#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 2706 of file objectaddress.c.

2707{
2708 int i;
2709
2710 for (i = 0; i < lengthof(ObjectTypeMap); i++)
2711 {
2712 if (strcmp(ObjectTypeMap[i].tm_name, objtype) == 0)
2713 return ObjectTypeMap[i].tm_type;
2714 }
2715 ereport(ERROR,
2717 errmsg("unrecognized object type \"%s\"", objtype)));
2718
2719 return -1; /* keep compiler quiet */
2720}
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 6448 of file objectaddress.c.

6449{
6450 ArrayType *arr;
6451 Datum *datums;
6452 bool *nulls;
6453 int j = 0;
6454 ListCell *cell;
6455 MemoryContext memcxt;
6457 int lb[1];
6458
6459 /* Work in a temp context; easier than individually pfree'ing the Datums */
6461 "strlist to array",
6463 oldcxt = MemoryContextSwitchTo(memcxt);
6464
6465 datums = palloc_array(Datum, list_length(list));
6466 nulls = palloc_array(bool, list_length(list));
6467
6468 foreach(cell, list)
6469 {
6470 char *name = lfirst(cell);
6471
6472 if (name)
6473 {
6474 nulls[j] = false;
6475 datums[j++] = CStringGetTextDatum(name);
6476 }
6477 else
6478 nulls[j] = true;
6479 }
6480
6482
6483 lb[0] = 1;
6484 arr = construct_md_array(datums, nulls, 1, &j,
6485 lb, TEXTOID, -1, false, TYPALIGN_INT);
6486
6487 MemoryContextDelete(memcxt);
6488
6489 return arr;
6490}
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