PostgreSQL Source Code git master
Loading...
Searching...
No Matches
objectaddress.c File Reference
#include "postgres.h"
#include "access/genam.h"
#include "access/htup_details.h"
#include "access/relation.h"
#include "access/table.h"
#include "catalog/catalog.h"
#include "catalog/objectaddress.h"
#include "catalog/pg_am.h"
#include "catalog/pg_amop.h"
#include "catalog/pg_amproc.h"
#include "catalog/pg_attrdef.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_auth_members.h"
#include "catalog/pg_cast.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_constraint.h"
#include "catalog/pg_conversion.h"
#include "catalog/pg_database.h"
#include "catalog/pg_default_acl.h"
#include "catalog/pg_event_trigger.h"
#include "catalog/pg_extension.h"
#include "catalog/pg_foreign_data_wrapper.h"
#include "catalog/pg_foreign_server.h"
#include "catalog/pg_language.h"
#include "catalog/pg_largeobject.h"
#include "catalog/pg_largeobject_metadata.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_opclass.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_opfamily.h"
#include "catalog/pg_parameter_acl.h"
#include "catalog/pg_policy.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_propgraph_element.h"
#include "catalog/pg_propgraph_element_label.h"
#include "catalog/pg_propgraph_label.h"
#include "catalog/pg_propgraph_label_property.h"
#include "catalog/pg_propgraph_property.h"
#include "catalog/pg_publication.h"
#include "catalog/pg_publication_namespace.h"
#include "catalog/pg_publication_rel.h"
#include "catalog/pg_rewrite.h"
#include "catalog/pg_statistic_ext.h"
#include "catalog/pg_subscription.h"
#include "catalog/pg_tablespace.h"
#include "catalog/pg_transform.h"
#include "catalog/pg_trigger.h"
#include "catalog/pg_ts_config.h"
#include "catalog/pg_ts_dict.h"
#include "catalog/pg_ts_parser.h"
#include "catalog/pg_ts_template.h"
#include "catalog/pg_type.h"
#include "catalog/pg_user_mapping.h"
#include "commands/defrem.h"
#include "commands/event_trigger.h"
#include "commands/extension.h"
#include "commands/policy.h"
#include "commands/proclang.h"
#include "commands/tablespace.h"
#include "commands/trigger.h"
#include "foreign/foreign.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "parser/parse_func.h"
#include "parser/parse_oper.h"
#include "parser/parse_type.h"
#include "rewrite/rewriteSupport.h"
#include "storage/large_object.h"
#include "storage/lmgr.h"
#include "storage/sinval.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/regproc.h"
#include "utils/syscache.h"
Include dependency graph for objectaddress.c:

Go to the source code of this file.

Data Structures

struct  ObjectPropertyType
 
struct  object_type_map
 

Functions

static ObjectAddress get_object_address_unqualified (ObjectType objtype, String *strval, 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_relobject (ObjectType objtype, List *object, Relation *relp, bool missing_ok)
 
static ObjectAddress get_object_address_attribute (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)
 
static ObjectAddress get_object_address_type (ObjectType objtype, TypeName *typename, bool missing_ok)
 
static ObjectAddress get_object_address_opcf (ObjectType objtype, List *object, bool missing_ok)
 
static ObjectAddress get_object_address_opf_member (ObjectType objtype, List *object, bool missing_ok)
 
static ObjectAddress get_object_address_usermapping (List *object, bool missing_ok)
 
static ObjectAddress get_object_address_publication_rel (List *object, Relation *relp, bool missing_ok)
 
static ObjectAddress get_object_address_publication_schema (List *object, bool missing_ok)
 
static ObjectAddress get_object_address_defacl (List *object, bool missing_ok)
 
static const ObjectPropertyTypeget_object_property_data (Oid class_id)
 
static void getRelationDescription (StringInfo buffer, Oid relid, bool missing_ok)
 
static void getOpFamilyDescription (StringInfo buffer, Oid opfid, bool missing_ok)
 
static void getRelationTypeDescription (StringInfo buffer, Oid relid, int32 objectSubId, bool missing_ok)
 
static void getProcedureTypeDescription (StringInfo buffer, Oid procid, bool missing_ok)
 
static void getConstraintTypeDescription (StringInfo buffer, Oid constroid, bool missing_ok)
 
static void getOpFamilyIdentity (StringInfo buffer, Oid opfid, List **object, bool missing_ok)
 
static void getRelationIdentity (StringInfo buffer, Oid relid, List **object, bool missing_ok)
 
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)
 
static Listtextarray_to_strvaluelist (ArrayType *arr)
 
Datum pg_get_object_address (PG_FUNCTION_ARGS)
 
void check_object_ownership (Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
 
Oid get_object_namespace (const ObjectAddress *address)
 
int read_objtype_from_string (const char *objtype)
 
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)
 
bool is_objectclass_supported (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)
 
static bool getPublicationSchemaInfo (const ObjectAddress *object, bool missing_ok, char **pubname, char **nspname)
 
chargetObjectDescription (const ObjectAddress *object, bool missing_ok)
 
chargetObjectDescriptionOids (Oid classid, Oid objid)
 
Datum pg_describe_object (PG_FUNCTION_ARGS)
 
Datum pg_identify_object (PG_FUNCTION_ARGS)
 
Datum pg_identify_object_as_address (PG_FUNCTION_ARGS)
 
Datum pg_get_acl (PG_FUNCTION_ARGS)
 
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)
 
ArrayTypestrlist_to_textarray (List *list)
 
ObjectType get_relkind_objtype (char relkind)
 

Variables

static const ObjectPropertyType ObjectProperty []
 
static const struct object_type_map ObjectTypeMap []
 
const ObjectAddress InvalidObjectAddress
 

Function Documentation

◆ check_object_ownership()

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

Definition at line 2493 of file objectaddress.c.

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

Definition at line 2888 of file objectaddress.c.

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

References fb(), and get_catalog_object_by_oid_extended().

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

◆ get_catalog_object_by_oid_extended()

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

Definition at line 2901 of file objectaddress.c.

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

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

Referenced by AlterObjectOwner_internal(), and get_catalog_object_by_oid().

◆ get_object_address()

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

Definition at line 1016 of file objectaddress.c.

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

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

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

◆ get_object_address_attrdef()

static ObjectAddress get_object_address_attrdef ( ObjectType  objtype,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
static

Definition at line 1651 of file objectaddress.c.

1654{
1655 ObjectAddress address;
1656 List *relname;
1657 Oid reloid;
1658 Relation relation;
1659 const char *attname;
1661 TupleDesc tupdesc;
1662 Oid defoid;
1663
1664 /* Extract relation name and open relation. */
1665 if (list_length(object) < 2)
1666 ereport(ERROR,
1668 errmsg("column name must be qualified")));
1669 attname = strVal(llast(object));
1670 relname = list_copy_head(object, list_length(object) - 1);
1671 /* XXX no missing_ok support here */
1672 relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1673 reloid = RelationGetRelid(relation);
1674
1675 tupdesc = RelationGetDescr(relation);
1676
1677 /* Look up attribute number and fetch the pg_attrdef OID */
1678 attnum = get_attnum(reloid, attname);
1680 if (attnum != InvalidAttrNumber && tupdesc->constr != NULL)
1681 defoid = GetAttrDefaultOid(reloid, attnum);
1682 if (!OidIsValid(defoid))
1683 {
1684 if (!missing_ok)
1685 ereport(ERROR,
1687 errmsg("default value for column \"%s\" of relation \"%s\" does not exist",
1689
1691 address.objectId = InvalidOid;
1693 relation_close(relation, lockmode);
1694 return address;
1695 }
1696
1698 address.objectId = defoid;
1699 address.objectSubId = 0;
1700
1701 *relp = relation;
1702 return address;
1703}
int16 AttrNumber
Definition attnum.h:21
#define InvalidAttrNumber
Definition attnum.h:23
List * list_copy_head(const List *oldlist, int len)
Definition list.c:1593
AttrNumber get_attnum(Oid relid, const char *attname)
Definition lsyscache.c:1084
RangeVar * makeRangeVarFromNameList(const List *names)
Definition namespace.c:3626
Oid GetAttrDefaultOid(Oid relid, AttrNumber attnum)
Definition pg_attrdef.c:280
NameData attname
int16 attnum
NameData relname
Definition pg_class.h:40
#define llast(l)
Definition pg_list.h:198
static int list_length(const List *l)
Definition pg_list.h:152
#define RelationGetDescr(relation)
Definition rel.h:542
void relation_close(Relation relation, LOCKMODE lockmode)
Definition relation.c:206
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition relation.c:138
TupleConstr * constr
Definition tupdesc.h:159

References attname, attnum, ObjectAddress::classId, TupleDescData::constr, ereport, errcode(), errmsg, ERROR, fb(), get_attnum(), GetAttrDefaultOid(), InvalidAttrNumber, InvalidOid, list_copy_head(), list_length(), llast, makeRangeVarFromNameList(), NameListToString(), ObjectAddress::objectId, ObjectAddress::objectSubId, OidIsValid, relation_close(), relation_openrv(), RelationGetDescr, RelationGetRelid, relname, and strVal.

Referenced by get_object_address().

◆ get_object_address_attribute()

static ObjectAddress get_object_address_attribute ( ObjectType  objtype,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
static

Definition at line 1600 of file objectaddress.c.

1603{
1604 ObjectAddress address;
1605 List *relname;
1606 Oid reloid;
1607 Relation relation;
1608 const char *attname;
1610
1611 /* Extract relation name and open relation. */
1612 if (list_length(object) < 2)
1613 ereport(ERROR,
1615 errmsg("column name must be qualified")));
1616 attname = strVal(llast(object));
1617 relname = list_copy_head(object, list_length(object) - 1);
1618 /* XXX no missing_ok support here */
1619 relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1620 reloid = RelationGetRelid(relation);
1621
1622 /* Look up attribute and construct return value. */
1623 attnum = get_attnum(reloid, attname);
1625 {
1626 if (!missing_ok)
1627 ereport(ERROR,
1629 errmsg("column \"%s\" of relation \"%s\" does not exist",
1631
1632 address.classId = RelationRelationId;
1633 address.objectId = InvalidOid;
1635 relation_close(relation, lockmode);
1636 return address;
1637 }
1638
1639 address.classId = RelationRelationId;
1640 address.objectId = reloid;
1641 address.objectSubId = attnum;
1642
1643 *relp = relation;
1644 return address;
1645}

References attname, attnum, ObjectAddress::classId, ereport, errcode(), errmsg, ERROR, fb(), get_attnum(), InvalidAttrNumber, InvalidOid, list_copy_head(), list_length(), llast, makeRangeVarFromNameList(), NameListToString(), ObjectAddress::objectId, ObjectAddress::objectSubId, relation_close(), relation_openrv(), RelationGetRelid, relname, and strVal.

Referenced by get_object_address().

◆ get_object_address_defacl()

static ObjectAddress get_object_address_defacl ( List object,
bool  missing_ok 
)
static

Definition at line 2064 of file objectaddress.c.

2065{
2066 HeapTuple tp;
2067 Oid userid;
2068 Oid schemaid;
2069 char *username;
2070 char *schema;
2071 char objtype;
2072 char *objtype_str;
2073 ObjectAddress address;
2074
2076
2077 /*
2078 * First figure out the textual attributes so that they can be used for
2079 * error reporting.
2080 */
2081 username = strVal(lsecond(object));
2082 if (list_length(object) >= 3)
2083 schema = (char *) strVal(lthird(object));
2084 else
2085 schema = NULL;
2086
2087 /*
2088 * Decode defaclobjtype. Only first char is considered; the rest of the
2089 * string, if any, is blissfully ignored.
2090 */
2091 objtype = ((char *) strVal(linitial(object)))[0];
2092 switch (objtype)
2093 {
2094 case DEFACLOBJ_RELATION:
2095 objtype_str = "tables";
2096 break;
2097 case DEFACLOBJ_SEQUENCE:
2098 objtype_str = "sequences";
2099 break;
2100 case DEFACLOBJ_FUNCTION:
2101 objtype_str = "functions";
2102 break;
2103 case DEFACLOBJ_TYPE:
2104 objtype_str = "types";
2105 break;
2107 objtype_str = "schemas";
2108 break;
2110 objtype_str = "large objects";
2111 break;
2112 default:
2113 ereport(ERROR,
2115 errmsg("unrecognized default ACL object type \"%c\"", objtype),
2116 errhint("Valid object types are \"%c\", \"%c\", \"%c\", \"%c\", \"%c\", \"%c\".",
2123 }
2124
2125 /*
2126 * Look up user ID. Behave as "default ACL not found" if the user doesn't
2127 * exist.
2128 */
2131 if (!HeapTupleIsValid(tp))
2132 goto not_found;
2133 userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
2134 ReleaseSysCache(tp);
2135
2136 /*
2137 * If a schema name was given, look up its OID. If it doesn't exist,
2138 * behave as "default ACL not found".
2139 */
2140 if (schema)
2141 {
2142 schemaid = get_namespace_oid(schema, true);
2143 if (schemaid == InvalidOid)
2144 goto not_found;
2145 }
2146 else
2148
2149 /* Finally, look up the pg_default_acl object */
2151 ObjectIdGetDatum(userid),
2153 CharGetDatum(objtype));
2154 if (!HeapTupleIsValid(tp))
2155 goto not_found;
2156
2157 address.objectId = ((Form_pg_default_acl) GETSTRUCT(tp))->oid;
2158 ReleaseSysCache(tp);
2159
2160 return address;
2161
2162not_found:
2163 if (!missing_ok)
2164 {
2165 if (schema)
2166 ereport(ERROR,
2168 errmsg("default ACL for user \"%s\" in schema \"%s\" on %s does not exist",
2169 username, schema, objtype_str)));
2170 else
2171 ereport(ERROR,
2173 errmsg("default ACL for user \"%s\" on %s does not exist",
2175 }
2176 return address;
2177}
int errhint(const char *fmt,...) pg_attribute_printf(1
static char * username
Definition initdb.c:153
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition namespace.c:3607
#define ObjectAddressSet(addr, class_id, object_id)
END_CATALOG_STRUCT typedef FormData_pg_authid * Form_pg_authid
Definition pg_authid.h:60
END_CATALOG_STRUCT typedef FormData_pg_default_acl * Form_pg_default_acl
#define lthird(l)
Definition pg_list.h:188
#define linitial(l)
Definition pg_list.h:178
static Datum CStringGetDatum(const char *X)
Definition postgres.h:383
static Datum CharGetDatum(char X)
Definition postgres.h:132
HeapTuple SearchSysCache3(SysCacheIdentifier cacheId, Datum key1, Datum key2, Datum key3)
Definition syscache.c:241

References CharGetDatum(), CStringGetDatum(), ereport, errcode(), errhint(), errmsg, ERROR, fb(), Form_pg_authid, Form_pg_default_acl, get_namespace_oid(), GETSTRUCT(), HeapTupleIsValid, InvalidOid, linitial, list_length(), lsecond, lthird, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache1(), SearchSysCache3(), strVal, and username.

Referenced by get_object_address().

◆ get_object_address_opcf()

static ObjectAddress get_object_address_opcf ( ObjectType  objtype,
List object,
bool  missing_ok 
)
static

Definition at line 1748 of file objectaddress.c.

1749{
1750 Oid amoid;
1751 ObjectAddress address;
1752
1753 /* XXX no missing_ok support here */
1754 amoid = get_index_am_oid(strVal(linitial(object)), false);
1755 object = list_copy_tail(object, 1);
1756
1757 switch (objtype)
1758 {
1759 case OBJECT_OPCLASS:
1761 address.objectId = get_opclass_oid(amoid, object, missing_ok);
1762 address.objectSubId = 0;
1763 break;
1764 case OBJECT_OPFAMILY:
1766 address.objectId = get_opfamily_oid(amoid, object, missing_ok);
1767 address.objectSubId = 0;
1768 break;
1769 default:
1770 elog(ERROR, "unrecognized object type: %d", (int) objtype);
1771 /* placate compiler, which doesn't know elog won't return */
1772 address.classId = InvalidOid;
1773 address.objectId = InvalidOid;
1774 address.objectSubId = 0;
1775 }
1776
1777 return address;
1778}
Oid get_index_am_oid(const char *amname, bool missing_ok)
Definition amcmds.c:163
List * list_copy_tail(const List *oldlist, int nskip)
Definition list.c:1613
Oid get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
Oid get_opfamily_oid(Oid amID, List *opfamilyname, bool missing_ok)

References ObjectAddress::classId, elog, ERROR, fb(), get_index_am_oid(), get_opclass_oid(), get_opfamily_oid(), InvalidOid, linitial, list_copy_tail(), OBJECT_OPCLASS, OBJECT_OPFAMILY, ObjectAddress::objectId, ObjectAddress::objectSubId, and strVal.

Referenced by get_object_address(), and get_object_address_opf_member().

◆ get_object_address_opf_member()

static ObjectAddress get_object_address_opf_member ( ObjectType  objtype,
List object,
bool  missing_ok 
)
static

Definition at line 1786 of file objectaddress.c.

1788{
1790 ObjectAddress address;
1791 ListCell *cell;
1792 List *copy;
1793 TypeName *typenames[2];
1794 Oid typeoids[2];
1795 int membernum;
1796 int i;
1797
1798 /*
1799 * The last element of the object list contains the strategy or procedure
1800 * number. We need to strip that out before getting the opclass/family
1801 * address. The rest can be used directly by get_object_address_opcf().
1802 */
1803 membernum = atoi(strVal(llast(linitial(object))));
1804 copy = list_copy_head(linitial(object), list_length(linitial(object)) - 1);
1805
1806 /* no missing_ok support here */
1808
1809 /* find out left/right type names and OIDs */
1810 typenames[0] = typenames[1] = NULL;
1811 typeoids[0] = typeoids[1] = InvalidOid;
1812 i = 0;
1813 foreach(cell, lsecond(object))
1814 {
1816
1817 typenames[i] = lfirst_node(TypeName, cell);
1819 typeoids[i] = typaddr.objectId;
1820 if (++i >= 2)
1821 break;
1822 }
1823
1824 switch (objtype)
1825 {
1826 case OBJECT_AMOP:
1827 {
1828 HeapTuple tp;
1829
1831 InvalidOid);
1832
1834 ObjectIdGetDatum(famaddr.objectId),
1838 if (!HeapTupleIsValid(tp))
1839 {
1840 if (!missing_ok)
1841 ereport(ERROR,
1843 errmsg("operator %d (%s, %s) of %s does not exist",
1844 membernum,
1847 getObjectDescription(&famaddr, false))));
1848 }
1849 else
1850 {
1851 address.objectId = ((Form_pg_amop) GETSTRUCT(tp))->oid;
1852 ReleaseSysCache(tp);
1853 }
1854 }
1855 break;
1856
1857 case OBJECT_AMPROC:
1858 {
1859 HeapTuple tp;
1860
1862 InvalidOid);
1863
1865 ObjectIdGetDatum(famaddr.objectId),
1869 if (!HeapTupleIsValid(tp))
1870 {
1871 if (!missing_ok)
1872 ereport(ERROR,
1874 errmsg("function %d (%s, %s) of %s does not exist",
1875 membernum,
1878 getObjectDescription(&famaddr, false))));
1879 }
1880 else
1881 {
1882 address.objectId = ((Form_pg_amproc) GETSTRUCT(tp))->oid;
1883 ReleaseSysCache(tp);
1884 }
1885 }
1886 break;
1887 default:
1888 elog(ERROR, "unrecognized object type: %d", (int) objtype);
1889 }
1890
1891 return address;
1892}
int i
Definition isn.c:77
const char ** typenames
Definition lexi.c:115
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
char * TypeNameToString(const TypeName *typeName)
Definition parse_type.c:478
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
#define lfirst_node(type, lc)
Definition pg_list.h:176
static Datum Int16GetDatum(int16 X)
Definition postgres.h:172
HeapTuple SearchSysCache4(SysCacheIdentifier cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
Definition syscache.c:251

References elog, ereport, errcode(), errmsg, ERROR, fb(), Form_pg_amop, Form_pg_amproc, get_object_address_opcf(), get_object_address_type(), getObjectDescription(), GETSTRUCT(), HeapTupleIsValid, i, Int16GetDatum(), InvalidOid, lfirst_node, linitial, list_copy_head(), list_length(), llast, lsecond, OBJECT_AMOP, OBJECT_AMPROC, OBJECT_OPFAMILY, OBJECT_TYPE, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache4(), strVal, typenames, and TypeNameToString().

Referenced by get_object_address().

◆ get_object_address_publication_rel()

static ObjectAddress get_object_address_publication_rel ( List object,
Relation relp,
bool  missing_ok 
)
static

Definition at line 1969 of file objectaddress.c.

1971{
1972 ObjectAddress address;
1973 Relation relation;
1974 List *relname;
1975 char *pubname;
1976 Publication *pub;
1977
1979
1980 relname = linitial(object);
1982 AccessShareLock, missing_ok);
1983 if (!relation)
1984 return address;
1985
1986 /* fetch publication name from input list */
1987 pubname = strVal(lsecond(object));
1988
1989 /* Now look up the pg_publication tuple */
1990 pub = GetPublicationByName(pubname, missing_ok);
1991 if (!pub)
1992 {
1994 return address;
1995 }
1996
1997 /* Find the publication relation mapping in syscache. */
1998 address.objectId =
2001 ObjectIdGetDatum(pub->oid));
2002 if (!OidIsValid(address.objectId))
2003 {
2004 if (!missing_ok)
2005 ereport(ERROR,
2007 errmsg("publication relation \"%s\" in publication \"%s\" does not exist",
2008 RelationGetRelationName(relation), pubname)));
2010 return address;
2011 }
2012
2013 *relp = relation;
2014 return address;
2015}
#define AccessShareLock
Definition lockdefs.h:36
Publication * GetPublicationByName(const char *pubname, bool missing_ok)
Relation relation_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition relation.c:173
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition syscache.h:111

References AccessShareLock, ereport, errcode(), errmsg, ERROR, fb(), GetPublicationByName(), GetSysCacheOid2, InvalidOid, linitial, lsecond, makeRangeVarFromNameList(), ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), Publication::oid, OidIsValid, relation_close(), relation_openrv_extended(), RelationGetRelationName, RelationGetRelid, relname, and strVal.

Referenced by get_object_address().

◆ get_object_address_publication_schema()

static ObjectAddress get_object_address_publication_schema ( List object,
bool  missing_ok 
)
static

Definition at line 2022 of file objectaddress.c.

2023{
2024 ObjectAddress address;
2025 Publication *pub;
2026 char *pubname;
2027 char *schemaname;
2028 Oid schemaid;
2029
2031
2032 /* Fetch schema name and publication name from input list */
2033 schemaname = strVal(linitial(object));
2034 pubname = strVal(lsecond(object));
2035
2036 schemaid = get_namespace_oid(schemaname, missing_ok);
2037 if (!OidIsValid(schemaid))
2038 return address;
2039
2040 /* Now look up the pg_publication tuple */
2041 pub = GetPublicationByName(pubname, missing_ok);
2042 if (!pub)
2043 return address;
2044
2045 /* Find the publication schema mapping in syscache */
2046 address.objectId =
2050 ObjectIdGetDatum(pub->oid));
2051 if (!OidIsValid(address.objectId) && !missing_ok)
2052 ereport(ERROR,
2054 errmsg("publication schema \"%s\" in publication \"%s\" does not exist",
2055 schemaname, pubname)));
2056
2057 return address;
2058}

References ereport, errcode(), errmsg, ERROR, fb(), get_namespace_oid(), GetPublicationByName(), GetSysCacheOid2, InvalidOid, linitial, lsecond, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), Publication::oid, OidIsValid, and strVal.

Referenced by get_object_address().

◆ get_object_address_relobject()

static ObjectAddress get_object_address_relobject ( ObjectType  objtype,
List object,
Relation relp,
bool  missing_ok 
)
static

Definition at line 1521 of file objectaddress.c.

1523{
1524 ObjectAddress address;
1525 Relation relation = NULL;
1526 int nnames;
1527 const char *depname;
1528 List *relname;
1529 Oid reloid;
1530
1531 /* Extract name of dependent object. */
1532 depname = strVal(llast(object));
1533
1534 /* Separate relation name from dependent object name. */
1535 nnames = list_length(object);
1536 if (nnames < 2)
1537 ereport(ERROR,
1539 errmsg("must specify relation and object name")));
1540
1541 /* Extract relation name and open relation. */
1542 relname = list_copy_head(object, nnames - 1);
1545 missing_ok);
1546
1547 reloid = relation ? RelationGetRelid(relation) : InvalidOid;
1548
1549 switch (objtype)
1550 {
1551 case OBJECT_RULE:
1552 address.classId = RewriteRelationId;
1553 address.objectId = relation ?
1554 get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
1555 address.objectSubId = 0;
1556 break;
1557 case OBJECT_TRIGGER:
1558 address.classId = TriggerRelationId;
1559 address.objectId = relation ?
1560 get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
1561 address.objectSubId = 0;
1562 break;
1564 address.classId = ConstraintRelationId;
1565 address.objectId = relation ?
1566 get_relation_constraint_oid(reloid, depname, missing_ok) :
1567 InvalidOid;
1568 address.objectSubId = 0;
1569 break;
1570 case OBJECT_POLICY:
1571 address.classId = PolicyRelationId;
1572 address.objectId = relation ?
1573 get_relation_policy_oid(reloid, depname, missing_ok) :
1574 InvalidOid;
1575 address.objectSubId = 0;
1576 break;
1577 default:
1578 elog(ERROR, "unrecognized object type: %d", (int) objtype);
1579 }
1580
1581 /* Avoid relcache leak when object not found. */
1582 if (!OidIsValid(address.objectId))
1583 {
1584 if (relation != NULL)
1585 table_close(relation, AccessShareLock);
1586
1587 relation = NULL; /* department of accident prevention */
1588 return address;
1589 }
1590
1591 /* Done. */
1592 *relp = relation;
1593 return address;
1594}
Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok)
Oid get_relation_policy_oid(Oid relid, const char *policy_name, bool missing_ok)
Definition policy.c:1216
Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok)
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition table.c:103
Oid get_trigger_oid(Oid relid, const char *trigname, bool missing_ok)
Definition trigger.c:1384

References AccessShareLock, ObjectAddress::classId, elog, ereport, errcode(), errmsg, ERROR, fb(), get_relation_constraint_oid(), get_relation_policy_oid(), get_rewrite_oid(), get_trigger_oid(), InvalidOid, list_copy_head(), list_length(), llast, makeRangeVarFromNameList(), OBJECT_POLICY, OBJECT_RULE, OBJECT_TABCONSTRAINT, OBJECT_TRIGGER, ObjectAddress::objectId, ObjectAddress::objectSubId, OidIsValid, RelationGetRelid, relname, strVal, table_close(), and table_openrv_extended().

Referenced by get_object_address().

◆ get_object_address_rv()

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

Definition at line 1319 of file objectaddress.c.

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

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

Referenced by ExecAlterObjectDependsStmt(), and ExecAlterOwnerStmt().

◆ get_object_address_type()

static ObjectAddress get_object_address_type ( ObjectType  objtype,
TypeName typename,
bool  missing_ok 
)
static

Definition at line 1709 of file objectaddress.c.

1710{
1711 ObjectAddress address;
1712 Type tup;
1713
1714 address.classId = TypeRelationId;
1715 address.objectId = InvalidOid;
1716 address.objectSubId = 0;
1717
1718 tup = LookupTypeName(NULL, typename, NULL, missing_ok);
1719 if (!HeapTupleIsValid(tup))
1720 {
1721 if (!missing_ok)
1722 ereport(ERROR,
1724 errmsg("type \"%s\" does not exist",
1725 TypeNameToString(typename))));
1726 return address;
1727 }
1728 address.objectId = typeTypeId(tup);
1729
1730 if (objtype == OBJECT_DOMAIN)
1731 {
1732 if (((Form_pg_type) GETSTRUCT(tup))->typtype != TYPTYPE_DOMAIN)
1733 ereport(ERROR,
1735 errmsg("\"%s\" is not a domain",
1736 TypeNameToString(typename))));
1737 }
1738
1740
1741 return address;
1742}
Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
Definition parse_type.c:38
Oid typeTypeId(Type tp)
Definition parse_type.c:590
END_CATALOG_STRUCT typedef FormData_pg_type * Form_pg_type
Definition pg_type.h:265

References ObjectAddress::classId, ereport, errcode(), errmsg, ERROR, fb(), Form_pg_type, GETSTRUCT(), HeapTupleIsValid, InvalidOid, LookupTypeName(), OBJECT_DOMAIN, ObjectAddress::objectId, ObjectAddress::objectSubId, ReleaseSysCache(), TypeNameToString(), and typeTypeId().

Referenced by get_object_address(), and get_object_address_opf_member().

◆ get_object_address_unqualified()

static ObjectAddress get_object_address_unqualified ( ObjectType  objtype,
String strval,
bool  missing_ok 
)
static

Definition at line 1341 of file objectaddress.c.

1343{
1344 const char *name;
1345 ObjectAddress address;
1346
1347 name = strVal(strval);
1348
1349 /* Translate name to OID. */
1350 switch (objtype)
1351 {
1354 address.objectId = get_am_oid(name, missing_ok);
1355 address.objectSubId = 0;
1356 break;
1357 case OBJECT_DATABASE:
1358 address.classId = DatabaseRelationId;
1359 address.objectId = get_database_oid(name, missing_ok);
1360 address.objectSubId = 0;
1361 break;
1362 case OBJECT_EXTENSION:
1363 address.classId = ExtensionRelationId;
1364 address.objectId = get_extension_oid(name, missing_ok);
1365 address.objectSubId = 0;
1366 break;
1367 case OBJECT_TABLESPACE:
1368 address.classId = TableSpaceRelationId;
1369 address.objectId = get_tablespace_oid(name, missing_ok);
1370 address.objectSubId = 0;
1371 break;
1372 case OBJECT_ROLE:
1373 address.classId = AuthIdRelationId;
1374 address.objectId = get_role_oid(name, missing_ok);
1375 address.objectSubId = 0;
1376 break;
1377 case OBJECT_SCHEMA:
1378 address.classId = NamespaceRelationId;
1379 address.objectId = get_namespace_oid(name, missing_ok);
1380 address.objectSubId = 0;
1381 break;
1382 case OBJECT_LANGUAGE:
1383 address.classId = LanguageRelationId;
1384 address.objectId = get_language_oid(name, missing_ok);
1385 address.objectSubId = 0;
1386 break;
1387 case OBJECT_FDW:
1389 address.objectId = get_foreign_data_wrapper_oid(name, missing_ok);
1390 address.objectSubId = 0;
1391 break;
1394 address.objectId = get_foreign_server_oid(name, missing_ok);
1395 address.objectSubId = 0;
1396 break;
1399 address.objectId = get_event_trigger_oid(name, missing_ok);
1400 address.objectSubId = 0;
1401 break;
1404 address.objectId = ParameterAclLookup(name, missing_ok);
1405 address.objectSubId = 0;
1406 break;
1407 case OBJECT_PUBLICATION:
1409 address.objectId = get_publication_oid(name, missing_ok);
1410 address.objectSubId = 0;
1411 break;
1414 address.objectId = get_subscription_oid(name, missing_ok);
1415 address.objectSubId = 0;
1416 break;
1417 default:
1418 elog(ERROR, "unrecognized object type: %d", (int) objtype);
1419 /* placate compiler, which doesn't know elog won't return */
1420 address.classId = InvalidOid;
1421 address.objectId = InvalidOid;
1422 address.objectSubId = 0;
1423 }
1424
1425 return address;
1426}
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition acl.c:5608
Oid get_am_oid(const char *amname, bool missing_ok)
Definition amcmds.c:183
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Oid get_database_oid(const char *dbname, bool missing_ok)
Oid get_event_trigger_oid(const char *trigname, bool missing_ok)
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition extension.c:229
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition foreign.c:736
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition foreign.c:713
Oid get_publication_oid(const char *pubname, bool missing_ok)
Definition lsyscache.c:3986
Oid get_subscription_oid(const char *subname, bool missing_ok)
Definition lsyscache.c:4036
Oid ParameterAclLookup(const char *parameter, bool missing_ok)
const char * name

References ObjectAddress::classId, elog, ERROR, fb(), get_am_oid(), get_database_oid(), get_event_trigger_oid(), get_extension_oid(), get_foreign_data_wrapper_oid(), get_foreign_server_oid(), get_language_oid(), get_namespace_oid(), get_publication_oid(), get_role_oid(), get_subscription_oid(), get_tablespace_oid(), InvalidOid, name, OBJECT_ACCESS_METHOD, OBJECT_DATABASE, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_LANGUAGE, OBJECT_PARAMETER_ACL, OBJECT_PUBLICATION, OBJECT_ROLE, OBJECT_SCHEMA, OBJECT_SUBSCRIPTION, OBJECT_TABLESPACE, ObjectAddress::objectId, ObjectAddress::objectSubId, ParameterAclLookup(), and strVal.

Referenced by get_object_address().

◆ get_object_address_usermapping()

static ObjectAddress get_object_address_usermapping ( List object,
bool  missing_ok 
)
static

Definition at line 1898 of file objectaddress.c.

1899{
1900 ObjectAddress address;
1901 Oid userid;
1902 char *username;
1903 char *servername;
1904 ForeignServer *server;
1905 HeapTuple tp;
1906
1908
1909 /* fetch string names from input lists, for error messages */
1910 username = strVal(linitial(object));
1911 servername = strVal(lsecond(object));
1912
1913 /* look up pg_authid OID of mapped user; InvalidOid if PUBLIC */
1914 if (strcmp(username, "public") == 0)
1915 userid = InvalidOid;
1916 else
1917 {
1920 if (!HeapTupleIsValid(tp))
1921 {
1922 if (!missing_ok)
1923 ereport(ERROR,
1925 errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1926 username, servername)));
1927 return address;
1928 }
1929 userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
1930 ReleaseSysCache(tp);
1931 }
1932
1933 /* Now look up the pg_user_mapping tuple */
1934 server = GetForeignServerByName(servername, true);
1935 if (!server)
1936 {
1937 if (!missing_ok)
1938 ereport(ERROR,
1940 errmsg("server \"%s\" does not exist", servername)));
1941 return address;
1942 }
1944 ObjectIdGetDatum(userid),
1945 ObjectIdGetDatum(server->serverid));
1946 if (!HeapTupleIsValid(tp))
1947 {
1948 if (!missing_ok)
1949 ereport(ERROR,
1951 errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1952 username, servername)));
1953 return address;
1954 }
1955
1956 address.objectId = ((Form_pg_user_mapping) GETSTRUCT(tp))->oid;
1957
1958 ReleaseSysCache(tp);
1959
1960 return address;
1961}
ForeignServer * GetForeignServerByName(const char *srvname, bool missing_ok)
Definition foreign.c:185
END_CATALOG_STRUCT typedef FormData_pg_user_mapping * Form_pg_user_mapping
HeapTuple SearchSysCache2(SysCacheIdentifier cacheId, Datum key1, Datum key2)
Definition syscache.c:231

References CStringGetDatum(), ereport, errcode(), errmsg, ERROR, fb(), Form_pg_authid, Form_pg_user_mapping, GetForeignServerByName(), GETSTRUCT(), HeapTupleIsValid, InvalidOid, linitial, lsecond, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache1(), SearchSysCache2(), ForeignServer::serverid, strVal, and username.

Referenced by get_object_address().

◆ get_object_attnum_acl()

AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 2794 of file objectaddress.c.

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

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

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

◆ get_object_attnum_name()

◆ get_object_attnum_namespace()

◆ get_object_attnum_oid()

◆ get_object_attnum_owner()

◆ get_object_catcache_name()

SysCacheIdentifier get_object_catcache_name ( Oid  class_id)

Definition at line 2754 of file objectaddress.c.

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

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

◆ get_object_catcache_oid()

◆ get_object_class_descr()

◆ get_object_namensp_unique()

bool get_object_namensp_unique ( Oid  class_id)

◆ get_object_namespace()

Oid get_object_namespace ( const ObjectAddress address)

Definition at line 2676 of file objectaddress.c.

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

◆ get_object_property_data()

static const ObjectPropertyType * get_object_property_data ( Oid  class_id)
static

Definition at line 2854 of file objectaddress.c.

2855{
2856 static const ObjectPropertyType *prop_last = NULL;
2857
2858 /*
2859 * A shortcut to speed up multiple consecutive lookups of a particular
2860 * object class.
2861 */
2862 if (prop_last && prop_last->class_oid == class_id)
2863 return prop_last;
2864
2865 for (size_t index = 0; index < lengthof(ObjectProperty); index++)
2866 {
2867 if (ObjectProperty[index].class_oid == class_id)
2868 {
2870 return &ObjectProperty[index];
2871 }
2872 }
2873
2874 ereport(ERROR,
2875 (errmsg_internal("unrecognized class ID: %u", class_id)));
2876
2877 return NULL; /* keep MSC compiler happy */
2878}
#define lengthof(array)
Definition c.h:932
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
static const ObjectPropertyType ObjectProperty[]
Definition type.h:97

References ereport, errmsg_internal(), ERROR, fb(), lengthof, and ObjectProperty.

Referenced by get_object_attnum_acl(), get_object_attnum_name(), get_object_attnum_namespace(), get_object_attnum_oid(), get_object_attnum_owner(), get_object_catcache_name(), get_object_catcache_oid(), get_object_class_descr(), get_object_namensp_unique(), get_object_namespace(), get_object_oid_index(), and get_object_type().

◆ get_object_type()

ObjectType get_object_type ( Oid  class_id,
Oid  object_id 
)

Definition at line 2809 of file objectaddress.c.

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

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

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

◆ get_relation_by_qualified_name()

static ObjectAddress get_relation_by_qualified_name ( ObjectType  objtype,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
static

Definition at line 1432 of file objectaddress.c.

1435{
1436 Relation relation;
1437 ObjectAddress address;
1438
1439 address.classId = RelationRelationId;
1440 address.objectId = InvalidOid;
1441 address.objectSubId = 0;
1442
1444 lockmode, missing_ok);
1445 if (!relation)
1446 return address;
1447
1448 switch (objtype)
1449 {
1450 case OBJECT_INDEX:
1451 if (relation->rd_rel->relkind != RELKIND_INDEX &&
1452 relation->rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
1453 ereport(ERROR,
1455 errmsg("\"%s\" is not an index",
1456 RelationGetRelationName(relation))));
1457 break;
1458 case OBJECT_PROPGRAPH:
1459 if (relation->rd_rel->relkind != RELKIND_PROPGRAPH)
1460 ereport(ERROR,
1462 errmsg("\"%s\" is not a property graph",
1463 RelationGetRelationName(relation))));
1464 break;
1465 case OBJECT_SEQUENCE:
1466 if (relation->rd_rel->relkind != RELKIND_SEQUENCE)
1467 ereport(ERROR,
1469 errmsg("\"%s\" is not a sequence",
1470 RelationGetRelationName(relation))));
1471 break;
1472 case OBJECT_TABLE:
1473 if (relation->rd_rel->relkind != RELKIND_RELATION &&
1474 relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1475 ereport(ERROR,
1477 errmsg("\"%s\" is not a table",
1478 RelationGetRelationName(relation))));
1479 break;
1480 case OBJECT_VIEW:
1481 if (relation->rd_rel->relkind != RELKIND_VIEW)
1482 ereport(ERROR,
1484 errmsg("\"%s\" is not a view",
1485 RelationGetRelationName(relation))));
1486 break;
1487 case OBJECT_MATVIEW:
1488 if (relation->rd_rel->relkind != RELKIND_MATVIEW)
1489 ereport(ERROR,
1491 errmsg("\"%s\" is not a materialized view",
1492 RelationGetRelationName(relation))));
1493 break;
1495 if (relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE)
1496 ereport(ERROR,
1498 errmsg("\"%s\" is not a foreign table",
1499 RelationGetRelationName(relation))));
1500 break;
1501 default:
1502 elog(ERROR, "unrecognized object type: %d", (int) objtype);
1503 break;
1504 }
1505
1506 /* Done. */
1507 address.objectId = RelationGetRelid(relation);
1508 *relp = relation;
1509
1510 return address;
1511}
Form_pg_class rd_rel
Definition rel.h:111

References ObjectAddress::classId, elog, ereport, errcode(), errmsg, ERROR, fb(), InvalidOid, makeRangeVarFromNameList(), OBJECT_FOREIGN_TABLE, OBJECT_INDEX, OBJECT_MATVIEW, OBJECT_PROPGRAPH, OBJECT_SEQUENCE, OBJECT_TABLE, OBJECT_VIEW, ObjectAddress::objectId, ObjectAddress::objectSubId, RelationData::rd_rel, relation_openrv_extended(), RelationGetRelationName, and RelationGetRelid.

Referenced by get_object_address().

◆ get_relkind_objtype()

ObjectType get_relkind_objtype ( char  relkind)

Definition at line 6600 of file objectaddress.c.

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

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

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

◆ getConstraintTypeDescription()

static void getConstraintTypeDescription ( StringInfo  buffer,
Oid  constroid,
bool  missing_ok 
)
static

Definition at line 5022 of file objectaddress.c.

5023{
5027
5030 constroid);
5032 {
5033 if (!missing_ok)
5034 elog(ERROR, "cache lookup failed for constraint %u", constroid);
5035
5037
5038 /* fallback to "constraint" for an undefined object */
5039 appendStringInfoString(buffer, "constraint");
5040 return;
5041 }
5042
5044
5045 if (OidIsValid(constrForm->conrelid))
5046 appendStringInfoString(buffer, "table constraint");
5047 else if (OidIsValid(constrForm->contypid))
5048 appendStringInfoString(buffer, "domain constraint");
5049 else
5050 elog(ERROR, "invalid constraint %u", constrForm->oid);
5051
5053}
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
void appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40

References AccessShareLock, appendStringInfoString(), elog, ERROR, fb(), Form_pg_constraint, get_catalog_object_by_oid(), GETSTRUCT(), HeapTupleIsValid, OidIsValid, table_close(), and table_open().

Referenced by getObjectTypeDescription().

◆ getObjectDescription()

char * getObjectDescription ( const ObjectAddress object,
bool  missing_ok 
)

Definition at line 3010 of file objectaddress.c.

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

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

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

◆ getObjectDescriptionOids()

char * getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 4331 of file objectaddress.c.

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

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

◆ getObjectIdentity()

◆ getObjectIdentityParts()

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

Definition at line 5111 of file objectaddress.c.

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

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

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

◆ getObjectTypeDescription()

char * getObjectTypeDescription ( const ObjectAddress object,
bool  missing_ok 
)

Definition at line 4746 of file objectaddress.c.

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

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

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

◆ getOpFamilyDescription()

static void getOpFamilyDescription ( StringInfo  buffer,
Oid  opfid,
bool  missing_ok 
)
static

Definition at line 4427 of file objectaddress.c.

4428{
4433 char *nspname;
4434
4437 {
4438 if (!missing_ok)
4439 elog(ERROR, "cache lookup failed for opfamily %u", opfid);
4440 return;
4441 }
4443
4445 if (!HeapTupleIsValid(amTup))
4446 elog(ERROR, "cache lookup failed for access method %u",
4447 opfForm->opfmethod);
4449
4450 /* Qualify the name if not visible in search path */
4452 nspname = NULL;
4453 else
4454 nspname = get_namespace_name(opfForm->opfnamespace);
4455
4456 appendStringInfo(buffer, _("operator family %s for access method %s"),
4458 NameStr(opfForm->opfname)),
4459 NameStr(amForm->amname));
4460
4463}
bool OpfamilyIsVisible(Oid opfid)
Definition namespace.c:2325
END_CATALOG_STRUCT typedef FormData_pg_opfamily * Form_pg_opfamily
Definition pg_opfamily.h:55

References _, appendStringInfo(), elog, ERROR, fb(), Form_pg_am, Form_pg_opfamily, get_namespace_name(), GETSTRUCT(), HeapTupleIsValid, NameStr, ObjectIdGetDatum(), OpfamilyIsVisible(), quote_qualified_identifier(), ReleaseSysCache(), and SearchSysCache1().

Referenced by getObjectDescription().

◆ getOpFamilyIdentity()

static void getOpFamilyIdentity ( StringInfo  buffer,
Oid  opfid,
List **  object,
bool  missing_ok 
)
static

Definition at line 6467 of file objectaddress.c.

6469{
6474 char *schema;
6475
6478 {
6479 if (!missing_ok)
6480 elog(ERROR, "cache lookup failed for opfamily %u", opfid);
6481 return;
6482 }
6484
6486 if (!HeapTupleIsValid(amTup))
6487 elog(ERROR, "cache lookup failed for access method %u",
6488 opfForm->opfmethod);
6490
6491 schema = get_namespace_name_or_temp(opfForm->opfnamespace);
6492 appendStringInfo(buffer, "%s USING %s",
6494 NameStr(opfForm->opfname)),
6495 NameStr(amForm->amname));
6496
6497 if (object)
6498 *object = list_make3(pstrdup(NameStr(amForm->amname)),
6499 pstrdup(schema),
6500 pstrdup(NameStr(opfForm->opfname)));
6501
6504}

References appendStringInfo(), elog, ERROR, fb(), Form_pg_am, Form_pg_opfamily, get_namespace_name_or_temp(), GETSTRUCT(), HeapTupleIsValid, list_make3, NameStr, ObjectIdGetDatum(), pstrdup(), quote_qualified_identifier(), ReleaseSysCache(), and SearchSysCache1().

Referenced by getObjectIdentityParts().

◆ getProcedureTypeDescription()

static void getProcedureTypeDescription ( StringInfo  buffer,
Oid  procid,
bool  missing_ok 
)
static

Definition at line 5059 of file objectaddress.c.

5061{
5064
5066 ObjectIdGetDatum(procid));
5068 {
5069 if (!missing_ok)
5070 elog(ERROR, "cache lookup failed for procedure %u", procid);
5071
5072 /* fallback to "procedure" for an undefined object */
5073 appendStringInfoString(buffer, "routine");
5074 return;
5075 }
5077
5078 if (procForm->prokind == PROKIND_AGGREGATE)
5079 appendStringInfoString(buffer, "aggregate");
5080 else if (procForm->prokind == PROKIND_PROCEDURE)
5081 appendStringInfoString(buffer, "procedure");
5082 else /* function or window function */
5083 appendStringInfoString(buffer, "function");
5084
5086}
END_CATALOG_STRUCT typedef FormData_pg_proc * Form_pg_proc
Definition pg_proc.h:140

References appendStringInfoString(), elog, ERROR, fb(), Form_pg_proc, GETSTRUCT(), HeapTupleIsValid, ObjectIdGetDatum(), ReleaseSysCache(), and SearchSysCache1().

Referenced by getObjectTypeDescription().

◆ getPublicationSchemaInfo()

static bool getPublicationSchemaInfo ( const ObjectAddress object,
bool  missing_ok,
char **  pubname,
char **  nspname 
)
static

Definition at line 2962 of file objectaddress.c.

2964{
2965 HeapTuple tup;
2967
2969 ObjectIdGetDatum(object->objectId));
2970 if (!HeapTupleIsValid(tup))
2971 {
2972 if (!missing_ok)
2973 elog(ERROR, "cache lookup failed for publication schema %u",
2974 object->objectId);
2975 return false;
2976 }
2977
2979 *pubname = get_publication_name(pnform->pnpubid, missing_ok);
2980 if (!(*pubname))
2981 {
2983 return false;
2984 }
2985
2986 *nspname = get_namespace_name(pnform->pnnspid);
2987 if (!(*nspname))
2988 {
2989 Oid schemaid = pnform->pnnspid;
2990
2991 pfree(*pubname);
2993 if (!missing_ok)
2994 elog(ERROR, "cache lookup failed for schema %u",
2995 schemaid);
2996 return false;
2997 }
2998
3000 return true;
3001}
END_CATALOG_STRUCT typedef FormData_pg_publication_namespace * Form_pg_publication_namespace

References elog, ERROR, fb(), Form_pg_publication_namespace, get_namespace_name(), get_publication_name(), GETSTRUCT(), HeapTupleIsValid, ObjectAddress::objectId, ObjectIdGetDatum(), pfree(), ReleaseSysCache(), and SearchSysCache1().

Referenced by getObjectDescription(), and getObjectIdentityParts().

◆ getRelationDescription()

static void getRelationDescription ( StringInfo  buffer,
Oid  relid,
bool  missing_ok 
)
static

Definition at line 4348 of file objectaddress.c.

4349{
4352 char *nspname;
4353 char *relname;
4354
4356 ObjectIdGetDatum(relid));
4358 {
4359 if (!missing_ok)
4360 elog(ERROR, "cache lookup failed for relation %u", relid);
4361 return;
4362 }
4364
4365 /* Qualify the name if not visible in search path */
4366 if (RelationIsVisible(relid))
4367 nspname = NULL;
4368 else
4369 nspname = get_namespace_name(relForm->relnamespace);
4370
4371 relname = quote_qualified_identifier(nspname, NameStr(relForm->relname));
4372
4373 switch (relForm->relkind)
4374 {
4375 case RELKIND_RELATION:
4377 appendStringInfo(buffer, _("table %s"),
4378 relname);
4379 break;
4380 case RELKIND_INDEX:
4382 appendStringInfo(buffer, _("index %s"),
4383 relname);
4384 break;
4385 case RELKIND_SEQUENCE:
4386 appendStringInfo(buffer, _("sequence %s"),
4387 relname);
4388 break;
4389 case RELKIND_TOASTVALUE:
4390 appendStringInfo(buffer, _("toast table %s"),
4391 relname);
4392 break;
4393 case RELKIND_VIEW:
4394 appendStringInfo(buffer, _("view %s"),
4395 relname);
4396 break;
4397 case RELKIND_MATVIEW:
4398 appendStringInfo(buffer, _("materialized view %s"),
4399 relname);
4400 break;
4402 appendStringInfo(buffer, _("composite type %s"),
4403 relname);
4404 break;
4406 appendStringInfo(buffer, _("foreign table %s"),
4407 relname);
4408 break;
4409 case RELKIND_PROPGRAPH:
4410 appendStringInfo(buffer, _("property graph %s"),
4411 relname);
4412 break;
4413 default:
4414 /* shouldn't get here */
4415 appendStringInfo(buffer, _("relation %s"),
4416 relname);
4417 break;
4418 }
4419
4421}
bool RelationIsVisible(Oid relid)
Definition namespace.c:914
FormData_pg_class * Form_pg_class
Definition pg_class.h:160

References _, appendStringInfo(), elog, ERROR, fb(), get_namespace_name(), GETSTRUCT(), HeapTupleIsValid, NameStr, ObjectIdGetDatum(), quote_qualified_identifier(), RelationIsVisible(), ReleaseSysCache(), relname, and SearchSysCache1().

Referenced by getObjectDescription().

◆ getRelationIdentity()

static void getRelationIdentity ( StringInfo  buffer,
Oid  relid,
List **  object,
bool  missing_ok 
)
static

Definition at line 6511 of file objectaddress.c.

6513{
6516 char *schema;
6517
6519 ObjectIdGetDatum(relid));
6521 {
6522 if (!missing_ok)
6523 elog(ERROR, "cache lookup failed for relation %u", relid);
6524
6525 if (object)
6526 *object = NIL;
6527 return;
6528 }
6530
6531 schema = get_namespace_name_or_temp(relForm->relnamespace);
6534 NameStr(relForm->relname)));
6535 if (object)
6536 *object = list_make2(schema, pstrdup(NameStr(relForm->relname)));
6537
6539}

References appendStringInfoString(), elog, ERROR, fb(), get_namespace_name_or_temp(), GETSTRUCT(), HeapTupleIsValid, list_make2, NameStr, NIL, ObjectIdGetDatum(), pstrdup(), quote_qualified_identifier(), ReleaseSysCache(), and SearchSysCache1().

Referenced by getObjectIdentityParts().

◆ getRelationTypeDescription()

static void getRelationTypeDescription ( StringInfo  buffer,
Oid  relid,
int32  objectSubId,
bool  missing_ok 
)
static

Definition at line 4956 of file objectaddress.c.

4958{
4961
4963 ObjectIdGetDatum(relid));
4965 {
4966 if (!missing_ok)
4967 elog(ERROR, "cache lookup failed for relation %u", relid);
4968
4969 /* fallback to "relation" for an undefined object */
4970 appendStringInfoString(buffer, "relation");
4971 return;
4972 }
4974
4975 switch (relForm->relkind)
4976 {
4977 case RELKIND_RELATION:
4979 appendStringInfoString(buffer, "table");
4980 break;
4981 case RELKIND_INDEX:
4983 appendStringInfoString(buffer, "index");
4984 break;
4985 case RELKIND_SEQUENCE:
4986 appendStringInfoString(buffer, "sequence");
4987 break;
4988 case RELKIND_TOASTVALUE:
4989 appendStringInfoString(buffer, "toast table");
4990 break;
4991 case RELKIND_VIEW:
4992 appendStringInfoString(buffer, "view");
4993 break;
4994 case RELKIND_MATVIEW:
4995 appendStringInfoString(buffer, "materialized view");
4996 break;
4998 appendStringInfoString(buffer, "composite type");
4999 break;
5001 appendStringInfoString(buffer, "foreign table");
5002 break;
5003 case RELKIND_PROPGRAPH:
5004 appendStringInfoString(buffer, "property graph");
5005 break;
5006 default:
5007 /* shouldn't get here */
5008 appendStringInfoString(buffer, "relation");
5009 break;
5010 }
5011
5012 if (objectSubId != 0)
5013 appendStringInfoString(buffer, " column");
5014
5016}

References appendStringInfoString(), elog, ERROR, fb(), GETSTRUCT(), HeapTupleIsValid, ObjectIdGetDatum(), ReleaseSysCache(), and SearchSysCache1().

Referenced by getObjectTypeDescription().

◆ is_objectclass_supported()

bool is_objectclass_supported ( Oid  class_id)

Definition at line 2839 of file objectaddress.c.

2840{
2841 for (size_t index = 0; index < lengthof(ObjectProperty); index++)
2842 {
2843 if (ObjectProperty[index].class_oid == class_id)
2844 return true;
2845 }
2846
2847 return false;
2848}

References fb(), lengthof, and ObjectProperty.

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

◆ pg_describe_object()

Datum pg_describe_object ( PG_FUNCTION_ARGS  )

Definition at line 4469 of file objectaddress.c.

4470{
4471 Oid classid = PG_GETARG_OID(0);
4472 Oid objid = PG_GETARG_OID(1);
4473 int32 objsubid = PG_GETARG_INT32(2);
4474 char *description;
4475 ObjectAddress address;
4476
4477 /* for "pinned" items in pg_depend, return null */
4478 if (!OidIsValid(classid) && !OidIsValid(objid))
4480
4481 address.classId = classid;
4482 address.objectId = objid;
4483 address.objectSubId = objsubid;
4484
4485 description = getObjectDescription(&address, true);
4486
4487 if (description == NULL)
4489
4491}
int32_t int32
Definition c.h:679
#define PG_GETARG_OID(n)
Definition fmgr.h:275
#define PG_RETURN_NULL()
Definition fmgr.h:346
#define PG_RETURN_TEXT_P(x)
Definition fmgr.h:374
#define PG_GETARG_INT32(n)
Definition fmgr.h:269
text * cstring_to_text(const char *s)
Definition varlena.c:184
const char * description

References ObjectAddress::classId, cstring_to_text(), description, fb(), getObjectDescription(), ObjectAddress::objectId, ObjectAddress::objectSubId, OidIsValid, PG_GETARG_INT32, PG_GETARG_OID, PG_RETURN_NULL, and PG_RETURN_TEXT_P.

◆ pg_get_acl()

Datum pg_get_acl ( PG_FUNCTION_ARGS  )

Definition at line 4675 of file objectaddress.c.

4676{
4677 Oid classId = PG_GETARG_OID(0);
4678 Oid objectId = PG_GETARG_OID(1);
4679 int32 objsubid = PG_GETARG_INT32(2);
4680 Oid catalogId;
4682 Datum datum;
4683 bool isnull;
4684 HeapTuple tup;
4685
4686 /* for "pinned" items in pg_depend, return null */
4687 if (!OidIsValid(classId) && !OidIsValid(objectId))
4689
4690 /* for large objects, the catalog to look at is pg_largeobject_metadata */
4691 catalogId = (classId == LargeObjectRelationId) ?
4693 Anum_acl = get_object_attnum_acl(catalogId);
4694
4695 /* return NULL if no ACL field for this catalog */
4698
4699 /*
4700 * If dealing with a relation's attribute (objsubid is set), the ACL is
4701 * retrieved from pg_attribute.
4702 */
4703 if (classId == RelationRelationId && objsubid != 0)
4704 {
4705 AttrNumber attnum = (AttrNumber) objsubid;
4706
4707 tup = SearchSysCacheCopyAttNum(objectId, attnum);
4708
4709 if (!HeapTupleIsValid(tup))
4711
4713 &isnull);
4714 }
4715 else
4716 {
4717 Relation rel;
4718
4719 rel = table_open(catalogId, AccessShareLock);
4720
4722 objectId);
4723 if (!HeapTupleIsValid(tup))
4724 {
4727 }
4728
4729 datum = heap_getattr(tup, Anum_acl, RelationGetDescr(rel), &isnull);
4731 }
4732
4733 if (isnull)
4735
4736 PG_RETURN_DATUM(datum);
4737}
#define PG_RETURN_DATUM(x)
Definition fmgr.h:354
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
AttrNumber get_object_attnum_oid(Oid class_id)
AttrNumber get_object_attnum_acl(Oid class_id)
HeapTuple SearchSysCacheCopyAttNum(Oid relid, int16 attnum)
Definition syscache.c:562
Datum SysCacheGetAttr(SysCacheIdentifier cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition syscache.c:596

References AccessShareLock, attnum, fb(), get_catalog_object_by_oid(), get_object_attnum_acl(), get_object_attnum_oid(), heap_getattr(), HeapTupleIsValid, InvalidAttrNumber, OidIsValid, PG_GETARG_INT32, PG_GETARG_OID, PG_RETURN_DATUM, PG_RETURN_NULL, RelationGetDescr, SearchSysCacheCopyAttNum(), SysCacheGetAttr(), table_close(), and table_open().

◆ pg_get_object_address()

Datum pg_get_object_address ( PG_FUNCTION_ARGS  )

Definition at line 2210 of file objectaddress.c.

2211{
2212 char *ttype = TextDatumGetCString(PG_GETARG_DATUM(0));
2215 int itype;
2217 List *name = NIL;
2218 TypeName *typename = NULL;
2219 List *args = NIL;
2220 Node *objnode = NULL;
2221 ObjectAddress addr;
2222 TupleDesc tupdesc;
2223 Datum values[3];
2224 bool nulls[3];
2225 HeapTuple htup;
2226 Relation relation;
2227
2228 /* Decode object type, raise error if unknown */
2230 if (itype < 0)
2231 ereport(ERROR,
2233 errmsg("unsupported object type \"%s\"", ttype)));
2234 type = (ObjectType) itype;
2235
2236 /*
2237 * Convert the text array to the representation appropriate for the given
2238 * object type. Most use a simple string Values list, but there are some
2239 * exceptions.
2240 */
2241 if (type == OBJECT_TYPE || type == OBJECT_DOMAIN || type == OBJECT_CAST ||
2243 {
2244 Datum *elems;
2245 bool *nulls;
2246 int nelems;
2247
2248 deconstruct_array_builtin(namearr, TEXTOID, &elems, &nulls, &nelems);
2249 if (nelems != 1)
2250 ereport(ERROR,
2252 errmsg("name list length must be exactly %d", 1)));
2253 if (nulls[0])
2254 ereport(ERROR,
2256 errmsg("name or argument lists may not contain nulls")));
2257 typename = typeStringToTypeName(TextDatumGetCString(elems[0]), NULL);
2258 }
2259 else if (type == OBJECT_LARGEOBJECT)
2260 {
2261 Datum *elems;
2262 bool *nulls;
2263 int nelems;
2264
2265 deconstruct_array_builtin(namearr, TEXTOID, &elems, &nulls, &nelems);
2266 if (nelems != 1)
2267 ereport(ERROR,
2269 errmsg("name list length must be exactly %d", 1)));
2270 if (nulls[0])
2271 ereport(ERROR,
2273 errmsg("large object OID may not be null")));
2274 objnode = (Node *) makeFloat(TextDatumGetCString(elems[0]));
2275 }
2276 else
2277 {
2279 if (name == NIL)
2280 ereport(ERROR,
2282 errmsg("name list length must be at least %d", 1)));
2283 }
2284
2285 /*
2286 * If args are given, decode them according to the object type.
2287 */
2288 if (type == OBJECT_AGGREGATE ||
2289 type == OBJECT_FUNCTION ||
2291 type == OBJECT_ROUTINE ||
2292 type == OBJECT_OPERATOR ||
2293 type == OBJECT_CAST ||
2294 type == OBJECT_AMOP ||
2296 {
2297 /* in these cases, the args list must be of TypeName */
2298 Datum *elems;
2299 bool *nulls;
2300 int nelems;
2301 int i;
2302
2303 deconstruct_array_builtin(argsarr, TEXTOID, &elems, &nulls, &nelems);
2304
2305 args = NIL;
2306 for (i = 0; i < nelems; i++)
2307 {
2308 if (nulls[i])
2309 ereport(ERROR,
2311 errmsg("name or argument lists may not contain nulls")));
2312 args = lappend(args,
2314 NULL));
2315 }
2316 }
2317 else
2318 {
2319 /* For all other object types, use string Values */
2321 }
2322
2323 /*
2324 * get_object_address is pretty sensitive to the length of its input
2325 * lists; check that they're what it wants.
2326 */
2327 switch (type)
2328 {
2331 if (list_length(name) != 1)
2332 ereport(ERROR,
2334 errmsg("name list length must be exactly %d", 1)));
2335 /* fall through to check args length */
2338 case OBJECT_CAST:
2340 case OBJECT_DEFACL:
2341 case OBJECT_TRANSFORM:
2342 if (list_length(args) != 1)
2343 ereport(ERROR,
2345 errmsg("argument list length must be exactly %d", 1)));
2346 break;
2347 case OBJECT_OPFAMILY:
2348 case OBJECT_OPCLASS:
2349 if (list_length(name) < 2)
2350 ereport(ERROR,
2352 errmsg("name list length must be at least %d", 2)));
2353 break;
2354 case OBJECT_AMOP:
2355 case OBJECT_AMPROC:
2356 if (list_length(name) < 3)
2357 ereport(ERROR,
2359 errmsg("name list length must be at least %d", 3)));
2360 /* fall through to check args length */
2362 case OBJECT_OPERATOR:
2363 if (list_length(args) != 2)
2364 ereport(ERROR,
2366 errmsg("argument list length must be exactly %d", 2)));
2367 break;
2368 default:
2369 break;
2370 }
2371
2372 /*
2373 * Now build the Node type that get_object_address() expects for the given
2374 * type.
2375 */
2376 switch (type)
2377 {
2378 case OBJECT_TABLE:
2379 case OBJECT_SEQUENCE:
2380 case OBJECT_VIEW:
2381 case OBJECT_MATVIEW:
2382 case OBJECT_INDEX:
2384 case OBJECT_PROPGRAPH:
2385 case OBJECT_COLUMN:
2386 case OBJECT_ATTRIBUTE:
2387 case OBJECT_COLLATION:
2388 case OBJECT_CONVERSION:
2390 case OBJECT_TSPARSER:
2392 case OBJECT_TSTEMPLATE:
2394 case OBJECT_DEFAULT:
2395 case OBJECT_POLICY:
2396 case OBJECT_RULE:
2397 case OBJECT_TRIGGER:
2399 case OBJECT_OPCLASS:
2400 case OBJECT_OPFAMILY:
2401 objnode = (Node *) name;
2402 break;
2404 case OBJECT_DATABASE:
2406 case OBJECT_EXTENSION:
2407 case OBJECT_FDW:
2409 case OBJECT_LANGUAGE:
2411 case OBJECT_PUBLICATION:
2412 case OBJECT_ROLE:
2413 case OBJECT_SCHEMA:
2415 case OBJECT_TABLESPACE:
2416 if (list_length(name) != 1)
2417 ereport(ERROR,
2419 errmsg("name list length must be exactly %d", 1)));
2421 break;
2422 case OBJECT_TYPE:
2423 case OBJECT_DOMAIN:
2424 objnode = (Node *) typename;
2425 break;
2426 case OBJECT_CAST:
2428 case OBJECT_TRANSFORM:
2429 objnode = (Node *) list_make2(typename, linitial(args));
2430 break;
2432 objnode = (Node *) list_make2(name, linitial(args));
2433 break;
2437 break;
2438 case OBJECT_DEFACL:
2439 objnode = (Node *) lcons(linitial(args), name);
2440 break;
2441 case OBJECT_AMOP:
2442 case OBJECT_AMPROC:
2443 objnode = (Node *) list_make2(name, args);
2444 break;
2445 case OBJECT_FUNCTION:
2446 case OBJECT_PROCEDURE:
2447 case OBJECT_ROUTINE:
2448 case OBJECT_AGGREGATE:
2449 case OBJECT_OPERATOR:
2450 {
2452
2453 owa->objname = name;
2454 owa->objargs = args;
2455 objnode = (Node *) owa;
2456 break;
2457 }
2458 case OBJECT_LARGEOBJECT:
2459 /* already handled above */
2460 break;
2461 /* no default, to let compiler warn about missing case */
2462 }
2463
2464 if (objnode == NULL)
2465 elog(ERROR, "unrecognized object type: %d", type);
2466
2468 &relation, AccessShareLock, false);
2469
2470 /* We don't need the relcache entry, thank you very much */
2471 if (relation)
2473
2474 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
2475 elog(ERROR, "return type must be a row type");
2476
2477 values[0] = ObjectIdGetDatum(addr.classId);
2478 values[1] = ObjectIdGetDatum(addr.objectId);
2479 values[2] = Int32GetDatum(addr.objectSubId);
2480 nulls[0] = false;
2481 nulls[1] = false;
2482 nulls[2] = false;
2483
2484 htup = heap_form_tuple(tupdesc, values, nulls);
2485
2487}
#define PG_GETARG_ARRAYTYPE_P(n)
Definition array.h:263
void deconstruct_array_builtin(const ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
static Datum values[MAXATTR]
Definition bootstrap.c:190
#define pg_fallthrough
Definition c.h:220
#define PG_GETARG_DATUM(n)
Definition fmgr.h:268
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition funcapi.c:276
@ TYPEFUNC_COMPOSITE
Definition funcapi.h:149
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Definition funcapi.h:230
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1025
#define makeNode(_type_)
Definition nodes.h:159
int read_objtype_from_string(const char *objtype)
static List * textarray_to_strvaluelist(ArrayType *arr)
TypeName * typeStringToTypeName(const char *str, Node *escontext)
Definition parse_type.c:738
ObjectType
static Datum Int32GetDatum(int32 X)
Definition postgres.h:212
Float * makeFloat(char *numericStr)
Definition value.c:37
const char * type

References AccessShareLock, ObjectAddress::classId, deconstruct_array_builtin(), elog, ereport, errcode(), errmsg, ERROR, fb(), get_call_result_type(), get_object_address(), heap_form_tuple(), HeapTupleGetDatum(), i, Int32GetDatum(), lappend(), lcons(), linitial, list_length(), list_make2, makeFloat(), makeNode, name, NIL, 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, ObjectIdGetDatum(), ObjectAddress::objectSubId, pg_fallthrough, PG_GETARG_ARRAYTYPE_P, PG_GETARG_DATUM, PG_RETURN_DATUM, read_objtype_from_string(), relation_close(), textarray_to_strvaluelist(), TextDatumGetCString, type, TYPEFUNC_COMPOSITE, typeStringToTypeName(), and values.

◆ pg_identify_object()

Datum pg_identify_object ( PG_FUNCTION_ARGS  )

Definition at line 4497 of file objectaddress.c.

4498{
4499 Oid classid = PG_GETARG_OID(0);
4500 Oid objid = PG_GETARG_OID(1);
4501 int32 objsubid = PG_GETARG_INT32(2);
4503 const char *objname = NULL;
4504 char *objidentity;
4505 ObjectAddress address;
4506 Datum values[4];
4507 bool nulls[4];
4508 TupleDesc tupdesc;
4509 HeapTuple htup;
4510
4511 address.classId = classid;
4512 address.objectId = objid;
4513 address.objectSubId = objsubid;
4514
4515 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
4516 elog(ERROR, "return type must be a row type");
4517
4518 if (is_objectclass_supported(address.classId))
4519 {
4522
4525 address.objectId);
4526 if (objtup != NULL)
4527 {
4528 bool isnull;
4531
4534 {
4536 RelationGetDescr(catalog), &isnull));
4537 if (isnull)
4538 elog(ERROR, "invalid null namespace in object %u/%u/%d",
4539 address.classId, address.objectId, address.objectSubId);
4540 }
4541
4542 /*
4543 * We only return the object name if it can be used (together with
4544 * the schema name, if any) as a unique identifier.
4545 */
4547 {
4550 {
4552
4554 RelationGetDescr(catalog), &isnull);
4555 if (isnull)
4556 elog(ERROR, "invalid null name in object %u/%u/%d",
4557 address.classId, address.objectId, address.objectSubId);
4559 }
4560 }
4561 }
4562
4564 }
4565
4566 /* object type, which can never be NULL */
4568 nulls[0] = false;
4569
4570 /*
4571 * Before doing anything, extract the object identity. If the identity
4572 * could not be found, set all the fields except the object type to NULL.
4573 */
4574 objidentity = getObjectIdentity(&address, true);
4575
4576 /* schema name */
4577 if (OidIsValid(schema_oid) && objidentity)
4578 {
4579 const char *schema = quote_identifier(get_namespace_name(schema_oid));
4580
4581 values[1] = CStringGetTextDatum(schema);
4582 nulls[1] = false;
4583 }
4584 else
4585 nulls[1] = true;
4586
4587 /* object name */
4588 if (objname && objidentity)
4589 {
4590 values[2] = CStringGetTextDatum(objname);
4591 nulls[2] = false;
4592 }
4593 else
4594 nulls[2] = true;
4595
4596 /* object identity */
4597 if (objidentity)
4598 {
4599 values[3] = CStringGetTextDatum(objidentity);
4600 nulls[3] = false;
4601 }
4602 else
4603 nulls[3] = true;
4604
4605 htup = heap_form_tuple(tupdesc, values, nulls);
4606
4608}
#define CStringGetTextDatum(s)
Definition builtins.h:98
char * getObjectTypeDescription(const ObjectAddress *object, bool missing_ok)
bool get_object_namensp_unique(Oid class_id)
AttrNumber get_object_attnum_namespace(Oid class_id)
AttrNumber get_object_attnum_name(Oid class_id)
char * getObjectIdentity(const ObjectAddress *object, bool missing_ok)
bool is_objectclass_supported(Oid class_id)
static Name DatumGetName(Datum X)
Definition postgres.h:393

References AccessShareLock, ObjectAddress::classId, CStringGetTextDatum, DatumGetName(), DatumGetObjectId(), elog, ERROR, fb(), get_call_result_type(), get_catalog_object_by_oid(), get_namespace_name(), get_object_attnum_name(), get_object_attnum_namespace(), get_object_attnum_oid(), get_object_namensp_unique(), getObjectIdentity(), getObjectTypeDescription(), heap_form_tuple(), heap_getattr(), HeapTupleGetDatum(), InvalidAttrNumber, InvalidOid, is_objectclass_supported(), NameStr, ObjectAddress::objectId, ObjectAddress::objectSubId, OidIsValid, PG_GETARG_INT32, PG_GETARG_OID, PG_RETURN_DATUM, quote_identifier(), RelationGetDescr, table_close(), table_open(), TYPEFUNC_COMPOSITE, and values.

◆ pg_identify_object_as_address()

Datum pg_identify_object_as_address ( PG_FUNCTION_ARGS  )

Definition at line 4614 of file objectaddress.c.

4615{
4616 Oid classid = PG_GETARG_OID(0);
4617 Oid objid = PG_GETARG_OID(1);
4618 int32 objsubid = PG_GETARG_INT32(2);
4619 ObjectAddress address;
4620 char *identity;
4621 List *names;
4622 List *args;
4623 Datum values[3];
4624 bool nulls[3];
4625 TupleDesc tupdesc;
4626 HeapTuple htup;
4627
4628 address.classId = classid;
4629 address.objectId = objid;
4630 address.objectSubId = objsubid;
4631
4632 if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
4633 elog(ERROR, "return type must be a row type");
4634
4635 /* object type, which can never be NULL */
4637 nulls[0] = false;
4638
4639 /* object identity */
4640 identity = getObjectIdentityParts(&address, &names, &args, true);
4641 if (identity == NULL)
4642 {
4643 nulls[1] = true;
4644 nulls[2] = true;
4645 }
4646 else
4647 {
4648 pfree(identity);
4649
4650 /* object_names */
4651 if (names != NIL)
4653 else
4655 nulls[1] = false;
4656
4657 /* object_args */
4658 if (args)
4660 else
4662 nulls[2] = false;
4663 }
4664
4665 htup = heap_form_tuple(tupdesc, values, nulls);
4666
4668}
ArrayType * construct_empty_array(Oid elmtype)
ArrayType * strlist_to_textarray(List *list)
#define PointerGetDatum(X)
Definition postgres.h:354

References ObjectAddress::classId, construct_empty_array(), CStringGetTextDatum, elog, ERROR, fb(), get_call_result_type(), getObjectIdentityParts(), getObjectTypeDescription(), heap_form_tuple(), HeapTupleGetDatum(), NIL, ObjectAddress::objectId, ObjectAddress::objectSubId, pfree(), PG_GETARG_INT32, PG_GETARG_OID, PG_RETURN_DATUM, PointerGetDatum, strlist_to_textarray(), TYPEFUNC_COMPOSITE, and values.

◆ read_objtype_from_string()

int read_objtype_from_string ( const char objtype)

Definition at line 2712 of file objectaddress.c.

2713{
2714 for (size_t i = 0; i < lengthof(ObjectTypeMap); i++)
2715 {
2716 if (strcmp(ObjectTypeMap[i].tm_name, objtype) == 0)
2717 return ObjectTypeMap[i].tm_type;
2718 }
2719 ereport(ERROR,
2721 errmsg("unrecognized object type \"%s\"", objtype)));
2722
2723 return -1; /* keep compiler quiet */
2724}
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()

ArrayType * strlist_to_textarray ( List list)

Definition at line 6545 of file objectaddress.c.

6546{
6547 ArrayType *arr;
6548 Datum *datums;
6549 bool *nulls;
6550 int j = 0;
6551 ListCell *cell;
6552 MemoryContext memcxt;
6554 int lb[1];
6555
6556 /* Work in a temp context; easier than individually pfree'ing the Datums */
6558 "strlist to array",
6560 oldcxt = MemoryContextSwitchTo(memcxt);
6561
6562 datums = palloc_array(Datum, list_length(list));
6563 nulls = palloc_array(bool, list_length(list));
6564
6565 foreach(cell, list)
6566 {
6567 char *name = lfirst(cell);
6568
6569 if (name)
6570 {
6571 nulls[j] = false;
6572 datums[j++] = CStringGetTextDatum(name);
6573 }
6574 else
6575 nulls[j] = true;
6576 }
6577
6579
6580 lb[0] = 1;
6581 arr = construct_md_array(datums, nulls, 1, &j,
6582 lb, TEXTOID, -1, false, TYPALIGN_INT);
6583
6584 MemoryContextDelete(memcxt);
6585
6586 return arr;
6587}
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
#define 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

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().

◆ textarray_to_strvaluelist()

static List * textarray_to_strvaluelist ( ArrayType arr)
static

Definition at line 2184 of file objectaddress.c.

2185{
2186 Datum *elems;
2187 bool *nulls;
2188 int nelems;
2189 List *list = NIL;
2190 int i;
2191
2192 deconstruct_array_builtin(arr, TEXTOID, &elems, &nulls, &nelems);
2193
2194 for (i = 0; i < nelems; i++)
2195 {
2196 if (nulls[i])
2197 ereport(ERROR,
2199 errmsg("name or argument lists may not contain nulls")));
2200 list = lappend(list, makeString(TextDatumGetCString(elems[i])));
2201 }
2202
2203 return list;
2204}

References deconstruct_array_builtin(), ereport, errcode(), errmsg, ERROR, fb(), i, lappend(), makeString(), NIL, and TextDatumGetCString.

Referenced by pg_get_object_address().

Variable Documentation

◆ InvalidObjectAddress

◆ ObjectProperty

const ObjectPropertyType ObjectProperty[]
static

Definition at line 124 of file objectaddress.c.

125{
126 {
127 "access method",
130 AMOID,
131 AMNAME,
138 true
139 },
140 {
141 "access method operator",
152 false
153 },
154 {
155 "access method procedure",
166 false
167 },
168 {
169 "cast",
180 false
181 },
182 {
183 "collation",
186 COLLOID,
187 SYSCACHEID_INVALID, /* COLLNAMEENCNSP also takes encoding */
194 true
195 },
196 {
197 "constraint",
200 CONSTROID,
207 -1,
208 false
209 },
210 {
211 "conversion",
214 CONVOID,
222 true
223 },
224 {
225 "database",
236 true
237 },
238 {
239 "default ACL",
250 false
251 },
252 {
253 "extension",
260 InvalidAttrNumber, /* extension doesn't belong to extnamespace */
264 true
265 },
266 {
267 "foreign-data wrapper",
278 true
279 },
280 {
281 "foreign server",
292 true
293 },
294 {
295 "function",
298 PROCOID,
299 SYSCACHEID_INVALID, /* PROCNAMEARGSNSP also takes argument types */
306 false
307 },
308 {
309 "language",
312 LANGOID,
313 LANGNAME,
320 true
321 },
322 {
323 "large object metadata",
334 false
335 },
336 {
337 "operator class",
340 CLAOID,
341 SYSCACHEID_INVALID, /* CLAAMNAMENSP also takes opcmethod */
348 true
349 },
350 {
351 "operator",
354 OPEROID,
355 SYSCACHEID_INVALID, /* OPERNAMENSP also takes left and right type */
362 false
363 },
364 {
365 "operator family",
369 SYSCACHEID_INVALID, /* OPFAMILYAMNAMENSP also takes opfmethod */
376 true
377 },
378 {
379 "property graph element",
389 -1,
390 false
391 },
392 {
393 "property graph element label",
396 -1,
397 -1,
403 -1,
404 false
405 },
406 {
407 "property graph label",
417 -1,
418 false
419 },
420 {
421 "property graph label property",
424 -1,
425 -1,
431 -1,
432 false
433 },
434 {
435 "property graph property",
438 -1,
445 -1,
446 false
447 },
448 {
449 "role",
452 AUTHOID,
453 AUTHNAME,
460 true
461 },
462 {
463 "role membership",
473 -1,
474 true
475 },
476 {
477 "rule",
488 false
489 },
490 {
491 "schema",
502 true
503 },
504 {
505 "relation",
508 RELOID,
516 true
517 },
518 {
519 "tablespace",
530 true
531 },
532 {
533 "transform",
536 TRFOID,
544 false
545 },
546 {
547 "trigger",
558 false
559 },
560 {
561 "policy",
572 false
573 },
574 {
575 "event trigger",
586 true
587 },
588 {
589 "text search configuration",
600 true
601 },
602 {
603 "text search dictionary",
606 TSDICTOID,
614 true
615 },
616 {
617 "text search parser",
628 true
629 },
630 {
631 "text search template",
642 true,
643 },
644 {
645 "type",
648 TYPEOID,
656 true
657 },
658 {
659 "publication",
670 true
671 },
672 {
673 "subscription",
684 true
685 },
686 {
687 "extended statistics",
696 InvalidAttrNumber, /* no ACL (same as relation) */
698 true
699 },
700 {
701 "user mapping",
712 false
713 },
714};

Referenced by get_object_property_data(), and is_objectclass_supported().

◆ ObjectTypeMap

const struct object_type_map ObjectTypeMap[]
static