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

Go to the source code of this file.

Data Structures

struct  ObjectAddress
 

Macros

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

Typedefs

typedef struct ObjectAddress ObjectAddress
 

Functions

ObjectAddress get_object_address (ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
ObjectAddress get_object_address_rv (ObjectType objtype, RangeVar *rel, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
void check_object_ownership (Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
 
Oid get_object_namespace (const ObjectAddress *address)
 
bool is_objectclass_supported (Oid class_id)
 
const char * get_object_class_descr (Oid class_id)
 
Oid get_object_oid_index (Oid class_id)
 
int get_object_catcache_oid (Oid class_id)
 
int get_object_catcache_name (Oid class_id)
 
AttrNumber get_object_attnum_oid (Oid class_id)
 
AttrNumber get_object_attnum_name (Oid class_id)
 
AttrNumber get_object_attnum_namespace (Oid class_id)
 
AttrNumber get_object_attnum_owner (Oid class_id)
 
AttrNumber get_object_attnum_acl (Oid class_id)
 
ObjectType get_object_type (Oid class_id, Oid object_id)
 
bool get_object_namensp_unique (Oid class_id)
 
HeapTuple get_catalog_object_by_oid (Relation catalog, AttrNumber oidcol, Oid objectId)
 
char * getObjectDescription (const ObjectAddress *object, bool missing_ok)
 
char * getObjectDescriptionOids (Oid classid, Oid objid)
 
int read_objtype_from_string (const char *objtype)
 
char * getObjectTypeDescription (const ObjectAddress *object, bool missing_ok)
 
char * getObjectIdentity (const ObjectAddress *object, bool missing_ok)
 
char * getObjectIdentityParts (const ObjectAddress *object, List **objname, List **objargs, bool missing_ok)
 
struct ArrayTypestrlist_to_textarray (List *list)
 
ObjectType get_relkind_objtype (char relkind)
 

Variables

PGDLLIMPORT const ObjectAddress InvalidObjectAddress
 

Macro Definition Documentation

◆ ObjectAddressSet

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

Definition at line 40 of file objectaddress.h.

◆ ObjectAddressSubSet

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

Definition at line 33 of file objectaddress.h.

Typedef Documentation

◆ ObjectAddress

typedef struct ObjectAddress ObjectAddress

Function Documentation

◆ check_object_ownership()

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

Definition at line 2420 of file objectaddress.c.

2422 {
2423  switch (objtype)
2424  {
2425  case OBJECT_INDEX:
2426  case OBJECT_SEQUENCE:
2427  case OBJECT_TABLE:
2428  case OBJECT_VIEW:
2429  case OBJECT_MATVIEW:
2430  case OBJECT_FOREIGN_TABLE:
2431  case OBJECT_COLUMN:
2432  case OBJECT_RULE:
2433  case OBJECT_TRIGGER:
2434  case OBJECT_POLICY:
2435  case OBJECT_TABCONSTRAINT:
2436  if (!object_ownercheck(RelationRelationId, RelationGetRelid(relation), roleid))
2438  RelationGetRelationName(relation));
2439  break;
2440  case OBJECT_TYPE:
2441  case OBJECT_DOMAIN:
2442  case OBJECT_ATTRIBUTE:
2443  if (!object_ownercheck(address.classId, address.objectId, roleid))
2445  break;
2446  case OBJECT_DOMCONSTRAINT:
2447  {
2448  HeapTuple tuple;
2449  Oid contypid;
2450 
2451  tuple = SearchSysCache1(CONSTROID,
2452  ObjectIdGetDatum(address.objectId));
2453  if (!HeapTupleIsValid(tuple))
2454  elog(ERROR, "constraint with OID %u does not exist",
2455  address.objectId);
2456 
2457  contypid = ((Form_pg_constraint) GETSTRUCT(tuple))->contypid;
2458 
2459  ReleaseSysCache(tuple);
2460 
2461  /*
2462  * Fallback to type ownership check in this case as this is
2463  * what domain constraints rely on.
2464  */
2465  if (!object_ownercheck(TypeRelationId, contypid, roleid))
2467  }
2468  break;
2469  case OBJECT_AGGREGATE:
2470  case OBJECT_FUNCTION:
2471  case OBJECT_PROCEDURE:
2472  case OBJECT_ROUTINE:
2473  case OBJECT_OPERATOR:
2474  if (!object_ownercheck(address.classId, address.objectId, roleid))
2476  NameListToString((castNode(ObjectWithArgs, object))->objname));
2477  break;
2478  case OBJECT_DATABASE:
2479  case OBJECT_EVENT_TRIGGER:
2480  case OBJECT_EXTENSION:
2481  case OBJECT_FDW:
2482  case OBJECT_FOREIGN_SERVER:
2483  case OBJECT_LANGUAGE:
2484  case OBJECT_PUBLICATION:
2485  case OBJECT_SCHEMA:
2486  case OBJECT_SUBSCRIPTION:
2487  case OBJECT_TABLESPACE:
2488  if (!object_ownercheck(address.classId, address.objectId, roleid))
2490  strVal(object));
2491  break;
2492  case OBJECT_COLLATION:
2493  case OBJECT_CONVERSION:
2494  case OBJECT_OPCLASS:
2495  case OBJECT_OPFAMILY:
2496  case OBJECT_STATISTIC_EXT:
2497  case OBJECT_TSDICTIONARY:
2499  if (!object_ownercheck(address.classId, address.objectId, roleid))
2501  NameListToString(castNode(List, object)));
2502  break;
2503  case OBJECT_LARGEOBJECT:
2504  if (!lo_compat_privileges &&
2505  !object_ownercheck(address.classId, address.objectId, roleid))
2506  ereport(ERROR,
2507  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2508  errmsg("must be owner of large object %u",
2509  address.objectId)));
2510  break;
2511  case OBJECT_CAST:
2512  {
2513  /* We can only check permissions on the source/target types */
2514  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2515  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2516  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2517  Oid targettypeid = typenameTypeId(NULL, targettype);
2518 
2519  if (!object_ownercheck(TypeRelationId, sourcetypeid, roleid)
2520  && !object_ownercheck(TypeRelationId, targettypeid, roleid))
2521  ereport(ERROR,
2522  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2523  errmsg("must be owner of type %s or type %s",
2524  format_type_be(sourcetypeid),
2525  format_type_be(targettypeid))));
2526  }
2527  break;
2528  case OBJECT_TRANSFORM:
2529  {
2530  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2531  Oid typeid = typenameTypeId(NULL, typename);
2532 
2533  if (!object_ownercheck(TypeRelationId, typeid, roleid))
2535  }
2536  break;
2537  case OBJECT_ROLE:
2538 
2539  /*
2540  * We treat roles as being "owned" by those with CREATEROLE priv,
2541  * provided that they also have admin option on the role.
2542  *
2543  * However, superusers are only owned by superusers.
2544  */
2545  if (superuser_arg(address.objectId))
2546  {
2547  if (!superuser_arg(roleid))
2548  ereport(ERROR,
2549  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2550  errmsg("must be superuser")));
2551  }
2552  else
2553  {
2554  if (!has_createrole_privilege(roleid))
2555  ereport(ERROR,
2556  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2557  errmsg("must have CREATEROLE privilege")));
2558  if (!is_admin_of_role(roleid, address.objectId))
2559  ereport(ERROR,
2560  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2561  errmsg("must have admin option on role \"%s\"",
2562  GetUserNameFromId(address.objectId,
2563  true))));
2564  }
2565  break;
2566  case OBJECT_TSPARSER:
2567  case OBJECT_TSTEMPLATE:
2568  case OBJECT_ACCESS_METHOD:
2569  case OBJECT_PARAMETER_ACL:
2570  /* We treat these object types as being owned by superusers */
2571  if (!superuser_arg(roleid))
2572  ereport(ERROR,
2573  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2574  errmsg("must be superuser")));
2575  break;
2576  case OBJECT_AMOP:
2577  case OBJECT_AMPROC:
2578  case OBJECT_DEFAULT:
2579  case OBJECT_DEFACL:
2582  case OBJECT_USER_MAPPING:
2583  /* These are currently not supported or don't make sense here. */
2584  elog(ERROR, "unsupported object type: %d", (int) objtype);
2585  break;
2586  }
2587 }
bool is_admin_of_role(Oid member, Oid role)
Definition: acl.c:5099
@ ACLCHECK_NOT_OWNER
Definition: acl.h:185
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:2679
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition: aclchk.c:3984
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:2998
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:4065
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
bool lo_compat_privileges
Definition: inv_api.c:58
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:972
char * NameListToString(List *names)
Definition: namespace.c:3145
#define castNode(_type_, nodeptr)
Definition: nodes.h:186
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:291
@ OBJECT_EVENT_TRIGGER
Definition: parsenodes.h:1957
@ OBJECT_FDW
Definition: parsenodes.h:1959
@ OBJECT_TSPARSER
Definition: parsenodes.h:1990
@ OBJECT_COLLATION
Definition: parsenodes.h:1950
@ OBJECT_USER_MAPPING
Definition: parsenodes.h:1993
@ OBJECT_ACCESS_METHOD
Definition: parsenodes.h:1943
@ OBJECT_OPCLASS
Definition: parsenodes.h:1967
@ OBJECT_DEFACL
Definition: parsenodes.h:1954
@ OBJECT_AGGREGATE
Definition: parsenodes.h:1944
@ OBJECT_MATVIEW
Definition: parsenodes.h:1966
@ OBJECT_SCHEMA
Definition: parsenodes.h:1979
@ OBJECT_POLICY
Definition: parsenodes.h:1971
@ OBJECT_OPERATOR
Definition: parsenodes.h:1968
@ OBJECT_FOREIGN_TABLE
Definition: parsenodes.h:1961
@ OBJECT_TSCONFIGURATION
Definition: parsenodes.h:1988
@ OBJECT_OPFAMILY
Definition: parsenodes.h:1969
@ OBJECT_DOMAIN
Definition: parsenodes.h:1955
@ OBJECT_COLUMN
Definition: parsenodes.h:1949
@ OBJECT_TABLESPACE
Definition: parsenodes.h:1985
@ OBJECT_ROLE
Definition: parsenodes.h:1976
@ OBJECT_ROUTINE
Definition: parsenodes.h:1977
@ OBJECT_LARGEOBJECT
Definition: parsenodes.h:1965
@ OBJECT_PUBLICATION_NAMESPACE
Definition: parsenodes.h:1974
@ OBJECT_PROCEDURE
Definition: parsenodes.h:1972
@ OBJECT_EXTENSION
Definition: parsenodes.h:1958
@ OBJECT_INDEX
Definition: parsenodes.h:1963
@ OBJECT_DEFAULT
Definition: parsenodes.h:1953
@ OBJECT_DATABASE
Definition: parsenodes.h:1952
@ OBJECT_SEQUENCE
Definition: parsenodes.h:1980
@ OBJECT_TSTEMPLATE
Definition: parsenodes.h:1991
@ OBJECT_LANGUAGE
Definition: parsenodes.h:1964
@ OBJECT_AMOP
Definition: parsenodes.h:1945
@ OBJECT_PUBLICATION_REL
Definition: parsenodes.h:1975
@ OBJECT_FOREIGN_SERVER
Definition: parsenodes.h:1960
@ OBJECT_TSDICTIONARY
Definition: parsenodes.h:1989
@ OBJECT_ATTRIBUTE
Definition: parsenodes.h:1947
@ OBJECT_PUBLICATION
Definition: parsenodes.h:1973
@ OBJECT_RULE
Definition: parsenodes.h:1978
@ OBJECT_CONVERSION
Definition: parsenodes.h:1951
@ OBJECT_AMPROC
Definition: parsenodes.h:1946
@ OBJECT_TABLE
Definition: parsenodes.h:1984
@ OBJECT_VIEW
Definition: parsenodes.h:1994
@ OBJECT_PARAMETER_ACL
Definition: parsenodes.h:1970
@ OBJECT_TYPE
Definition: parsenodes.h:1992
@ OBJECT_FUNCTION
Definition: parsenodes.h:1962
@ OBJECT_TABCONSTRAINT
Definition: parsenodes.h:1983
@ OBJECT_DOMCONSTRAINT
Definition: parsenodes.h:1956
@ OBJECT_SUBSCRIPTION
Definition: parsenodes.h:1981
@ OBJECT_STATISTIC_EXT
Definition: parsenodes.h:1982
@ OBJECT_CAST
Definition: parsenodes.h:1948
@ OBJECT_TRIGGER
Definition: parsenodes.h:1987
@ OBJECT_TRANSFORM
Definition: parsenodes.h:1986
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
Definition: postgres_ext.h:31
#define RelationGetRelid(relation)
Definition: rel.h:501
#define RelationGetRelationName(relation)
Definition: rel.h:535
Definition: pg_list.h:54
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:865
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:817
@ CONSTROID
Definition: syscache.h:53
#define strVal(v)
Definition: value.h:82

References aclcheck_error(), aclcheck_error_type(), ACLCHECK_NOT_OWNER, castNode, ObjectAddress::classId, CONSTROID, elog(), ereport, errcode(), errmsg(), ERROR, 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_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 2816 of file objectaddress.c.

2817 {
2818  HeapTuple tuple;
2819  Oid classId = RelationGetRelid(catalog);
2820  int oidCacheId = get_object_catcache_oid(classId);
2821 
2822  if (oidCacheId > 0)
2823  {
2824  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2825  if (!HeapTupleIsValid(tuple)) /* should not happen */
2826  return NULL;
2827  }
2828  else
2829  {
2830  Oid oidIndexId = get_object_oid_index(classId);
2831  SysScanDesc scan;
2832  ScanKeyData skey;
2833 
2834  Assert(OidIsValid(oidIndexId));
2835 
2836  ScanKeyInit(&skey,
2837  oidcol,
2838  BTEqualStrategyNumber, F_OIDEQ,
2839  ObjectIdGetDatum(objectId));
2840 
2841  scan = systable_beginscan(catalog, oidIndexId, true,
2842  NULL, 1, &skey);
2843  tuple = systable_getnext(scan);
2844  if (!HeapTupleIsValid(tuple))
2845  {
2846  systable_endscan(scan);
2847  return NULL;
2848  }
2849  tuple = heap_copytuple(tuple);
2850 
2851  systable_endscan(scan);
2852  }
2853 
2854  return tuple;
2855 }
#define OidIsValid(objectId)
Definition: c.h:759
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:599
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:506
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:387
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:680
Assert(fmt[strlen(fmt) - 1] !='\n')
int get_object_catcache_oid(Oid class_id)
Oid get_object_oid_index(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
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:179

References Assert(), BTEqualStrategyNumber, get_object_catcache_oid(), get_object_oid_index(), heap_copytuple(), HeapTupleIsValid, ObjectIdGetDatum(), OidIsValid, RelationGetRelid, ScanKeyInit(), SearchSysCacheCopy1, systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by AlterObjectOwner_internal(), EventTriggerSQLDropAddObject(), getConstraintTypeDescription(), getObjectIdentityParts(), pg_event_trigger_ddl_commands(), and pg_identify_object().

◆ get_object_address()

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

Definition at line 960 of file objectaddress.c.

962 {
963  ObjectAddress address = {InvalidOid, InvalidOid, 0};
964  ObjectAddress old_address = {InvalidOid, InvalidOid, 0};
965  Relation relation = NULL;
966  uint64 inval_count;
967 
968  /* Some kind of lock must be taken. */
969  Assert(lockmode != NoLock);
970 
971  for (;;)
972  {
973  /*
974  * Remember this value, so that, after looking up the object name and
975  * locking it, we can check whether any invalidation messages have
976  * been processed that might require a do-over.
977  */
978  inval_count = SharedInvalidMessageCounter;
979 
980  /* Look up object address. */
981  switch (objtype)
982  {
983  case OBJECT_INDEX:
984  case OBJECT_SEQUENCE:
985  case OBJECT_TABLE:
986  case OBJECT_VIEW:
987  case OBJECT_MATVIEW:
989  address =
990  get_relation_by_qualified_name(objtype, castNode(List, object),
991  &relation, lockmode,
992  missing_ok);
993  break;
994  case OBJECT_ATTRIBUTE:
995  case OBJECT_COLUMN:
996  address =
997  get_object_address_attribute(objtype, castNode(List, object),
998  &relation, lockmode,
999  missing_ok);
1000  break;
1001  case OBJECT_DEFAULT:
1002  address =
1003  get_object_address_attrdef(objtype, castNode(List, object),
1004  &relation, lockmode,
1005  missing_ok);
1006  break;
1007  case OBJECT_RULE:
1008  case OBJECT_TRIGGER:
1009  case OBJECT_TABCONSTRAINT:
1010  case OBJECT_POLICY:
1011  address = get_object_address_relobject(objtype, castNode(List, object),
1012  &relation, missing_ok);
1013  break;
1014  case OBJECT_DOMCONSTRAINT:
1015  {
1016  List *objlist;
1017  ObjectAddress domaddr;
1018  char *constrname;
1019 
1020  objlist = castNode(List, object);
1022  linitial_node(TypeName, objlist),
1023  missing_ok);
1024  constrname = strVal(lsecond(objlist));
1025 
1026  address.classId = ConstraintRelationId;
1027  address.objectId = get_domain_constraint_oid(domaddr.objectId,
1028  constrname, missing_ok);
1029  address.objectSubId = 0;
1030  }
1031  break;
1032  case OBJECT_DATABASE:
1033  case OBJECT_EXTENSION:
1034  case OBJECT_TABLESPACE:
1035  case OBJECT_ROLE:
1036  case OBJECT_SCHEMA:
1037  case OBJECT_LANGUAGE:
1038  case OBJECT_FDW:
1039  case OBJECT_FOREIGN_SERVER:
1040  case OBJECT_EVENT_TRIGGER:
1041  case OBJECT_PARAMETER_ACL:
1042  case OBJECT_ACCESS_METHOD:
1043  case OBJECT_PUBLICATION:
1044  case OBJECT_SUBSCRIPTION:
1045  address = get_object_address_unqualified(objtype,
1046  castNode(String, object), missing_ok);
1047  break;
1048  case OBJECT_TYPE:
1049  case OBJECT_DOMAIN:
1050  address = get_object_address_type(objtype, castNode(TypeName, object), missing_ok);
1051  break;
1052  case OBJECT_AGGREGATE:
1053  case OBJECT_FUNCTION:
1054  case OBJECT_PROCEDURE:
1055  case OBJECT_ROUTINE:
1056  address.classId = ProcedureRelationId;
1057  address.objectId = LookupFuncWithArgs(objtype, castNode(ObjectWithArgs, object), missing_ok);
1058  address.objectSubId = 0;
1059  break;
1060  case OBJECT_OPERATOR:
1061  address.classId = OperatorRelationId;
1062  address.objectId = LookupOperWithArgs(castNode(ObjectWithArgs, object), missing_ok);
1063  address.objectSubId = 0;
1064  break;
1065  case OBJECT_COLLATION:
1066  address.classId = CollationRelationId;
1067  address.objectId = get_collation_oid(castNode(List, object), missing_ok);
1068  address.objectSubId = 0;
1069  break;
1070  case OBJECT_CONVERSION:
1071  address.classId = ConversionRelationId;
1072  address.objectId = get_conversion_oid(castNode(List, object), missing_ok);
1073  address.objectSubId = 0;
1074  break;
1075  case OBJECT_OPCLASS:
1076  case OBJECT_OPFAMILY:
1077  address = get_object_address_opcf(objtype, castNode(List, object), missing_ok);
1078  break;
1079  case OBJECT_AMOP:
1080  case OBJECT_AMPROC:
1081  address = get_object_address_opf_member(objtype, castNode(List, object), missing_ok);
1082  break;
1083  case OBJECT_LARGEOBJECT:
1084  address.classId = LargeObjectRelationId;
1085  address.objectId = oidparse(object);
1086  address.objectSubId = 0;
1087  if (!LargeObjectExists(address.objectId))
1088  {
1089  if (!missing_ok)
1090  ereport(ERROR,
1091  (errcode(ERRCODE_UNDEFINED_OBJECT),
1092  errmsg("large object %u does not exist",
1093  address.objectId)));
1094  }
1095  break;
1096  case OBJECT_CAST:
1097  {
1098  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
1099  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
1100  Oid sourcetypeid;
1101  Oid targettypeid;
1102 
1103  sourcetypeid = LookupTypeNameOid(NULL, sourcetype, missing_ok);
1104  targettypeid = LookupTypeNameOid(NULL, targettype, missing_ok);
1105  address.classId = CastRelationId;
1106  address.objectId =
1107  get_cast_oid(sourcetypeid, targettypeid, missing_ok);
1108  address.objectSubId = 0;
1109  }
1110  break;
1111  case OBJECT_TRANSFORM:
1112  {
1113  TypeName *typename = linitial_node(TypeName, castNode(List, object));
1114  char *langname = strVal(lsecond(castNode(List, object)));
1115  Oid type_id = LookupTypeNameOid(NULL, typename, missing_ok);
1116  Oid lang_id = get_language_oid(langname, missing_ok);
1117 
1118  address.classId = TransformRelationId;
1119  address.objectId =
1120  get_transform_oid(type_id, lang_id, missing_ok);
1121  address.objectSubId = 0;
1122  }
1123  break;
1124  case OBJECT_TSPARSER:
1125  address.classId = TSParserRelationId;
1126  address.objectId = get_ts_parser_oid(castNode(List, object), missing_ok);
1127  address.objectSubId = 0;
1128  break;
1129  case OBJECT_TSDICTIONARY:
1130  address.classId = TSDictionaryRelationId;
1131  address.objectId = get_ts_dict_oid(castNode(List, object), missing_ok);
1132  address.objectSubId = 0;
1133  break;
1134  case OBJECT_TSTEMPLATE:
1135  address.classId = TSTemplateRelationId;
1136  address.objectId = get_ts_template_oid(castNode(List, object), missing_ok);
1137  address.objectSubId = 0;
1138  break;
1140  address.classId = TSConfigRelationId;
1141  address.objectId = get_ts_config_oid(castNode(List, object), missing_ok);
1142  address.objectSubId = 0;
1143  break;
1144  case OBJECT_USER_MAPPING:
1145  address = get_object_address_usermapping(castNode(List, object),
1146  missing_ok);
1147  break;
1150  missing_ok);
1151  break;
1154  &relation,
1155  missing_ok);
1156  break;
1157  case OBJECT_DEFACL:
1158  address = get_object_address_defacl(castNode(List, object),
1159  missing_ok);
1160  break;
1161  case OBJECT_STATISTIC_EXT:
1162  address.classId = StatisticExtRelationId;
1163  address.objectId = get_statistics_object_oid(castNode(List, object),
1164  missing_ok);
1165  address.objectSubId = 0;
1166  break;
1167  /* no default, to let compiler warn about missing case */
1168  }
1169 
1170  if (!address.classId)
1171  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1172 
1173  /*
1174  * If we could not find the supplied object, return without locking.
1175  */
1176  if (!OidIsValid(address.objectId))
1177  {
1178  Assert(missing_ok);
1179  return address;
1180  }
1181 
1182  /*
1183  * If we're retrying, see if we got the same answer as last time. If
1184  * so, we're done; if not, we locked the wrong thing, so give up our
1185  * lock.
1186  */
1187  if (OidIsValid(old_address.classId))
1188  {
1189  if (old_address.classId == address.classId
1190  && old_address.objectId == address.objectId
1191  && old_address.objectSubId == address.objectSubId)
1192  break;
1193  if (old_address.classId != RelationRelationId)
1194  {
1195  if (IsSharedRelation(old_address.classId))
1196  UnlockSharedObject(old_address.classId,
1197  old_address.objectId,
1198  0, lockmode);
1199  else
1200  UnlockDatabaseObject(old_address.classId,
1201  old_address.objectId,
1202  0, lockmode);
1203  }
1204  }
1205 
1206  /*
1207  * If we're dealing with a relation or attribute, then the relation is
1208  * already locked. Otherwise, we lock it now.
1209  */
1210  if (address.classId != RelationRelationId)
1211  {
1212  if (IsSharedRelation(address.classId))
1213  LockSharedObject(address.classId, address.objectId, 0,
1214  lockmode);
1215  else
1216  LockDatabaseObject(address.classId, address.objectId, 0,
1217  lockmode);
1218  }
1219 
1220  /*
1221  * At this point, we've resolved the name to an OID and locked the
1222  * corresponding database object. However, it's possible that by the
1223  * time we acquire the lock on the object, concurrent DDL has modified
1224  * the database in such a way that the name we originally looked up no
1225  * longer resolves to that OID.
1226  *
1227  * We can be certain that this isn't an issue if (a) no shared
1228  * invalidation messages have been processed or (b) we've locked a
1229  * relation somewhere along the line. All the relation name lookups
1230  * in this module ultimately use RangeVarGetRelid() to acquire a
1231  * relation lock, and that function protects against the same kinds of
1232  * races we're worried about here. Even when operating on a
1233  * constraint, rule, or trigger, we still acquire AccessShareLock on
1234  * the relation, which is enough to freeze out any concurrent DDL.
1235  *
1236  * In all other cases, however, it's possible that the name we looked
1237  * up no longer refers to the object we locked, so we retry the lookup
1238  * and see whether we get the same answer.
1239  */
1240  if (inval_count == SharedInvalidMessageCounter || relation != NULL)
1241  break;
1242  old_address = address;
1243  }
1244 
1245  /* Return the object address and the relation. */
1246  *relp = relation;
1247  return address;
1248 }
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:245
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:1046
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1005
void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1067
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1026
#define NoLock
Definition: lockdefs.h:34
Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok)
Definition: lsyscache.c:1033
Oid get_statistics_object_oid(List *names, bool missing_ok)
Definition: namespace.c:2221
Oid get_collation_oid(List *collname, bool missing_ok)
Definition: namespace.c:3644
Oid get_conversion_oid(List *conname, bool missing_ok)
Definition: namespace.c:3698
Oid get_ts_dict_oid(List *names, bool missing_ok)
Definition: namespace.c:2469
Oid get_ts_parser_oid(List *names, bool missing_ok)
Definition: namespace.c:2343
Oid get_ts_config_oid(List *names, bool missing_ok)
Definition: namespace.c:2722
Oid get_ts_template_oid(List *names, bool missing_ok)
Definition: namespace.c:2596
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:234
Oid LookupFuncWithArgs(ObjectType objtype, ObjectWithArgs *func, bool missing_ok)
Definition: parse_func.c:2208
Oid LookupOperWithArgs(ObjectWithArgs *oper, bool noError)
Definition: parse_oper.c:145
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
Definition: postgres_ext.h:36
Oid get_language_oid(const char *langname, bool missing_ok)
Definition: proclang.c:228
uint64 SharedInvalidMessageCounter
Definition: sinval.c:26
Definition: value.h:64

References Assert(), castNode, ObjectAddress::classId, elog(), ereport, errcode(), errmsg(), ERROR, 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_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(), pg_get_object_address(), and RemoveObjects().

◆ get_object_address_rv()

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

Definition at line 1258 of file objectaddress.c.

1261 {
1262  if (rel)
1263  {
1264  object = lcons(makeString(rel->relname), object);
1265  if (rel->schemaname)
1266  object = lcons(makeString(rel->schemaname), object);
1267  if (rel->catalogname)
1268  object = lcons(makeString(rel->catalogname), object);
1269  }
1270 
1271  return get_object_address(objtype, (Node *) object,
1272  relp, lockmode, missing_ok);
1273 }
List * lcons(void *datum, List *list)
Definition: list.c:494
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
Definition: nodes.h:118
char * relname
Definition: primnodes.h:74
char * catalogname
Definition: primnodes.h:68
char * schemaname
Definition: primnodes.h:71
String * makeString(char *str)
Definition: value.c:63

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

Referenced by ExecAlterObjectDependsStmt().

◆ get_object_attnum_acl()

AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 2719 of file objectaddress.c.

2720 {
2721  const ObjectPropertyType *prop = get_object_property_data(class_id);
2722 
2723  return prop->attnum_acl;
2724 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_acl

References ObjectPropertyType::attnum_acl, and get_object_property_data().

Referenced by AlterObjectOwner_internal(), ExecGrant_common(), object_aclmask(), and recordExtObjInitPriv().

◆ get_object_attnum_name()

AttrNumber get_object_attnum_name ( Oid  class_id)

◆ get_object_attnum_namespace()

◆ get_object_attnum_oid()

AttrNumber get_object_attnum_oid ( Oid  class_id)

◆ get_object_attnum_owner()

AttrNumber get_object_attnum_owner ( Oid  class_id)

◆ get_object_catcache_name()

int get_object_catcache_name ( Oid  class_id)

Definition at line 2679 of file objectaddress.c.

2680 {
2681  const ObjectPropertyType *prop = get_object_property_data(class_id);
2682 
2683  return prop->name_catcache_id;
2684 }

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

◆ get_object_catcache_oid()

◆ get_object_class_descr()

const char* get_object_class_descr ( Oid  class_id)

Definition at line 2655 of file objectaddress.c.

2656 {
2657  const ObjectPropertyType *prop = get_object_property_data(class_id);
2658 
2659  return prop->class_descr;
2660 }
const char * class_descr

References ObjectPropertyType::class_descr, and get_object_property_data().

Referenced by DropObjectById(), ExecGrant_common(), object_aclmask(), object_ownercheck(), and recordExtObjInitPriv().

◆ get_object_namensp_unique()

bool get_object_namensp_unique ( Oid  class_id)

Definition at line 2752 of file objectaddress.c.

2753 {
2754  const ObjectPropertyType *prop = get_object_property_data(class_id);
2755 
2756  return prop->is_nsp_name_unique;
2757 }

References get_object_property_data(), and ObjectPropertyType::is_nsp_name_unique.

Referenced by EventTriggerSQLDropAddObject(), and pg_identify_object().

◆ get_object_namespace()

Oid get_object_namespace ( const ObjectAddress address)

Definition at line 2596 of file objectaddress.c.

2597 {
2598  int cache;
2599  HeapTuple tuple;
2600  bool isnull;
2601  Oid oid;
2602  const ObjectPropertyType *property;
2603 
2604  /* If not owned by a namespace, just return InvalidOid. */
2605  property = get_object_property_data(address->classId);
2606  if (property->attnum_namespace == InvalidAttrNumber)
2607  return InvalidOid;
2608 
2609  /* Currently, we can only handle object types with system caches. */
2610  cache = property->oid_catcache_id;
2611  Assert(cache != -1);
2612 
2613  /* Fetch tuple from syscache and extract namespace attribute. */
2614  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2615  if (!HeapTupleIsValid(tuple))
2616  elog(ERROR, "cache lookup failed for cache %d oid %u",
2617  cache, address->objectId);
2618  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2619  tuple,
2620  property->attnum_namespace,
2621  &isnull));
2622  Assert(!isnull);
2623  ReleaseSysCache(tuple);
2624 
2625  return oid;
2626 }
#define InvalidAttrNumber
Definition: attnum.h:23
static Oid DatumGetObjectId(Datum X)
Definition: postgres.h:242
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1078

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

Referenced by RemoveObjects().

◆ get_object_oid_index()

Oid get_object_oid_index ( Oid  class_id)

Definition at line 2663 of file objectaddress.c.

2664 {
2665  const ObjectPropertyType *prop = get_object_property_data(class_id);
2666 
2667  return prop->oid_index_oid;
2668 }

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by DropObjectById(), get_catalog_object_by_oid(), and object_ownercheck().

◆ get_object_type()

ObjectType get_object_type ( Oid  class_id,
Oid  object_id 
)

Definition at line 2734 of file objectaddress.c.

2735 {
2736  const ObjectPropertyType *prop = get_object_property_data(class_id);
2737 
2738  if (prop->objtype == OBJECT_TABLE)
2739  {
2740  /*
2741  * If the property data says it's a table, dig a little deeper to get
2742  * the real relation kind, so that callers can produce more precise
2743  * error messages.
2744  */
2745  return get_relkind_objtype(get_rel_relkind(object_id));
2746  }
2747  else
2748  return prop->objtype;
2749 }
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1985
ObjectType get_relkind_objtype(char relkind)

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

◆ get_relkind_objtype()

ObjectType get_relkind_objtype ( char  relkind)

Definition at line 6103 of file objectaddress.c.

6104 {
6105  switch (relkind)
6106  {
6107  case RELKIND_RELATION:
6108  case RELKIND_PARTITIONED_TABLE:
6109  return OBJECT_TABLE;
6110  case RELKIND_INDEX:
6111  case RELKIND_PARTITIONED_INDEX:
6112  return OBJECT_INDEX;
6113  case RELKIND_SEQUENCE:
6114  return OBJECT_SEQUENCE;
6115  case RELKIND_VIEW:
6116  return OBJECT_VIEW;
6117  case RELKIND_MATVIEW:
6118  return OBJECT_MATVIEW;
6119  case RELKIND_FOREIGN_TABLE:
6120  return OBJECT_FOREIGN_TABLE;
6121  case RELKIND_TOASTVALUE:
6122  return OBJECT_TABLE;
6123  default:
6124  /* Per above, don't raise an error */
6125  return OBJECT_TABLE;
6126  }
6127 }

References OBJECT_FOREIGN_TABLE, OBJECT_INDEX, OBJECT_MATVIEW, OBJECT_SEQUENCE, OBJECT_TABLE, and OBJECT_VIEW.

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

◆ getObjectDescription()

char* getObjectDescription ( const ObjectAddress object,
bool  missing_ok 
)

Definition at line 2913 of file objectaddress.c.

2914 {
2915  StringInfoData buffer;
2916 
2917  initStringInfo(&buffer);
2918 
2919  switch (getObjectClass(object))
2920  {
2921  case OCLASS_CLASS:
2922  if (object->objectSubId == 0)
2923  getRelationDescription(&buffer, object->objectId, missing_ok);
2924  else
2925  {
2926  /* column, not whole relation */
2927  StringInfoData rel;
2928  char *attname = get_attname(object->objectId,
2929  object->objectSubId,
2930  missing_ok);
2931 
2932  if (!attname)
2933  break;
2934 
2935  initStringInfo(&rel);
2936  getRelationDescription(&rel, object->objectId, missing_ok);
2937  /* translator: second %s is, e.g., "table %s" */
2938  appendStringInfo(&buffer, _("column %s of %s"),
2939  attname, rel.data);
2940  pfree(rel.data);
2941  }
2942  break;
2943 
2944  case OCLASS_PROC:
2945  {
2947  char *proname = format_procedure_extended(object->objectId,
2948  flags);
2949 
2950  if (proname == NULL)
2951  break;
2952 
2953  appendStringInfo(&buffer, _("function %s"), proname);
2954  break;
2955  }
2956 
2957  case OCLASS_TYPE:
2958  {
2960  char *typname = format_type_extended(object->objectId, -1,
2961  flags);
2962 
2963  if (typname == NULL)
2964  break;
2965 
2966  appendStringInfo(&buffer, _("type %s"), typname);
2967  break;
2968  }
2969 
2970  case OCLASS_CAST:
2971  {
2972  Relation castDesc;
2973  ScanKeyData skey[1];
2974  SysScanDesc rcscan;
2975  HeapTuple tup;
2976  Form_pg_cast castForm;
2977 
2978  castDesc = table_open(CastRelationId, AccessShareLock);
2979 
2980  ScanKeyInit(&skey[0],
2981  Anum_pg_cast_oid,
2982  BTEqualStrategyNumber, F_OIDEQ,
2983  ObjectIdGetDatum(object->objectId));
2984 
2985  rcscan = systable_beginscan(castDesc, CastOidIndexId, true,
2986  NULL, 1, skey);
2987 
2988  tup = systable_getnext(rcscan);
2989 
2990  if (!HeapTupleIsValid(tup))
2991  {
2992  if (!missing_ok)
2993  elog(ERROR, "could not find tuple for cast %u",
2994  object->objectId);
2995 
2996  systable_endscan(rcscan);
2997  table_close(castDesc, AccessShareLock);
2998  break;
2999  }
3000 
3001  castForm = (Form_pg_cast) GETSTRUCT(tup);
3002 
3003  appendStringInfo(&buffer, _("cast from %s to %s"),
3004  format_type_be(castForm->castsource),
3005  format_type_be(castForm->casttarget));
3006 
3007  systable_endscan(rcscan);
3008  table_close(castDesc, AccessShareLock);
3009  break;
3010  }
3011 
3012  case OCLASS_COLLATION:
3013  {
3014  HeapTuple collTup;
3015  Form_pg_collation coll;
3016  char *nspname;
3017 
3018  collTup = SearchSysCache1(COLLOID,
3019  ObjectIdGetDatum(object->objectId));
3020  if (!HeapTupleIsValid(collTup))
3021  {
3022  if (!missing_ok)
3023  elog(ERROR, "cache lookup failed for collation %u",
3024  object->objectId);
3025  break;
3026  }
3027 
3028  coll = (Form_pg_collation) GETSTRUCT(collTup);
3029 
3030  /* Qualify the name if not visible in search path */
3031  if (CollationIsVisible(object->objectId))
3032  nspname = NULL;
3033  else
3034  nspname = get_namespace_name(coll->collnamespace);
3035 
3036  appendStringInfo(&buffer, _("collation %s"),
3038  NameStr(coll->collname)));
3039  ReleaseSysCache(collTup);
3040  break;
3041  }
3042 
3043  case OCLASS_CONSTRAINT:
3044  {
3045  HeapTuple conTup;
3046  Form_pg_constraint con;
3047 
3048  conTup = SearchSysCache1(CONSTROID,
3049  ObjectIdGetDatum(object->objectId));
3050  if (!HeapTupleIsValid(conTup))
3051  {
3052  if (!missing_ok)
3053  elog(ERROR, "cache lookup failed for constraint %u",
3054  object->objectId);
3055  break;
3056  }
3057 
3058  con = (Form_pg_constraint) GETSTRUCT(conTup);
3059 
3060  if (OidIsValid(con->conrelid))
3061  {
3062  StringInfoData rel;
3063 
3064  initStringInfo(&rel);
3065  getRelationDescription(&rel, con->conrelid, false);
3066  /* translator: second %s is, e.g., "table %s" */
3067  appendStringInfo(&buffer, _("constraint %s on %s"),
3068  NameStr(con->conname), rel.data);
3069  pfree(rel.data);
3070  }
3071  else
3072  {
3073  appendStringInfo(&buffer, _("constraint %s"),
3074  NameStr(con->conname));
3075  }
3076 
3077  ReleaseSysCache(conTup);
3078  break;
3079  }
3080 
3081  case OCLASS_CONVERSION:
3082  {
3083  HeapTuple conTup;
3084  Form_pg_conversion conv;
3085  char *nspname;
3086 
3087  conTup = SearchSysCache1(CONVOID,
3088  ObjectIdGetDatum(object->objectId));
3089  if (!HeapTupleIsValid(conTup))
3090  {
3091  if (!missing_ok)
3092  elog(ERROR, "cache lookup failed for conversion %u",
3093  object->objectId);
3094  break;
3095  }
3096 
3097  conv = (Form_pg_conversion) GETSTRUCT(conTup);
3098 
3099  /* Qualify the name if not visible in search path */
3100  if (ConversionIsVisible(object->objectId))
3101  nspname = NULL;
3102  else
3103  nspname = get_namespace_name(conv->connamespace);
3104 
3105  appendStringInfo(&buffer, _("conversion %s"),
3107  NameStr(conv->conname)));
3108  ReleaseSysCache(conTup);
3109  break;
3110  }
3111 
3112  case OCLASS_DEFAULT:
3113  {
3114  ObjectAddress colobject;
3115 
3116  colobject = GetAttrDefaultColumnAddress(object->objectId);
3117 
3118  if (!OidIsValid(colobject.objectId))
3119  {
3120  if (!missing_ok)
3121  elog(ERROR, "could not find tuple for attrdef %u",
3122  object->objectId);
3123  break;
3124  }
3125 
3126  /* translator: %s is typically "column %s of table %s" */
3127  appendStringInfo(&buffer, _("default value for %s"),
3128  getObjectDescription(&colobject, false));
3129  break;
3130  }
3131 
3132  case OCLASS_LANGUAGE:
3133  {
3134  char *langname = get_language_name(object->objectId,
3135  missing_ok);
3136 
3137  if (langname)
3138  appendStringInfo(&buffer, _("language %s"),
3139  get_language_name(object->objectId, false));
3140  break;
3141  }
3142 
3143  case OCLASS_LARGEOBJECT:
3144  if (!LargeObjectExists(object->objectId))
3145  break;
3146  appendStringInfo(&buffer, _("large object %u"),
3147  object->objectId);
3148  break;
3149 
3150  case OCLASS_OPERATOR:
3151  {
3153  char *oprname = format_operator_extended(object->objectId,
3154  flags);
3155 
3156  if (oprname == NULL)
3157  break;
3158 
3159  appendStringInfo(&buffer, _("operator %s"), oprname);
3160  break;
3161  }
3162 
3163  case OCLASS_OPCLASS:
3164  {
3165  HeapTuple opcTup;
3166  Form_pg_opclass opcForm;
3167  HeapTuple amTup;
3168  Form_pg_am amForm;
3169  char *nspname;
3170 
3171  opcTup = SearchSysCache1(CLAOID,
3172  ObjectIdGetDatum(object->objectId));
3173  if (!HeapTupleIsValid(opcTup))
3174  {
3175  if (!missing_ok)
3176  elog(ERROR, "cache lookup failed for opclass %u",
3177  object->objectId);
3178  break;
3179  }
3180 
3181  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
3182 
3183  amTup = SearchSysCache1(AMOID,
3184  ObjectIdGetDatum(opcForm->opcmethod));
3185  if (!HeapTupleIsValid(amTup))
3186  elog(ERROR, "cache lookup failed for access method %u",
3187  opcForm->opcmethod);
3188  amForm = (Form_pg_am) GETSTRUCT(amTup);
3189 
3190  /* Qualify the name if not visible in search path */
3191  if (OpclassIsVisible(object->objectId))
3192  nspname = NULL;
3193  else
3194  nspname = get_namespace_name(opcForm->opcnamespace);
3195 
3196  appendStringInfo(&buffer, _("operator class %s for access method %s"),
3198  NameStr(opcForm->opcname)),
3199  NameStr(amForm->amname));
3200 
3201  ReleaseSysCache(amTup);
3202  ReleaseSysCache(opcTup);
3203  break;
3204  }
3205 
3206  case OCLASS_OPFAMILY:
3207  getOpFamilyDescription(&buffer, object->objectId, missing_ok);
3208  break;
3209 
3210  case OCLASS_AM:
3211  {
3212  HeapTuple tup;
3213 
3214  tup = SearchSysCache1(AMOID,
3215  ObjectIdGetDatum(object->objectId));
3216  if (!HeapTupleIsValid(tup))
3217  {
3218  if (!missing_ok)
3219  elog(ERROR, "cache lookup failed for access method %u",
3220  object->objectId);
3221  break;
3222  }
3223 
3224  appendStringInfo(&buffer, _("access method %s"),
3225  NameStr(((Form_pg_am) GETSTRUCT(tup))->amname));
3226  ReleaseSysCache(tup);
3227  break;
3228  }
3229 
3230  case OCLASS_AMOP:
3231  {
3232  Relation amopDesc;
3233  HeapTuple tup;
3234  ScanKeyData skey[1];
3235  SysScanDesc amscan;
3236  Form_pg_amop amopForm;
3237  StringInfoData opfam;
3238 
3239  amopDesc = table_open(AccessMethodOperatorRelationId,
3240  AccessShareLock);
3241 
3242  ScanKeyInit(&skey[0],
3243  Anum_pg_amop_oid,
3244  BTEqualStrategyNumber, F_OIDEQ,
3245  ObjectIdGetDatum(object->objectId));
3246 
3247  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
3248  NULL, 1, skey);
3249 
3250  tup = systable_getnext(amscan);
3251 
3252  if (!HeapTupleIsValid(tup))
3253  {
3254  if (!missing_ok)
3255  elog(ERROR, "could not find tuple for amop entry %u",
3256  object->objectId);
3257 
3258  systable_endscan(amscan);
3259  table_close(amopDesc, AccessShareLock);
3260  break;
3261  }
3262 
3263  amopForm = (Form_pg_amop) GETSTRUCT(tup);
3264 
3265  initStringInfo(&opfam);
3266  getOpFamilyDescription(&opfam, amopForm->amopfamily, false);
3267 
3268  /*------
3269  translator: %d is the operator strategy (a number), the
3270  first two %s's are data type names, the third %s is the
3271  description of the operator family, and the last %s is the
3272  textual form of the operator with arguments. */
3273  appendStringInfo(&buffer, _("operator %d (%s, %s) of %s: %s"),
3274  amopForm->amopstrategy,
3275  format_type_be(amopForm->amoplefttype),
3276  format_type_be(amopForm->amoprighttype),
3277  opfam.data,
3278  format_operator(amopForm->amopopr));
3279 
3280  pfree(opfam.data);
3281 
3282  systable_endscan(amscan);
3283  table_close(amopDesc, AccessShareLock);
3284  break;
3285  }
3286 
3287  case OCLASS_AMPROC:
3288  {
3289  Relation amprocDesc;
3290  ScanKeyData skey[1];
3291  SysScanDesc amscan;
3292  HeapTuple tup;
3293  Form_pg_amproc amprocForm;
3294  StringInfoData opfam;
3295 
3296  amprocDesc = table_open(AccessMethodProcedureRelationId,
3297  AccessShareLock);
3298 
3299  ScanKeyInit(&skey[0],
3300  Anum_pg_amproc_oid,
3301  BTEqualStrategyNumber, F_OIDEQ,
3302  ObjectIdGetDatum(object->objectId));
3303 
3304  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
3305  NULL, 1, skey);
3306 
3307  tup = systable_getnext(amscan);
3308 
3309  if (!HeapTupleIsValid(tup))
3310  {
3311  if (!missing_ok)
3312  elog(ERROR, "could not find tuple for amproc entry %u",
3313  object->objectId);
3314 
3315  systable_endscan(amscan);
3316  table_close(amprocDesc, AccessShareLock);
3317  break;
3318  }
3319 
3320  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
3321 
3322  initStringInfo(&opfam);
3323  getOpFamilyDescription(&opfam, amprocForm->amprocfamily, false);
3324 
3325  /*------
3326  translator: %d is the function number, the first two %s's
3327  are data type names, the third %s is the description of the
3328  operator family, and the last %s is the textual form of the
3329  function with arguments. */
3330  appendStringInfo(&buffer, _("function %d (%s, %s) of %s: %s"),
3331  amprocForm->amprocnum,
3332  format_type_be(amprocForm->amproclefttype),
3333  format_type_be(amprocForm->amprocrighttype),
3334  opfam.data,
3335  format_procedure(amprocForm->amproc));
3336 
3337  pfree(opfam.data);
3338 
3339  systable_endscan(amscan);
3340  table_close(amprocDesc, AccessShareLock);
3341  break;
3342  }
3343 
3344  case OCLASS_REWRITE:
3345  {
3346  Relation ruleDesc;
3347  ScanKeyData skey[1];
3348  SysScanDesc rcscan;
3349  HeapTuple tup;
3351  StringInfoData rel;
3352 
3353  ruleDesc = table_open(RewriteRelationId, AccessShareLock);
3354 
3355  ScanKeyInit(&skey[0],
3356  Anum_pg_rewrite_oid,
3357  BTEqualStrategyNumber, F_OIDEQ,
3358  ObjectIdGetDatum(object->objectId));
3359 
3360  rcscan = systable_beginscan(ruleDesc, RewriteOidIndexId, true,
3361  NULL, 1, skey);
3362 
3363  tup = systable_getnext(rcscan);
3364 
3365  if (!HeapTupleIsValid(tup))
3366  {
3367  if (!missing_ok)
3368  elog(ERROR, "could not find tuple for rule %u",
3369  object->objectId);
3370 
3371  systable_endscan(rcscan);
3372  table_close(ruleDesc, AccessShareLock);
3373  break;
3374  }
3375 
3376  rule = (Form_pg_rewrite) GETSTRUCT(tup);
3377 
3378  initStringInfo(&rel);
3379  getRelationDescription(&rel, rule->ev_class, false);
3380 
3381  /* translator: second %s is, e.g., "table %s" */
3382  appendStringInfo(&buffer, _("rule %s on %s"),
3383  NameStr(rule->rulename), rel.data);
3384  pfree(rel.data);
3385  systable_endscan(rcscan);
3386  table_close(ruleDesc, AccessShareLock);
3387  break;
3388  }
3389 
3390  case OCLASS_TRIGGER:
3391  {
3392  Relation trigDesc;
3393  ScanKeyData skey[1];
3394  SysScanDesc tgscan;
3395  HeapTuple tup;
3396  Form_pg_trigger trig;
3397  StringInfoData rel;
3398 
3399  trigDesc = table_open(TriggerRelationId, AccessShareLock);
3400 
3401  ScanKeyInit(&skey[0],
3402  Anum_pg_trigger_oid,
3403  BTEqualStrategyNumber, F_OIDEQ,
3404  ObjectIdGetDatum(object->objectId));
3405 
3406  tgscan = systable_beginscan(trigDesc, TriggerOidIndexId, true,
3407  NULL, 1, skey);
3408 
3409  tup = systable_getnext(tgscan);
3410 
3411  if (!HeapTupleIsValid(tup))
3412  {
3413  if (!missing_ok)
3414  elog(ERROR, "could not find tuple for trigger %u",
3415  object->objectId);
3416 
3417  systable_endscan(tgscan);
3418  table_close(trigDesc, AccessShareLock);
3419  break;
3420  }
3421 
3422  trig = (Form_pg_trigger) GETSTRUCT(tup);
3423 
3424  initStringInfo(&rel);
3425  getRelationDescription(&rel, trig->tgrelid, false);
3426 
3427  /* translator: second %s is, e.g., "table %s" */
3428  appendStringInfo(&buffer, _("trigger %s on %s"),
3429  NameStr(trig->tgname), rel.data);
3430  pfree(rel.data);
3431  systable_endscan(tgscan);
3432  table_close(trigDesc, AccessShareLock);
3433  break;
3434  }
3435 
3436  case OCLASS_SCHEMA:
3437  {
3438  char *nspname;
3439 
3440  nspname = get_namespace_name(object->objectId);
3441  if (!nspname)
3442  {
3443  if (!missing_ok)
3444  elog(ERROR, "cache lookup failed for namespace %u",
3445  object->objectId);
3446  break;
3447  }
3448  appendStringInfo(&buffer, _("schema %s"), nspname);
3449  break;
3450  }
3451 
3452  case OCLASS_STATISTIC_EXT:
3453  {
3454  HeapTuple stxTup;
3455  Form_pg_statistic_ext stxForm;
3456  char *nspname;
3457 
3458  stxTup = SearchSysCache1(STATEXTOID,
3459  ObjectIdGetDatum(object->objectId));
3460  if (!HeapTupleIsValid(stxTup))
3461  {
3462  if (!missing_ok)
3463  elog(ERROR, "could not find tuple for statistics object %u",
3464  object->objectId);
3465  break;
3466  }
3467 
3468  stxForm = (Form_pg_statistic_ext) GETSTRUCT(stxTup);
3469 
3470  /* Qualify the name if not visible in search path */
3471  if (StatisticsObjIsVisible(object->objectId))
3472  nspname = NULL;
3473  else
3474  nspname = get_namespace_name(stxForm->stxnamespace);
3475 
3476  appendStringInfo(&buffer, _("statistics object %s"),
3478  NameStr(stxForm->stxname)));
3479 
3480  ReleaseSysCache(stxTup);
3481  break;
3482  }
3483 
3484  case OCLASS_TSPARSER:
3485  {
3486  HeapTuple tup;
3487  Form_pg_ts_parser prsForm;
3488  char *nspname;
3489 
3491  ObjectIdGetDatum(object->objectId));
3492  if (!HeapTupleIsValid(tup))
3493  {
3494  if (!missing_ok)
3495  elog(ERROR, "cache lookup failed for text search parser %u",
3496  object->objectId);
3497  break;
3498  }
3499  prsForm = (Form_pg_ts_parser) GETSTRUCT(tup);
3500 
3501  /* Qualify the name if not visible in search path */
3502  if (TSParserIsVisible(object->objectId))
3503  nspname = NULL;
3504  else
3505  nspname = get_namespace_name(prsForm->prsnamespace);
3506 
3507  appendStringInfo(&buffer, _("text search parser %s"),
3509  NameStr(prsForm->prsname)));
3510  ReleaseSysCache(tup);
3511  break;
3512  }
3513 
3514  case OCLASS_TSDICT:
3515  {
3516  HeapTuple tup;
3517  Form_pg_ts_dict dictForm;
3518  char *nspname;
3519 
3520  tup = SearchSysCache1(TSDICTOID,
3521  ObjectIdGetDatum(object->objectId));
3522  if (!HeapTupleIsValid(tup))
3523  {
3524  if (!missing_ok)
3525  elog(ERROR, "cache lookup failed for text search dictionary %u",
3526  object->objectId);
3527  break;
3528  }
3529 
3530  dictForm = (Form_pg_ts_dict) GETSTRUCT(tup);
3531 
3532  /* Qualify the name if not visible in search path */
3533  if (TSDictionaryIsVisible(object->objectId))
3534  nspname = NULL;
3535  else
3536  nspname = get_namespace_name(dictForm->dictnamespace);
3537 
3538  appendStringInfo(&buffer, _("text search dictionary %s"),
3540  NameStr(dictForm->dictname)));
3541  ReleaseSysCache(tup);
3542  break;
3543  }
3544 
3545  case OCLASS_TSTEMPLATE:
3546  {
3547  HeapTuple tup;
3548  Form_pg_ts_template tmplForm;
3549  char *nspname;
3550 
3552  ObjectIdGetDatum(object->objectId));
3553  if (!HeapTupleIsValid(tup))
3554  {
3555  if (!missing_ok)
3556  elog(ERROR, "cache lookup failed for text search template %u",
3557  object->objectId);
3558  break;
3559  }
3560 
3561  tmplForm = (Form_pg_ts_template) GETSTRUCT(tup);
3562 
3563  /* Qualify the name if not visible in search path */
3564  if (TSTemplateIsVisible(object->objectId))
3565  nspname = NULL;
3566  else
3567  nspname = get_namespace_name(tmplForm->tmplnamespace);
3568 
3569  appendStringInfo(&buffer, _("text search template %s"),
3571  NameStr(tmplForm->tmplname)));
3572  ReleaseSysCache(tup);
3573  break;
3574  }
3575 
3576  case OCLASS_TSCONFIG:
3577  {
3578  HeapTuple tup;
3579  Form_pg_ts_config cfgForm;
3580  char *nspname;
3581 
3583  ObjectIdGetDatum(object->objectId));
3584  if (!HeapTupleIsValid(tup))
3585  {
3586  if (!missing_ok)
3587  elog(ERROR, "cache lookup failed for text search configuration %u",
3588  object->objectId);
3589  break;
3590  }
3591 
3592  cfgForm = (Form_pg_ts_config) GETSTRUCT(tup);
3593 
3594  /* Qualify the name if not visible in search path */
3595  if (TSConfigIsVisible(object->objectId))
3596  nspname = NULL;
3597  else
3598  nspname = get_namespace_name(cfgForm->cfgnamespace);
3599 
3600  appendStringInfo(&buffer, _("text search configuration %s"),
3602  NameStr(cfgForm->cfgname)));
3603  ReleaseSysCache(tup);
3604  break;
3605  }
3606 
3607  case OCLASS_ROLE:
3608  {
3609  char *username = GetUserNameFromId(object->objectId,
3610  missing_ok);
3611 
3612  if (username)
3613  appendStringInfo(&buffer, _("role %s"), username);
3614  break;
3615  }
3616 
3618  {
3619  Relation amDesc;
3620  ScanKeyData skey[1];
3621  SysScanDesc rcscan;
3622  HeapTuple tup;
3623  Form_pg_auth_members amForm;
3624 
3625  amDesc = table_open(AuthMemRelationId, AccessShareLock);
3626 
3627  ScanKeyInit(&skey[0],
3628  Anum_pg_auth_members_oid,
3629  BTEqualStrategyNumber, F_OIDEQ,
3630  ObjectIdGetDatum(object->objectId));
3631 
3632  rcscan = systable_beginscan(amDesc, AuthMemOidIndexId, true,
3633  NULL, 1, skey);
3634 
3635  tup = systable_getnext(rcscan);
3636 
3637  if (!HeapTupleIsValid(tup))
3638  {
3639  if (!missing_ok)
3640  elog(ERROR, "could not find tuple for role membership %u",
3641  object->objectId);
3642 
3643  systable_endscan(rcscan);
3644  table_close(amDesc, AccessShareLock);
3645  break;
3646  }
3647 
3648  amForm = (Form_pg_auth_members) GETSTRUCT(tup);
3649 
3650  appendStringInfo(&buffer, _("membership of role %s in role %s"),
3651  GetUserNameFromId(amForm->member, false),
3652  GetUserNameFromId(amForm->roleid, false));
3653 
3654  systable_endscan(rcscan);
3655  table_close(amDesc, AccessShareLock);
3656  break;
3657  }
3658 
3659  case OCLASS_DATABASE:
3660  {
3661  char *datname;
3662 
3663  datname = get_database_name(object->objectId);
3664  if (!datname)
3665  {
3666  if (!missing_ok)
3667  elog(ERROR, "cache lookup failed for database %u",
3668  object->objectId);
3669  break;
3670  }
3671  appendStringInfo(&buffer, _("database %s"), datname);
3672  break;
3673  }
3674 
3675  case OCLASS_TBLSPACE:
3676  {
3677  char *tblspace;
3678 
3679  tblspace = get_tablespace_name(object->objectId);
3680  if (!tblspace)
3681  {
3682  if (!missing_ok)
3683  elog(ERROR, "cache lookup failed for tablespace %u",
3684  object->objectId);
3685  break;
3686  }
3687  appendStringInfo(&buffer, _("tablespace %s"), tblspace);
3688  break;
3689  }
3690 
3691  case OCLASS_FDW:
3692  {
3693  ForeignDataWrapper *fdw;
3694 
3696  missing_ok);
3697  if (fdw)
3698  appendStringInfo(&buffer, _("foreign-data wrapper %s"), fdw->fdwname);
3699  break;
3700  }
3701 
3702  case OCLASS_FOREIGN_SERVER:
3703  {
3704  ForeignServer *srv;
3705 
3706  srv = GetForeignServerExtended(object->objectId, missing_ok);
3707  if (srv)
3708  appendStringInfo(&buffer, _("server %s"), srv->servername);
3709  break;
3710  }
3711 
3712  case OCLASS_USER_MAPPING:
3713  {
3714  HeapTuple tup;
3715  Oid useid;
3716  char *usename;
3717  Form_pg_user_mapping umform;
3718  ForeignServer *srv;
3719 
3721  ObjectIdGetDatum(object->objectId));
3722  if (!HeapTupleIsValid(tup))
3723  {
3724  if (!missing_ok)
3725  elog(ERROR, "cache lookup failed for user mapping %u",
3726  object->objectId);
3727  break;
3728  }
3729 
3730  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
3731  useid = umform->umuser;
3732  srv = GetForeignServer(umform->umserver);
3733 
3734  ReleaseSysCache(tup);
3735 
3736  if (OidIsValid(useid))
3737  usename = GetUserNameFromId(useid, false);
3738  else
3739  usename = "public";
3740 
3741  appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
3742  srv->servername);
3743  break;
3744  }
3745 
3746  case OCLASS_DEFACL:
3747  {
3748  Relation defaclrel;
3749  ScanKeyData skey[1];
3750  SysScanDesc rcscan;
3751  HeapTuple tup;
3752  Form_pg_default_acl defacl;
3753  char *rolename;
3754  char *nspname;
3755 
3756  defaclrel = table_open(DefaultAclRelationId, AccessShareLock);
3757 
3758  ScanKeyInit(&skey[0],
3759  Anum_pg_default_acl_oid,
3760  BTEqualStrategyNumber, F_OIDEQ,
3761  ObjectIdGetDatum(object->objectId));
3762 
3763  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
3764  true, NULL, 1, skey);
3765 
3766  tup = systable_getnext(rcscan);
3767 
3768  if (!HeapTupleIsValid(tup))
3769  {
3770  if (!missing_ok)
3771  elog(ERROR, "could not find tuple for default ACL %u",
3772  object->objectId);
3773 
3774  systable_endscan(rcscan);
3775  table_close(defaclrel, AccessShareLock);
3776  break;
3777  }
3778 
3779  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
3780 
3781  rolename = GetUserNameFromId(defacl->defaclrole, false);
3782 
3783  if (OidIsValid(defacl->defaclnamespace))
3784  nspname = get_namespace_name(defacl->defaclnamespace);
3785  else
3786  nspname = NULL;
3787 
3788  switch (defacl->defaclobjtype)
3789  {
3790  case DEFACLOBJ_RELATION:
3791  if (nspname)
3792  appendStringInfo(&buffer,
3793  _("default privileges on new relations belonging to role %s in schema %s"),
3794  rolename, nspname);
3795  else
3796  appendStringInfo(&buffer,
3797  _("default privileges on new relations belonging to role %s"),
3798  rolename);
3799  break;
3800  case DEFACLOBJ_SEQUENCE:
3801  if (nspname)
3802  appendStringInfo(&buffer,
3803  _("default privileges on new sequences belonging to role %s in schema %s"),
3804  rolename, nspname);
3805  else
3806  appendStringInfo(&buffer,
3807  _("default privileges on new sequences belonging to role %s"),
3808  rolename);
3809  break;
3810  case DEFACLOBJ_FUNCTION:
3811  if (nspname)
3812  appendStringInfo(&buffer,
3813  _("default privileges on new functions belonging to role %s in schema %s"),
3814  rolename, nspname);
3815  else
3816  appendStringInfo(&buffer,
3817  _("default privileges on new functions belonging to role %s"),
3818  rolename);
3819  break;
3820  case DEFACLOBJ_TYPE:
3821  if (nspname)
3822  appendStringInfo(&buffer,
3823  _("default privileges on new types belonging to role %s in schema %s"),
3824  rolename, nspname);
3825  else
3826  appendStringInfo(&buffer,
3827  _("default privileges on new types belonging to role %s"),
3828  rolename);
3829  break;
3830  case DEFACLOBJ_NAMESPACE:
3831  Assert(!nspname);
3832  appendStringInfo(&buffer,
3833  _("default privileges on new schemas belonging to role %s"),
3834  rolename);
3835  break;
3836  default:
3837  /* shouldn't get here */
3838  if (nspname)
3839  appendStringInfo(&buffer,
3840  _("default privileges belonging to role %s in schema %s"),
3841  rolename, nspname);
3842  else
3843  appendStringInfo(&buffer,
3844  _("default privileges belonging to role %s"),
3845  rolename);
3846  break;
3847  }
3848 
3849  systable_endscan(rcscan);
3850  table_close(defaclrel, AccessShareLock);
3851  break;
3852  }
3853 
3854  case OCLASS_EXTENSION:
3855  {
3856  char *extname;
3857 
3858  extname = get_extension_name(object->objectId);
3859  if (!extname)
3860  {
3861  if (!missing_ok)
3862  elog(ERROR, "cache lookup failed for extension %u",
3863  object->objectId);
3864  break;
3865  }
3866  appendStringInfo(&buffer, _("extension %s"), extname);
3867  break;
3868  }
3869 
3870  case OCLASS_EVENT_TRIGGER:
3871  {
3872  HeapTuple tup;
3873 
3875  ObjectIdGetDatum(object->objectId));
3876  if (!HeapTupleIsValid(tup))
3877  {
3878  if (!missing_ok)
3879  elog(ERROR, "cache lookup failed for event trigger %u",
3880  object->objectId);
3881  break;
3882  }
3883  appendStringInfo(&buffer, _("event trigger %s"),
3884  NameStr(((Form_pg_event_trigger) GETSTRUCT(tup))->evtname));
3885  ReleaseSysCache(tup);
3886  break;
3887  }
3888 
3889  case OCLASS_PARAMETER_ACL:
3890  {
3891  HeapTuple tup;
3892  Datum nameDatum;
3893  bool isNull;
3894  char *parname;
3895 
3897  ObjectIdGetDatum(object->objectId));
3898  if (!HeapTupleIsValid(tup))
3899  {
3900  if (!missing_ok)
3901  elog(ERROR, "cache lookup failed for parameter ACL %u",
3902  object->objectId);
3903  break;
3904  }
3905  nameDatum = SysCacheGetAttr(PARAMETERACLOID, tup,
3906  Anum_pg_parameter_acl_parname,
3907  &isNull);
3908  Assert(!isNull);
3909  parname = TextDatumGetCString(nameDatum);
3910  appendStringInfo(&buffer, _("parameter %s"), parname);
3911  ReleaseSysCache(tup);
3912  break;
3913  }
3914 
3915  case OCLASS_POLICY:
3916  {
3917  Relation policy_rel;
3918  ScanKeyData skey[1];
3919  SysScanDesc sscan;
3920  HeapTuple tuple;
3921  Form_pg_policy form_policy;
3922  StringInfoData rel;
3923 
3924  policy_rel = table_open(PolicyRelationId, AccessShareLock);
3925 
3926  ScanKeyInit(&skey[0],
3927  Anum_pg_policy_oid,
3928  BTEqualStrategyNumber, F_OIDEQ,
3929  ObjectIdGetDatum(object->objectId));
3930 
3931  sscan = systable_beginscan(policy_rel, PolicyOidIndexId,
3932  true, NULL, 1, skey);
3933 
3934  tuple = systable_getnext(sscan);
3935 
3936  if (!HeapTupleIsValid(tuple))
3937  {
3938  if (!missing_ok)
3939  elog(ERROR, "could not find tuple for policy %u",
3940  object->objectId);
3941 
3942  systable_endscan(sscan);
3943  table_close(policy_rel, AccessShareLock);
3944  break;
3945  }
3946 
3947  form_policy = (Form_pg_policy) GETSTRUCT(tuple);
3948 
3949  initStringInfo(&rel);
3950  getRelationDescription(&rel, form_policy->polrelid, false);
3951 
3952  /* translator: second %s is, e.g., "table %s" */
3953  appendStringInfo(&buffer, _("policy %s on %s"),
3954  NameStr(form_policy->polname), rel.data);
3955  pfree(rel.data);
3956  systable_endscan(sscan);
3957  table_close(policy_rel, AccessShareLock);
3958  break;
3959  }
3960 
3961  case OCLASS_PUBLICATION:
3962  {
3963  char *pubname = get_publication_name(object->objectId,
3964  missing_ok);
3965 
3966  if (pubname)
3967  appendStringInfo(&buffer, _("publication %s"), pubname);
3968  break;
3969  }
3970 
3972  {
3973  char *pubname;
3974  char *nspname;
3975 
3976  if (!getPublicationSchemaInfo(object, missing_ok,
3977  &pubname, &nspname))
3978  break;
3979 
3980  appendStringInfo(&buffer, _("publication of schema %s in publication %s"),
3981  nspname, pubname);
3982  pfree(pubname);
3983  pfree(nspname);
3984  break;
3985  }
3986 
3988  {
3989  HeapTuple tup;
3990  char *pubname;
3991  Form_pg_publication_rel prform;
3992  StringInfoData rel;
3993 
3995  ObjectIdGetDatum(object->objectId));
3996  if (!HeapTupleIsValid(tup))
3997  {
3998  if (!missing_ok)
3999  elog(ERROR, "cache lookup failed for publication table %u",
4000  object->objectId);
4001  break;
4002  }
4003 
4004  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
4005  pubname = get_publication_name(prform->prpubid, false);
4006 
4007  initStringInfo(&rel);
4008  getRelationDescription(&rel, prform->prrelid, false);
4009 
4010  /* translator: first %s is, e.g., "table %s" */
4011  appendStringInfo(&buffer, _("publication of %s in publication %s"),
4012  rel.data, pubname);
4013  pfree(rel.data);
4014  ReleaseSysCache(tup);
4015  break;
4016  }
4017 
4018  case OCLASS_SUBSCRIPTION:
4019  {
4020  char *subname = get_subscription_name(object->objectId,
4021  missing_ok);
4022 
4023  if (subname)
4024  appendStringInfo(&buffer, _("subscription %s"), subname);
4025  break;
4026  }
4027 
4028  case OCLASS_TRANSFORM:
4029  {
4030  HeapTuple trfTup;
4031  Form_pg_transform trfForm;
4032 
4033  trfTup = SearchSysCache1(TRFOID,
4034  ObjectIdGetDatum(object->objectId));
4035  if (!HeapTupleIsValid(trfTup))
4036  {
4037  if (!missing_ok)
4038  elog(ERROR, "could not find tuple for transform %u",
4039  object->objectId);
4040  break;
4041  }
4042 
4043  trfForm = (Form_pg_transform) GETSTRUCT(trfTup);
4044 
4045  appendStringInfo(&buffer, _("transform for %s language %s"),
4046  format_type_be(trfForm->trftype),
4047  get_language_name(trfForm->trflang, false));
4048 
4049  ReleaseSysCache(trfTup);
4050  break;
4051  }
4052 
4053  /*
4054  * There's intentionally no default: case here; we want the
4055  * compiler to warn if a new OCLASS hasn't been handled above.
4056  */
4057  }
4058 
4059  /* an empty buffer is equivalent to no object found */
4060  if (buffer.len == 0)
4061  return NULL;
4062 
4063  return buffer.data;
4064 }
char * get_tablespace_name(Oid spc_oid)
Definition: tablespace.c:1478
#define TextDatumGetCString(d)
Definition: builtins.h:95
#define FORMAT_TYPE_INVALID_AS_NULL
Definition: builtins.h:124
#define NameStr(name)
Definition: c.h:730
uint16 bits16
Definition: c.h:498
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2980
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2836
@ OCLASS_OPERATOR
Definition: dependency.h:100
@ OCLASS_PARAMETER_ACL
Definition: dependency.h:124
@ OCLASS_LARGEOBJECT
Definition: dependency.h:99
@ OCLASS_FDW
Definition: dependency.h:118
@ OCLASS_OPFAMILY
Definition: dependency.h:102
@ OCLASS_DEFACL
Definition: dependency.h:121
@ OCLASS_TSPARSER
Definition: dependency.h:110
@ OCLASS_TRIGGER
Definition: dependency.h:107
@ OCLASS_DEFAULT
Definition: dependency.h:97
@ OCLASS_TSTEMPLATE
Definition: dependency.h:112
@ OCLASS_AMPROC
Definition: dependency.h:105
@ OCLASS_TBLSPACE
Definition: dependency.h:117
@ OCLASS_TSCONFIG
Definition: dependency.h:113
@ OCLASS_TYPE
Definition: dependency.h:92
@ OCLASS_LANGUAGE
Definition: dependency.h:98
@ OCLASS_CAST
Definition: dependency.h:93
@ OCLASS_SUBSCRIPTION
Definition: dependency.h:129
@ OCLASS_PUBLICATION_NAMESPACE
Definition: dependency.h:127
@ OCLASS_EXTENSION
Definition: dependency.h:122
@ OCLASS_COLLATION
Definition: dependency.h:94
@ OCLASS_FOREIGN_SERVER
Definition: dependency.h:119
@ OCLASS_REWRITE
Definition: dependency.h:106
@ OCLASS_STATISTIC_EXT
Definition: dependency.h:109
@ OCLASS_PROC
Definition: dependency.h:91
@ OCLASS_OPCLASS
Definition: dependency.h:101
@ OCLASS_CONVERSION
Definition: dependency.h:96
@ OCLASS_DATABASE
Definition: dependency.h:116
@ OCLASS_ROLE_MEMBERSHIP
Definition: dependency.h:115
@ OCLASS_SCHEMA
Definition: dependency.h:108
@ OCLASS_EVENT_TRIGGER
Definition: dependency.h:123
@ OCLASS_CLASS
Definition: dependency.h:90
@ OCLASS_TRANSFORM
Definition: dependency.h:130
@ OCLASS_ROLE
Definition: dependency.h:114
@ OCLASS_CONSTRAINT
Definition: dependency.h:95
@ OCLASS_POLICY
Definition: dependency.h:125
@ OCLASS_USER_MAPPING
Definition: dependency.h:120
@ OCLASS_PUBLICATION_REL
Definition: dependency.h:128
@ OCLASS_AM
Definition: dependency.h:103
@ OCLASS_TSDICT
Definition: dependency.h:111
@ OCLASS_PUBLICATION
Definition: dependency.h:126
@ OCLASS_AMOP
Definition: dependency.h:104
#define _(x)
Definition: elog.c:91
char * get_extension_name(Oid ext_oid)
Definition: extension.c:187
ForeignServer * GetForeignServerExtended(Oid serverid, bits16 flags)
Definition: foreign.c:123
ForeignDataWrapper * GetForeignDataWrapperExtended(Oid fdwid, bits16 flags)
Definition: foreign.c:49
ForeignServer * GetForeignServer(Oid serverid)
Definition: foreign.c:111
char * format_type_extended(Oid type_oid, int32 typemod, bits16 flags)
Definition: format_type.c:112
#define AccessShareLock
Definition: lockdefs.h:36
char * get_language_name(Oid langoid, bool missing_ok)
Definition: lsyscache.c:1165
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3331
char * get_publication_name(Oid pubid, bool missing_ok)
Definition: lsyscache.c:3614
char * get_subscription_name(Oid subid, bool missing_ok)
Definition: lsyscache.c:3664
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition: lsyscache.c:826
void pfree(void *pointer)
Definition: mcxt.c:1436
bool TSTemplateIsVisible(Oid tmplId)
Definition: namespace.c:2654
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2091
bool ConversionIsVisible(Oid conid)
Definition: namespace.c:2174
bool OpclassIsVisible(Oid opcid)
Definition: namespace.c:1876
bool StatisticsObjIsVisible(Oid relid)
Definition: namespace.c:2278
bool TSParserIsVisible(Oid prsId)
Definition: namespace.c:2401
bool TSConfigIsVisible(Oid cfgid)
Definition: namespace.c:2780
bool TSDictionaryIsVisible(Oid dictId)
Definition: namespace.c:2527
static void getRelationDescription(StringInfo buffer, Oid relid, bool missing_ok)
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
static bool getPublicationSchemaInfo(const ObjectAddress *object, bool missing_ok, char **pubname, char **nspname)
static void getOpFamilyDescription(StringInfo buffer, Oid opfid, bool missing_ok)
FormData_pg_am * Form_pg_am
Definition: pg_am.h:48
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:88
FormData_pg_amproc * Form_pg_amproc
Definition: pg_amproc.h:68
ObjectAddress GetAttrDefaultColumnAddress(Oid attrdefoid)
Definition: pg_attrdef.c:381
NameData attname
Definition: pg_attribute.h:41
FormData_pg_auth_members * Form_pg_auth_members
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:57
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:57
FormData_pg_conversion * Form_pg_conversion
Definition: pg_conversion.h:61
NameData datname
Definition: pg_database.h:35
FormData_pg_default_acl * Form_pg_default_acl
FormData_pg_event_trigger * Form_pg_event_trigger
FormData_pg_opclass * Form_pg_opclass
Definition: pg_opclass.h:83
FormData_pg_policy * Form_pg_policy
Definition: pg_policy.h:51
NameData proname
Definition: pg_proc.h:35
FormData_pg_publication_rel * Form_pg_publication_rel
FormData_pg_rewrite * Form_pg_rewrite
Definition: pg_rewrite.h:52
FormData_pg_statistic_ext * Form_pg_statistic_ext
NameData subname
FormData_pg_transform * Form_pg_transform
Definition: pg_transform.h:43
FormData_pg_trigger * Form_pg_trigger
Definition: pg_trigger.h:80
FormData_pg_ts_config * Form_pg_ts_config
Definition: pg_ts_config.h:48
FormData_pg_ts_dict * Form_pg_ts_dict
Definition: pg_ts_dict.h:52
FormData_pg_ts_parser * Form_pg_ts_parser
Definition: pg_ts_parser.h:55
FormData_pg_ts_template * Form_pg_ts_template
NameData typname
Definition: pg_type.h:41
FormData_pg_user_mapping * Form_pg_user_mapping
const char * username
Definition: pgbench.c:306
uintptr_t Datum
Definition: postgres.h:64
char * format_operator(Oid operator_oid)
Definition: regproc.c:793
char * format_procedure(Oid procedure_oid)
Definition: regproc.c:299
char * format_operator_extended(Oid operator_oid, bits16 flags)
Definition: regproc.c:722
char * format_procedure_extended(Oid procedure_oid, bits16 flags)
Definition: regproc.c:326
#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)
Definition: ruleutils.c:11613
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
char * fdwname
Definition: foreign.h:28
char * servername
Definition: foreign.h:39
Definition: localtime.c:73
@ PARAMETERACLOID
Definition: syscache.h:76
@ TSTEMPLATEOID
Definition: syscache.h:112
@ TSDICTOID
Definition: syscache.h:108
@ PUBLICATIONREL
Definition: syscache.h:84
@ STATEXTOID
Definition: syscache.h:96
@ AMOID
Definition: syscache.h:36
@ EVENTTRIGGEROID
Definition: syscache.h:60
@ CONVOID
Definition: syscache.h:54
@ COLLOID
Definition: syscache.h:50
@ TRFOID
Definition: syscache.h:102
@ CLAOID
Definition: syscache.h:48
@ USERMAPPINGOID
Definition: syscache.h:115
@ TSPARSEROID
Definition: syscache.h:110
@ TSCONFIGOID
Definition: syscache.h:106
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40

References _, AccessShareLock, AMOID, appendStringInfo(), Assert(), attname, BTEqualStrategyNumber, CLAOID, CollationIsVisible(), COLLOID, CONSTROID, ConversionIsVisible(), CONVOID, StringInfoData::data, datname, elog(), ERROR, EVENTTRIGGEROID, ForeignDataWrapper::fdwname, format_operator(), format_operator_extended(), FORMAT_OPERATOR_INVALID_AS_NULL, FORMAT_PROC_INVALID_AS_NULL, format_procedure(), format_procedure_extended(), format_type_be(), format_type_extended(), FORMAT_TYPE_INVALID_AS_NULL, get_attname(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name(), get_publication_name(), get_subscription_name(), get_tablespace_name(), GetAttrDefaultColumnAddress(), GetForeignDataWrapperExtended(), GetForeignServer(), GetForeignServerExtended(), getObjectClass(), getOpFamilyDescription(), getPublicationSchemaInfo(), getRelationDescription(), GETSTRUCT, GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), LargeObjectExists(), StringInfoData::len, NameStr, ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, OCLASS_AM, OCLASS_AMOP, OCLASS_AMPROC, OCLASS_CAST, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONSTRAINT, OCLASS_CONVERSION, OCLASS_DATABASE, OCLASS_DEFACL, OCLASS_DEFAULT, OCLASS_EVENT_TRIGGER, OCLASS_EXTENSION, OCLASS_FDW, OCLASS_FOREIGN_SERVER, OCLASS_LANGUAGE, OCLASS_LARGEOBJECT, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_PARAMETER_ACL, OCLASS_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_NAMESPACE, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, OCLASS_ROLE_MEMBERSHIP, OCLASS_SCHEMA, OCLASS_STATISTIC_EXT, OCLASS_SUBSCRIPTION, OCLASS_TBLSPACE, OCLASS_TRANSFORM, OCLASS_TRIGGER, OCLASS_TSCONFIG, OCLASS_TSDICT, OCLASS_TSPARSER, OCLASS_TSTEMPLATE, OCLASS_TYPE, OCLASS_USER_MAPPING, OidIsValid, OpclassIsVisible(), PARAMETERACLOID, pfree(), proname, PUBLICATIONREL, quote_qualified_identifier(), ReleaseSysCache(), ScanKeyInit(), SearchSysCache1(), ForeignServer::servername, STATEXTOID, StatisticsObjIsVisible(), subname, SysCacheGetAttr(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TextDatumGetCString, TRFOID, TSConfigIsVisible(), TSCONFIGOID, TSDictionaryIsVisible(), TSDICTOID, TSParserIsVisible(), TSPARSEROID, TSTemplateIsVisible(), TSTEMPLATEOID, typname, USERMAPPINGOID, and username.

Referenced by AlterExtensionNamespace(), ATExecAlterColumnType(), changeDependenciesOn(), check_relation_privileges(), checkMembershipInCurrentExtension(), checkSharedDependencies(), ExecAlterExtensionContentsStmt(), findDependentObjects(), get_altertable_subcmdinfo(), get_object_address_opf_member(), getObjectDescriptionOids(), pg_describe_object(), recordDependencyOnCurrentExtension(), reportDependentObjects(), sepgsql_fmgr_hook(), shdepDropOwned(), shdepReassignOwned(), and storeObjectDescription().

◆ getObjectDescriptionOids()

char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 4070 of file objectaddress.c.

4071 {
4072  ObjectAddress address;
4073 
4074  address.classId = classid;
4075  address.objectId = objid;
4076  address.objectSubId = 0;
4077 
4078  return getObjectDescription(&address, false);
4079 }

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

4759 {
4760  StringInfoData buffer;
4761 
4762  initStringInfo(&buffer);
4763 
4764  /*
4765  * Make sure that both objname and objargs were passed, or none was; and
4766  * initialize them to empty lists. For objname this is useless because it
4767  * will be initialized in all cases inside the switch; but we do it anyway
4768  * so that we can test below that no branch leaves it unset.
4769  */
4770  Assert(PointerIsValid(objname) == PointerIsValid(objargs));
4771  if (objname)
4772  {
4773  *objname = NIL;
4774  *objargs = NIL;
4775  }
4776 
4777  switch (getObjectClass(object))
4778  {
4779  case OCLASS_CLASS:
4780  {
4781  char *attr = NULL;
4782 
4783  /*
4784  * Check for the attribute first, so as if it is missing we
4785  * can skip the entire relation description.
4786  */
4787  if (object->objectSubId != 0)
4788  {
4789  attr = get_attname(object->objectId,
4790  object->objectSubId,
4791  missing_ok);
4792 
4793  if (missing_ok && attr == NULL)
4794  break;
4795  }
4796 
4797  getRelationIdentity(&buffer, object->objectId, objname,
4798  missing_ok);
4799  if (objname && *objname == NIL)
4800  break;
4801 
4802  if (attr)
4803  {
4804  appendStringInfo(&buffer, ".%s",
4805  quote_identifier(attr));
4806  if (objname)
4807  *objname = lappend(*objname, attr);
4808  }
4809  }
4810  break;
4811 
4812  case OCLASS_PROC:
4813  {
4815  char *proname = format_procedure_extended(object->objectId,
4816  flags);
4817 
4818  if (proname == NULL)
4819  break;
4820 
4821  appendStringInfoString(&buffer, proname);
4822  if (objname)
4823  format_procedure_parts(object->objectId, objname, objargs,
4824  missing_ok);
4825  break;
4826  }
4827 
4828  case OCLASS_TYPE:
4829  {
4831  char *typeout;
4832 
4833  typeout = format_type_extended(object->objectId, -1, flags);
4834 
4835  if (typeout == NULL)
4836  break;
4837 
4838  appendStringInfoString(&buffer, typeout);
4839  if (objname)
4840  *objname = list_make1(typeout);
4841  }
4842  break;
4843 
4844  case OCLASS_CAST:
4845  {
4846  Relation castRel;
4847  HeapTuple tup;
4848  Form_pg_cast castForm;
4849 
4850  castRel = table_open(CastRelationId, AccessShareLock);
4851 
4852  tup = get_catalog_object_by_oid(castRel, Anum_pg_cast_oid,
4853  object->objectId);
4854 
4855  if (!HeapTupleIsValid(tup))
4856  {
4857  if (!missing_ok)
4858  elog(ERROR, "could not find tuple for cast %u",
4859  object->objectId);
4860 
4861  table_close(castRel, AccessShareLock);
4862  break;
4863  }
4864 
4865  castForm = (Form_pg_cast) GETSTRUCT(tup);
4866 
4867  appendStringInfo(&buffer, "(%s AS %s)",
4868  format_type_be_qualified(castForm->castsource),
4869  format_type_be_qualified(castForm->casttarget));
4870 
4871  if (objname)
4872  {
4873  *objname = list_make1(format_type_be_qualified(castForm->castsource));
4874  *objargs = list_make1(format_type_be_qualified(castForm->casttarget));
4875  }
4876 
4877  table_close(castRel, AccessShareLock);
4878  break;
4879  }
4880 
4881  case OCLASS_COLLATION:
4882  {
4883  HeapTuple collTup;
4884  Form_pg_collation coll;
4885  char *schema;
4886 
4887  collTup = SearchSysCache1(COLLOID,
4888  ObjectIdGetDatum(object->objectId));
4889  if (!HeapTupleIsValid(collTup))
4890  {
4891  if (!missing_ok)
4892  elog(ERROR, "cache lookup failed for collation %u",
4893  object->objectId);
4894  break;
4895  }
4896  coll = (Form_pg_collation) GETSTRUCT(collTup);
4897  schema = get_namespace_name_or_temp(coll->collnamespace);
4898  appendStringInfoString(&buffer,
4900  NameStr(coll->collname)));
4901  if (objname)
4902  *objname = list_make2(schema,
4903  pstrdup(NameStr(coll->collname)));
4904  ReleaseSysCache(collTup);
4905  break;
4906  }
4907 
4908  case OCLASS_CONSTRAINT:
4909  {
4910  HeapTuple conTup;
4911  Form_pg_constraint con;
4912 
4913  conTup = SearchSysCache1(CONSTROID,
4914  ObjectIdGetDatum(object->objectId));
4915  if (!HeapTupleIsValid(conTup))
4916  {
4917  if (!missing_ok)
4918  elog(ERROR, "cache lookup failed for constraint %u",
4919  object->objectId);
4920  break;
4921  }
4922  con = (Form_pg_constraint) GETSTRUCT(conTup);
4923 
4924  if (OidIsValid(con->conrelid))
4925  {
4926  appendStringInfo(&buffer, "%s on ",
4927  quote_identifier(NameStr(con->conname)));
4928  getRelationIdentity(&buffer, con->conrelid, objname,
4929  false);
4930  if (objname)
4931  *objname = lappend(*objname, pstrdup(NameStr(con->conname)));
4932  }
4933  else
4934  {
4935  ObjectAddress domain;
4936 
4937  Assert(OidIsValid(con->contypid));
4938  domain.classId = TypeRelationId;
4939  domain.objectId = con->contypid;
4940  domain.objectSubId = 0;
4941 
4942  appendStringInfo(&buffer, "%s on %s",
4943  quote_identifier(NameStr(con->conname)),
4944  getObjectIdentityParts(&domain, objname,
4945  objargs, false));
4946 
4947  if (objname)
4948  *objargs = lappend(*objargs, pstrdup(NameStr(con->conname)));
4949  }
4950 
4951  ReleaseSysCache(conTup);
4952  break;
4953  }
4954 
4955  case OCLASS_CONVERSION:
4956  {
4957  HeapTuple conTup;
4958  Form_pg_conversion conForm;
4959  char *schema;
4960 
4961  conTup = SearchSysCache1(CONVOID,
4962  ObjectIdGetDatum(object->objectId));
4963  if (!HeapTupleIsValid(conTup))
4964  {
4965  if (!missing_ok)
4966  elog(ERROR, "cache lookup failed for conversion %u",
4967  object->objectId);
4968  break;
4969  }
4970  conForm = (Form_pg_conversion) GETSTRUCT(conTup);
4971  schema = get_namespace_name_or_temp(conForm->connamespace);
4972  appendStringInfoString(&buffer,
4974  NameStr(conForm->conname)));
4975  if (objname)
4976  *objname = list_make2(schema,
4977  pstrdup(NameStr(conForm->conname)));
4978  ReleaseSysCache(conTup);
4979  break;
4980  }
4981 
4982  case OCLASS_DEFAULT:
4983  {
4984  ObjectAddress colobject;
4985 
4986  colobject = GetAttrDefaultColumnAddress(object->objectId);
4987 
4988  if (!OidIsValid(colobject.objectId))
4989  {
4990  if (!missing_ok)
4991  elog(ERROR, "could not find tuple for attrdef %u",
4992  object->objectId);
4993  break;
4994  }
4995 
4996  appendStringInfo(&buffer, "for %s",
4997  getObjectIdentityParts(&colobject,
4998  objname, objargs,
4999  false));
5000  break;
5001  }
5002 
5003  case OCLASS_LANGUAGE:
5004  {
5005  HeapTuple langTup;
5006  Form_pg_language langForm;
5007 
5008  langTup = SearchSysCache1(LANGOID,
5009  ObjectIdGetDatum(object->objectId));
5010  if (!HeapTupleIsValid(langTup))
5011  {
5012  if (!missing_ok)
5013  elog(ERROR, "cache lookup failed for language %u",
5014  object->objectId);
5015  break;
5016  }
5017  langForm = (Form_pg_language) GETSTRUCT(langTup);
5018  appendStringInfoString(&buffer,
5019  quote_identifier(NameStr(langForm->lanname)));
5020  if (objname)
5021  *objname = list_make1(pstrdup(NameStr(langForm->lanname)));
5022  ReleaseSysCache(langTup);
5023  break;
5024  }
5025  case OCLASS_LARGEOBJECT:
5026  if (!LargeObjectExists(object->objectId))
5027  break;
5028  appendStringInfo(&buffer, "%u",
5029  object->objectId);
5030  if (objname)
5031  *objname = list_make1(psprintf("%u", object->objectId));
5032  break;
5033 
5034  case OCLASS_OPERATOR:
5035  {
5037  char *oprname = format_operator_extended(object->objectId,
5038  flags);
5039 
5040  if (oprname == NULL)
5041  break;
5042 
5043  appendStringInfoString(&buffer, oprname);
5044  if (objname)
5045  format_operator_parts(object->objectId, objname, objargs, missing_ok);
5046  break;
5047  }
5048 
5049  case OCLASS_OPCLASS:
5050  {
5051  HeapTuple opcTup;
5052  Form_pg_opclass opcForm;
5053  HeapTuple amTup;
5054  Form_pg_am amForm;
5055  char *schema;
5056 
5057  opcTup = SearchSysCache1(CLAOID,
5058  ObjectIdGetDatum(object->objectId));
5059  if (!HeapTupleIsValid(opcTup))
5060  {
5061  if (!missing_ok)
5062  elog(ERROR, "cache lookup failed for opclass %u",
5063  object->objectId);
5064  break;
5065  }
5066  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
5067  schema = get_namespace_name_or_temp(opcForm->opcnamespace);
5068 
5069  amTup = SearchSysCache1(AMOID,
5070  ObjectIdGetDatum(opcForm->opcmethod));
5071  if (!HeapTupleIsValid(amTup))
5072  elog(ERROR, "cache lookup failed for access method %u",
5073  opcForm->opcmethod);
5074  amForm = (Form_pg_am) GETSTRUCT(amTup);
5075 
5076  appendStringInfo(&buffer, "%s USING %s",
5078  NameStr(opcForm->opcname)),
5079  quote_identifier(NameStr(amForm->amname)));
5080  if (objname)
5081  *objname = list_make3(pstrdup(NameStr(amForm->amname)),
5082  schema,
5083  pstrdup(NameStr(opcForm->opcname)));
5084 
5085  ReleaseSysCache(amTup);
5086  ReleaseSysCache(opcTup);
5087  break;
5088  }
5089 
5090  case OCLASS_OPFAMILY:
5091  getOpFamilyIdentity(&buffer, object->objectId, objname,
5092  missing_ok);
5093  break;
5094 
5095  case OCLASS_AM:
5096  {
5097  char *amname;
5098 
5099  amname = get_am_name(object->objectId);
5100  if (!amname)
5101  {
5102  if (!missing_ok)
5103  elog(ERROR, "cache lookup failed for access method %u",
5104  object->objectId);
5105  break;
5106  }
5107  appendStringInfoString(&buffer, quote_identifier(amname));
5108  if (objname)
5109  *objname = list_make1(amname);
5110  }
5111  break;
5112 
5113  case OCLASS_AMOP:
5114  {
5115  Relation amopDesc;
5116  HeapTuple tup;
5117  ScanKeyData skey[1];
5118  SysScanDesc amscan;
5119  Form_pg_amop amopForm;
5120  StringInfoData opfam;
5121  char *ltype;
5122  char *rtype;
5123 
5124  amopDesc = table_open(AccessMethodOperatorRelationId,
5125  AccessShareLock);
5126 
5127  ScanKeyInit(&skey[0],
5128  Anum_pg_amop_oid,
5129  BTEqualStrategyNumber, F_OIDEQ,
5130  ObjectIdGetDatum(object->objectId));
5131 
5132  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
5133  NULL, 1, skey);
5134 
5135  tup = systable_getnext(amscan);
5136 
5137  if (!HeapTupleIsValid(tup))
5138  {
5139  if (!missing_ok)
5140  elog(ERROR, "could not find tuple for amop entry %u",
5141  object->objectId);
5142 
5143  systable_endscan(amscan);
5144  table_close(amopDesc, AccessShareLock);
5145  break;
5146  }
5147 
5148  amopForm = (Form_pg_amop) GETSTRUCT(tup);
5149 
5150  initStringInfo(&opfam);
5151  getOpFamilyIdentity(&opfam, amopForm->amopfamily, objname,
5152  false);
5153 
5154  ltype = format_type_be_qualified(amopForm->amoplefttype);
5155  rtype = format_type_be_qualified(amopForm->amoprighttype);
5156 
5157  if (objname)
5158  {
5159  *objname = lappend(*objname,
5160  psprintf("%d", amopForm->amopstrategy));
5161  *objargs = list_make2(ltype, rtype);
5162  }
5163 
5164  appendStringInfo(&buffer, "operator %d (%s, %s) of %s",
5165  amopForm->amopstrategy,
5166  ltype, rtype, opfam.data);
5167 
5168  pfree(opfam.data);
5169 
5170  systable_endscan(amscan);
5171  table_close(amopDesc, AccessShareLock);
5172  break;
5173  }
5174 
5175  case OCLASS_AMPROC:
5176  {
5177  Relation amprocDesc;
5178  ScanKeyData skey[1];
5179  SysScanDesc amscan;
5180  HeapTuple tup;
5181  Form_pg_amproc amprocForm;
5182  StringInfoData opfam;
5183  char *ltype;
5184  char *rtype;
5185 
5186  amprocDesc = table_open(AccessMethodProcedureRelationId,
5187  AccessShareLock);
5188 
5189  ScanKeyInit(&skey[0],
5190  Anum_pg_amproc_oid,
5191  BTEqualStrategyNumber, F_OIDEQ,
5192  ObjectIdGetDatum(object->objectId));
5193 
5194  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
5195  NULL, 1, skey);
5196 
5197  tup = systable_getnext(amscan);
5198 
5199  if (!HeapTupleIsValid(tup))
5200  {
5201  if (!missing_ok)
5202  elog(ERROR, "could not find tuple for amproc entry %u",
5203  object->objectId);
5204 
5205  systable_endscan(amscan);
5206  table_close(amprocDesc, AccessShareLock);
5207  break;
5208  }
5209 
5210  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
5211 
5212  initStringInfo(&opfam);
5213  getOpFamilyIdentity(&opfam, amprocForm->amprocfamily, objname,
5214  false);
5215 
5216  ltype = format_type_be_qualified(amprocForm->amproclefttype);
5217  rtype = format_type_be_qualified(amprocForm->amprocrighttype);
5218 
5219  if (objname)
5220  {
5221  *objname = lappend(*objname,
5222  psprintf("%d", amprocForm->amprocnum));
5223  *objargs = list_make2(ltype, rtype);
5224  }
5225 
5226  appendStringInfo(&buffer, "function %d (%s, %s) of %s",
5227  amprocForm->amprocnum,
5228  ltype, rtype, opfam.data);
5229 
5230  pfree(opfam.data);
5231 
5232  systable_endscan(amscan);
5233  table_close(amprocDesc, AccessShareLock);
5234  break;
5235  }
5236 
5237  case OCLASS_REWRITE:
5238  {
5239  Relation ruleDesc;
5240  HeapTuple tup;
5242 
5243  ruleDesc = table_open(RewriteRelationId, AccessShareLock);
5244 
5245  tup = get_catalog_object_by_oid(ruleDesc, Anum_pg_rewrite_oid,
5246  object->objectId);
5247 
5248  if (!HeapTupleIsValid(tup))
5249  {
5250  if (!missing_ok)
5251  elog(ERROR, "could not find tuple for rule %u",
5252  object->objectId);
5253 
5254  table_close(ruleDesc, AccessShareLock);
5255  break;
5256  }
5257 
5258  rule = (Form_pg_rewrite) GETSTRUCT(tup);
5259 
5260  appendStringInfo(&buffer, "%s on ",
5261  quote_identifier(NameStr(rule->rulename)));
5262  getRelationIdentity(&buffer, rule->ev_class, objname, false);
5263  if (objname)
5264  *objname = lappend(*objname, pstrdup(NameStr(rule->rulename)));
5265 
5266  table_close(ruleDesc, AccessShareLock);
5267  break;
5268  }
5269 
5270  case OCLASS_TRIGGER:
5271  {
5272  Relation trigDesc;
5273  HeapTuple tup;
5274  Form_pg_trigger trig;
5275 
5276  trigDesc = table_open(TriggerRelationId, AccessShareLock);
5277 
5278  tup = get_catalog_object_by_oid(trigDesc, Anum_pg_trigger_oid,
5279  object->objectId);
5280 
5281  if (!HeapTupleIsValid(tup))
5282  {
5283  if (!missing_ok)
5284  elog(ERROR, "could not find tuple for trigger %u",
5285  object->objectId);
5286 
5287  table_close(trigDesc, AccessShareLock);
5288  break;
5289  }
5290 
5291  trig = (Form_pg_trigger) GETSTRUCT(tup);
5292 
5293  appendStringInfo(&buffer, "%s on ",
5294  quote_identifier(NameStr(trig->tgname)));
5295  getRelationIdentity(&buffer, trig->tgrelid, objname, false);
5296  if (objname)
5297  *objname = lappend(*objname, pstrdup(NameStr(trig->tgname)));
5298 
5299  table_close(trigDesc, AccessShareLock);
5300  break;
5301  }
5302 
5303  case OCLASS_SCHEMA:
5304  {
5305  char *nspname;
5306 
5307  nspname = get_namespace_name_or_temp(object->objectId);
5308  if (!nspname)
5309  {
5310  if (!missing_ok)
5311  elog(ERROR, "cache lookup failed for namespace %u",
5312  object->objectId);
5313  break;
5314  }
5315  appendStringInfoString(&buffer,
5316  quote_identifier(nspname));
5317  if (objname)
5318  *objname = list_make1(nspname);
5319  break;
5320  }
5321 
5322  case OCLASS_STATISTIC_EXT:
5323  {
5324  HeapTuple tup;
5325  Form_pg_statistic_ext formStatistic;
5326  char *schema;
5327 
5329  ObjectIdGetDatum(object->objectId));
5330  if (!HeapTupleIsValid(tup))
5331  {
5332  if (!missing_ok)
5333  elog(ERROR, "cache lookup failed for statistics object %u",
5334  object->objectId);
5335  break;
5336  }
5337  formStatistic = (Form_pg_statistic_ext) GETSTRUCT(tup);
5338  schema = get_namespace_name_or_temp(formStatistic->stxnamespace);
5339  appendStringInfoString(&buffer,
5341  NameStr(formStatistic->stxname)));
5342  if (objname)
5343  *objname = list_make2(schema,
5344  pstrdup(NameStr(formStatistic->stxname)));
5345  ReleaseSysCache(tup);
5346  }
5347  break;
5348 
5349  case OCLASS_TSPARSER:
5350  {
5351  HeapTuple tup;
5352  Form_pg_ts_parser formParser;
5353  char *schema;
5354 
5356  ObjectIdGetDatum(object->objectId));
5357  if (!HeapTupleIsValid(tup))
5358  {
5359  if (!missing_ok)
5360  elog(ERROR, "cache lookup failed for text search parser %u",
5361  object->objectId);
5362  break;
5363  }
5364  formParser = (Form_pg_ts_parser) GETSTRUCT(tup);
5365  schema = get_namespace_name_or_temp(formParser->prsnamespace);
5366  appendStringInfoString(&buffer,
5368  NameStr(formParser->prsname)));
5369  if (objname)
5370  *objname = list_make2(schema,
5371  pstrdup(NameStr(formParser->prsname)));
5372  ReleaseSysCache(tup);
5373  break;
5374  }
5375 
5376  case OCLASS_TSDICT:
5377  {
5378  HeapTuple tup;
5379  Form_pg_ts_dict formDict;
5380  char *schema;
5381 
5382  tup = SearchSysCache1(TSDICTOID,
5383  ObjectIdGetDatum(object->objectId));
5384  if (!HeapTupleIsValid(tup))
5385  {
5386  if (!missing_ok)
5387  elog(ERROR, "cache lookup failed for text search dictionary %u",
5388  object->objectId);
5389  break;
5390  }
5391  formDict = (Form_pg_ts_dict) GETSTRUCT(tup);
5392  schema = get_namespace_name_or_temp(formDict->dictnamespace);
5393  appendStringInfoString(&buffer,
5395  NameStr(formDict->dictname)));
5396  if (objname)
5397  *objname = list_make2(schema,
5398  pstrdup(NameStr(formDict->dictname)));
5399  ReleaseSysCache(tup);
5400  break;
5401  }
5402 
5403  case OCLASS_TSTEMPLATE:
5404  {
5405  HeapTuple tup;
5406  Form_pg_ts_template formTmpl;
5407  char *schema;
5408 
5410  ObjectIdGetDatum(object->objectId));
5411  if (!HeapTupleIsValid(tup))
5412  {
5413  if (!missing_ok)
5414  elog(ERROR, "cache lookup failed for text search template %u",
5415  object->objectId);
5416  break;
5417  }
5418  formTmpl = (Form_pg_ts_template) GETSTRUCT(tup);
5419  schema = get_namespace_name_or_temp(formTmpl->tmplnamespace);
5420  appendStringInfoString(&buffer,
5422  NameStr(formTmpl->tmplname)));
5423  if (objname)
5424  *objname = list_make2(schema,
5425  pstrdup(NameStr(formTmpl->tmplname)));
5426  ReleaseSysCache(tup);
5427  break;
5428  }
5429 
5430  case OCLASS_TSCONFIG:
5431  {
5432  HeapTuple tup;
5433  Form_pg_ts_config formCfg;
5434  char *schema;
5435 
5437  ObjectIdGetDatum(object->objectId));
5438  if (!HeapTupleIsValid(tup))
5439  {
5440  if (!missing_ok)
5441  elog(ERROR, "cache lookup failed for text search configuration %u",
5442  object->objectId);
5443  break;
5444  }
5445  formCfg = (Form_pg_ts_config) GETSTRUCT(tup);
5446  schema = get_namespace_name_or_temp(formCfg->cfgnamespace);
5447  appendStringInfoString(&buffer,
5449  NameStr(formCfg->cfgname)));
5450  if (objname)
5451  *objname = list_make2(schema,
5452  pstrdup(NameStr(formCfg->cfgname)));
5453  ReleaseSysCache(tup);
5454  break;
5455  }
5456 
5457  case OCLASS_ROLE:
5458  {
5459  char *username;
5460 
5461  username = GetUserNameFromId(object->objectId, missing_ok);
5462  if (!username)
5463  break;
5464  if (objname)
5465  *objname = list_make1(username);
5466  appendStringInfoString(&buffer,
5468  break;
5469  }
5470 
5472  {
5473  Relation authMemDesc;
5474  ScanKeyData skey[1];
5475  SysScanDesc amscan;
5476  HeapTuple tup;
5477  Form_pg_auth_members amForm;
5478 
5479  authMemDesc = table_open(AuthMemRelationId,
5480  AccessShareLock);
5481 
5482  ScanKeyInit(&skey[0],
5483  Anum_pg_auth_members_oid,
5484  BTEqualStrategyNumber, F_OIDEQ,
5485  ObjectIdGetDatum(object->objectId));
5486 
5487  amscan = systable_beginscan(authMemDesc, AuthMemOidIndexId, true,
5488  NULL, 1, skey);
5489 
5490  tup = systable_getnext(amscan);
5491 
5492  if (!HeapTupleIsValid(tup))
5493  {
5494  if (!missing_ok)
5495  elog(ERROR, "could not find tuple for pg_auth_members entry %u",
5496  object->objectId);
5497 
5498  systable_endscan(amscan);
5499  table_close(authMemDesc, AccessShareLock);
5500  break;
5501  }
5502 
5503  amForm = (Form_pg_auth_members) GETSTRUCT(tup);
5504 
5505  appendStringInfo(&buffer, _("membership of role %s in role %s"),
5506  GetUserNameFromId(amForm->member, false),
5507  GetUserNameFromId(amForm->roleid, false));
5508 
5509  systable_endscan(amscan);
5510  table_close(authMemDesc, AccessShareLock);
5511  break;
5512  }
5513 
5514  case OCLASS_DATABASE:
5515  {
5516  char *datname;
5517 
5518  datname = get_database_name(object->objectId);
5519  if (!datname)
5520  {
5521  if (!missing_ok)
5522  elog(ERROR, "cache lookup failed for database %u",
5523  object->objectId);
5524  break;
5525  }
5526  if (objname)
5527  *objname = list_make1(datname);
5528  appendStringInfoString(&buffer,
5530  break;
5531  }
5532 
5533  case OCLASS_TBLSPACE:
5534  {
5535  char *tblspace;
5536 
5537  tblspace = get_tablespace_name(object->objectId);
5538  if (!tblspace)
5539  {
5540  if (!missing_ok)
5541  elog(ERROR, "cache lookup failed for tablespace %u",
5542  object->objectId);
5543  break;
5544  }
5545  if (objname)
5546  *objname = list_make1(tblspace);
5547  appendStringInfoString(&buffer,
5548  quote_identifier(tblspace));
5549  break;
5550  }
5551 
5552  case OCLASS_FDW:
5553  {
5554  ForeignDataWrapper *fdw;
5555 
5557  missing_ok);
5558  if (fdw)
5559  {
5561  if (objname)
5562  *objname = list_make1(pstrdup(fdw->fdwname));
5563  }
5564  break;
5565  }
5566 
5567  case OCLASS_FOREIGN_SERVER:
5568  {
5569  ForeignServer *srv;
5570 
5571  srv = GetForeignServerExtended(object->objectId,
5572  missing_ok);
5573  if (srv)
5574  {
5575  appendStringInfoString(&buffer,
5577  if (objname)
5578  *objname = list_make1(pstrdup(srv->servername));
5579  }
5580  break;
5581  }
5582 
5583  case OCLASS_USER_MAPPING:
5584  {
5585  HeapTuple tup;
5586  Oid useid;
5587  Form_pg_user_mapping umform;
5588  ForeignServer *srv;
5589  const char *usename;
5590 
5592  ObjectIdGetDatum(object->objectId));
5593  if (!HeapTupleIsValid(tup))
5594  {
5595  if (!missing_ok)
5596  elog(ERROR, "cache lookup failed for user mapping %u",
5597  object->objectId);
5598  break;
5599  }
5600  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
5601  useid = umform->umuser;
5602  srv = GetForeignServer(umform->umserver);
5603 
5604  ReleaseSysCache(tup);
5605 
5606  if (OidIsValid(useid))
5607  usename = GetUserNameFromId(useid, false);
5608  else
5609  usename = "public";
5610 
5611  if (objname)
5612  {
5613  *objname = list_make1(pstrdup(usename));
5614  *objargs = list_make1(pstrdup(srv->servername));
5615  }
5616 
5617  appendStringInfo(&buffer, "%s on server %s",
5618  quote_identifier(usename),
5619  srv->servername);
5620  break;
5621  }
5622 
5623  case OCLASS_DEFACL:
5624  {
5625  Relation defaclrel;
5626  ScanKeyData skey[1];
5627  SysScanDesc rcscan;
5628  HeapTuple tup;
5629  Form_pg_default_acl defacl;
5630  char *schema;
5631  char *username;
5632 
5633  defaclrel = table_open(DefaultAclRelationId, AccessShareLock);
5634 
5635  ScanKeyInit(&skey[0],
5636  Anum_pg_default_acl_oid,
5637  BTEqualStrategyNumber, F_OIDEQ,
5638  ObjectIdGetDatum(object->objectId));
5639 
5640  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
5641  true, NULL, 1, skey);
5642 
5643  tup = systable_getnext(rcscan);
5644 
5645  if (!HeapTupleIsValid(tup))
5646  {
5647  if (!missing_ok)
5648  elog(ERROR, "could not find tuple for default ACL %u",
5649  object->objectId);
5650 
5651  systable_endscan(rcscan);
5652  table_close(defaclrel, AccessShareLock);
5653  break;
5654  }
5655 
5656  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
5657 
5658  username = GetUserNameFromId(defacl->defaclrole, false);
5659  appendStringInfo(&buffer,
5660  "for role %s",
5662 
5663  if (OidIsValid(defacl->defaclnamespace))
5664  {
5665  schema = get_namespace_name_or_temp(defacl->defaclnamespace);
5666  appendStringInfo(&buffer,
5667  " in schema %s",
5668  quote_identifier(schema));
5669  }
5670  else
5671  schema = NULL;
5672 
5673  switch (defacl->defaclobjtype)
5674  {
5675  case DEFACLOBJ_RELATION:
5676  appendStringInfoString(&buffer,
5677  " on tables");
5678  break;
5679  case DEFACLOBJ_SEQUENCE:
5680  appendStringInfoString(&buffer,
5681  " on sequences");
5682  break;
5683  case DEFACLOBJ_FUNCTION:
5684  appendStringInfoString(&buffer,
5685  " on functions");
5686  break;
5687  case DEFACLOBJ_TYPE:
5688  appendStringInfoString(&buffer,
5689  " on types");
5690  break;
5691  case DEFACLOBJ_NAMESPACE:
5692  appendStringInfoString(&buffer,
5693  " on schemas");
5694  break;
5695  }
5696 
5697  if (objname)
5698  {
5699  *objname = list_make1(username);
5700  if (schema)
5701  *objname = lappend(*objname, schema);
5702  *objargs = list_make1(psprintf("%c", defacl->defaclobjtype));
5703  }
5704 
5705  systable_endscan(rcscan);
5706  table_close(defaclrel, AccessShareLock);
5707  break;
5708  }
5709 
5710  case OCLASS_EXTENSION:
5711  {
5712  char *extname;
5713 
5714  extname = get_extension_name(object->objectId);
5715  if (!extname)
5716  {
5717  if (!missing_ok)
5718  elog(ERROR, "cache lookup failed for extension %u",
5719  object->objectId);
5720  break;
5721  }
5722  appendStringInfoString(&buffer, quote_identifier(extname));
5723  if (objname)
5724  *objname = list_make1(extname);
5725  break;
5726  }
5727 
5728  case OCLASS_EVENT_TRIGGER:
5729  {
5730  HeapTuple tup;
5731  Form_pg_event_trigger trigForm;
5732  char *evtname;
5733 
5735  ObjectIdGetDatum(object->objectId));
5736  if (!HeapTupleIsValid(tup))
5737  {
5738  if (!missing_ok)
5739  elog(ERROR, "cache lookup failed for event trigger %u",
5740  object->objectId);
5741  break;
5742  }
5743  trigForm = (Form_pg_event_trigger) GETSTRUCT(tup);
5744  evtname = pstrdup(NameStr(trigForm->evtname));
5745  appendStringInfoString(&buffer, quote_identifier(evtname));
5746  if (objname)
5747  *objname = list_make1(evtname);
5748  ReleaseSysCache(tup);
5749  break;
5750  }
5751 
5752  case OCLASS_PARAMETER_ACL:
5753  {
5754  HeapTuple tup;
5755  Datum nameDatum;
5756  bool isNull;
5757  char *parname;
5758 
5760  ObjectIdGetDatum(object->objectId));
5761  if (!HeapTupleIsValid(tup))
5762  {
5763  if (!missing_ok)
5764  elog(ERROR, "cache lookup failed for parameter ACL %u",
5765  object->objectId);
5766  break;
5767  }
5768  nameDatum = SysCacheGetAttr(PARAMETERACLOID, tup,
5769  Anum_pg_parameter_acl_parname,
5770  &isNull);
5771  Assert(!isNull);
5772  parname = TextDatumGetCString(nameDatum);
5773  appendStringInfoString(&buffer, parname);
5774  if (objname)
5775  *objname = list_make1(parname);
5776  ReleaseSysCache(tup);
5777  break;
5778  }
5779 
5780  case OCLASS_POLICY:
5781  {
5782  Relation polDesc;
5783  HeapTuple tup;
5784  Form_pg_policy policy;
5785 
5786  polDesc = table_open(PolicyRelationId, AccessShareLock);
5787 
5788  tup = get_catalog_object_by_oid(polDesc, Anum_pg_policy_oid,
5789  object->objectId);
5790 
5791  if (!HeapTupleIsValid(tup))
5792  {
5793  if (!missing_ok)
5794  elog(ERROR, "could not find tuple for policy %u",
5795  object->objectId);
5796 
5797  table_close(polDesc, AccessShareLock);
5798  break;
5799  }
5800 
5801  policy = (Form_pg_policy) GETSTRUCT(tup);
5802 
5803  appendStringInfo(&buffer, "%s on ",
5804  quote_identifier(NameStr(policy->polname)));
5805  getRelationIdentity(&buffer, policy->polrelid, objname, false);
5806  if (objname)
5807  *objname = lappend(*objname, pstrdup(NameStr(policy->polname)));
5808 
5809  table_close(polDesc, AccessShareLock);
5810  break;
5811  }
5812 
5813  case OCLASS_PUBLICATION:
5814  {
5815  char *pubname;
5816 
5817  pubname = get_publication_name(object->objectId, missing_ok);
5818  if (pubname)
5819  {
5820  appendStringInfoString(&buffer,
5821  quote_identifier(pubname));
5822  if (objname)
5823  *objname = list_make1(pubname);
5824  }
5825  break;
5826  }
5827 
5829  {
5830  char *pubname;
5831  char *nspname;
5832 
5833  if (!getPublicationSchemaInfo(object, missing_ok, &pubname,
5834  &nspname))
5835  break;
5836  appendStringInfo(&buffer, "%s in publication %s",
5837  nspname, pubname);
5838 
5839  if (objargs)
5840  *objargs = list_make1(pubname);
5841  else
5842  pfree(pubname);
5843 
5844  if (objname)
5845  *objname = list_make1(nspname);
5846  else
5847  pfree(nspname);
5848 
5849  break;
5850  }
5851 
5853  {
5854  HeapTuple tup;
5855  char *pubname;
5856  Form_pg_publication_rel prform;
5857 
5859  ObjectIdGetDatum(object->objectId));
5860  if (!HeapTupleIsValid(tup))
5861  {
5862  if (!missing_ok)
5863  elog(ERROR, "cache lookup failed for publication table %u",
5864  object->objectId);
5865  break;
5866  }
5867 
5868  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
5869  pubname = get_publication_name(prform->prpubid, false);
5870 
5871  getRelationIdentity(&buffer, prform->prrelid, objname, false);
5872  appendStringInfo(&buffer, " in publication %s", pubname);
5873 
5874  if (objargs)
5875  *objargs = list_make1(pubname);
5876 
5877  ReleaseSysCache(tup);
5878  break;
5879  }
5880 
5881  case OCLASS_SUBSCRIPTION:
5882  {
5883  char *subname;
5884 
5885  subname = get_subscription_name(object->objectId, missing_ok);
5886  if (subname)
5887  {
5888  appendStringInfoString(&buffer,
5890  if (objname)
5891  *objname = list_make1(subname);
5892  }
5893  break;
5894  }
5895 
5896  case OCLASS_TRANSFORM:
5897  {
5898  Relation transformDesc;
5899  HeapTuple tup;
5900  Form_pg_transform transform;
5901  char *transformLang;
5902  char *transformType;
5903 
5904  transformDesc = table_open(TransformRelationId, AccessShareLock);
5905 
5906  tup = get_catalog_object_by_oid(transformDesc,
5907  Anum_pg_transform_oid,
5908  object->objectId);
5909 
5910  if (!HeapTupleIsValid(tup))
5911  {
5912  if (!missing_ok)
5913  elog(ERROR, "could not find tuple for transform %u",
5914  object->objectId);
5915 
5916  table_close(transformDesc, AccessShareLock);
5917  break;
5918  }
5919 
5920  transform = (Form_pg_transform) GETSTRUCT(tup);
5921 
5922  transformType = format_type_be_qualified(transform->trftype);
5923  transformLang = get_language_name(transform->trflang, false);
5924 
5925  appendStringInfo(&buffer, "for %s on language %s",
5926  transformType,
5927  transformLang);
5928  if (objname)
5929  {
5930  *objname = list_make1(transformType);
5931  *objargs = list_make1(pstrdup(transformLang));
5932  }
5933 
5934  table_close(transformDesc, AccessShareLock);
5935  }
5936  break;
5937 
5938  /*
5939  * There's intentionally no default: case here; we want the
5940  * compiler to warn if a new OCLASS hasn't been handled above.
5941  */
5942  }
5943 
5944  if (!missing_ok)
5945  {
5946  /*
5947  * If a get_object_address() representation was requested, make sure
5948  * we are providing one. We don't check objargs, because many of the
5949  * cases above leave it as NIL.
5950  */
5951  if (objname && *objname == NIL)
5952  elog(ERROR, "requested object address for unsupported object class %d: text result \"%s\"",
5953  (int) getObjectClass(object), buffer.data);
5954  }
5955  else
5956  {
5957  /* an empty buffer is equivalent to no object found */
5958  if (buffer.len == 0)
5959  {
5960  Assert((objname == NULL || *objname == NIL) &&
5961  (objargs == NULL || *objargs == NIL));
5962  return NULL;
5963  }
5964  }
5965 
5966  return buffer.data;
5967 }
char * get_am_name(Oid amOid)
Definition: amcmds.c:192
#define FORMAT_TYPE_FORCE_QUALIFY
Definition: builtins.h:123
#define PointerIsValid(pointer)
Definition: c.h:747
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:349
List * lappend(List *list, void *datum)
Definition: list.c:338
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3355
char * pstrdup(const char *in)
Definition: mcxt.c:1624
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
static void getOpFamilyIdentity(StringInfo buffer, Oid opfid, List **object, bool missing_ok)
static void getRelationIdentity(StringInfo buffer, Oid relid, List **object, bool missing_ok)
FormData_pg_language * Form_pg_language
Definition: pg_language.h:65
#define NIL
Definition: pg_list.h:68
#define list_make1(x1)
Definition: pg_list.h:212
#define list_make3(x1, x2, x3)
Definition: pg_list.h:216
#define list_make2(x1, x2)
Definition: pg_list.h:214
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
void format_operator_parts(Oid operator_oid, List **objnames, List **objargs, bool missing_ok)
Definition: regproc.c:806
void format_procedure_parts(Oid procedure_oid, List **objnames, List **objargs, bool missing_ok)
Definition: regproc.c:398
#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)
Definition: ruleutils.c:11529
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
@ LANGOID
Definition: syscache.h:68

References _, AccessShareLock, AMOID, appendStringInfo(), appendStringInfoString(), Assert(), BTEqualStrategyNumber, CLAOID, ObjectAddress::classId, COLLOID, CONSTROID, CONVOID, StringInfoData::data, datname, elog(), ERROR, EVENTTRIGGEROID, ForeignDataWrapper::fdwname, format_operator_extended(), FORMAT_OPERATOR_FORCE_QUALIFY, FORMAT_OPERATOR_INVALID_AS_NULL, format_operator_parts(), FORMAT_PROC_FORCE_QUALIFY, FORMAT_PROC_INVALID_AS_NULL, format_procedure_extended(), format_procedure_parts(), format_type_be_qualified(), format_type_extended(), FORMAT_TYPE_FORCE_QUALIFY, FORMAT_TYPE_INVALID_AS_NULL, get_am_name(), get_attname(), get_catalog_object_by_oid(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name_or_temp(), get_publication_name(), get_subscription_name(), get_tablespace_name(), GetAttrDefaultColumnAddress(), GetForeignDataWrapperExtended(), GetForeignServer(), GetForeignServerExtended(), getObjectClass(), getOpFamilyIdentity(), getPublicationSchemaInfo(), getRelationIdentity(), GETSTRUCT, GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), LANGOID, lappend(), LargeObjectExists(), StringInfoData::len, list_make1, list_make2, list_make3, NameStr, NIL, ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, OCLASS_AM, OCLASS_AMOP, OCLASS_AMPROC, OCLASS_CAST, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONSTRAINT, OCLASS_CONVERSION, OCLASS_DATABASE, OCLASS_DEFACL, OCLASS_DEFAULT, OCLASS_EVENT_TRIGGER, OCLASS_EXTENSION, OCLASS_FDW, OCLASS_FOREIGN_SERVER, OCLASS_LANGUAGE, OCLASS_LARGEOBJECT, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_PARAMETER_ACL, OCLASS_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_NAMESPACE, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, OCLASS_ROLE_MEMBERSHIP, OCLASS_SCHEMA, OCLASS_STATISTIC_EXT, OCLASS_SUBSCRIPTION, OCLASS_TBLSPACE, OCLASS_TRANSFORM, OCLASS_TRIGGER, OCLASS_TSCONFIG, OCLASS_TSDICT, OCLASS_TSPARSER, OCLASS_TSTEMPLATE, OCLASS_TYPE, OCLASS_USER_MAPPING, OidIsValid, PARAMETERACLOID, pfree(), PointerIsValid, proname, psprintf(), pstrdup(), PUBLICATIONREL, quote_identifier(), quote_qualified_identifier(), ReleaseSysCache(), ScanKeyInit(), SearchSysCache1(), ForeignServer::servername, STATEXTOID, subname, SysCacheGetAttr(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TextDatumGetCString, TSCONFIGOID, TSDICTOID, TSPARSEROID, TSTEMPLATEOID, USERMAPPINGOID, and username.

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

◆ getObjectTypeDescription()

char* getObjectTypeDescription ( const ObjectAddress object,
bool  missing_ok 
)

Definition at line 4412 of file objectaddress.c.

4413 {
4414  StringInfoData buffer;
4415 
4416  initStringInfo(&buffer);
4417 
4418  switch (getObjectClass(object))
4419  {
4420  case OCLASS_CLASS:
4421  getRelationTypeDescription(&buffer, object->objectId,
4422  object->objectSubId,
4423  missing_ok);
4424  break;
4425 
4426  case OCLASS_PROC:
4427  getProcedureTypeDescription(&buffer, object->objectId,
4428  missing_ok);
4429  break;
4430 
4431  case OCLASS_TYPE:
4432  appendStringInfoString(&buffer, "type");
4433  break;
4434 
4435  case OCLASS_CAST:
4436  appendStringInfoString(&buffer, "cast");
4437  break;
4438 
4439  case OCLASS_COLLATION:
4440  appendStringInfoString(&buffer, "collation");
4441  break;
4442 
4443  case OCLASS_CONSTRAINT:
4444  getConstraintTypeDescription(&buffer, object->objectId,
4445  missing_ok);
4446  break;
4447 
4448  case OCLASS_CONVERSION:
4449  appendStringInfoString(&buffer, "conversion");
4450  break;
4451 
4452  case OCLASS_DEFAULT:
4453  appendStringInfoString(&buffer, "default value");
4454  break;
4455 
4456  case OCLASS_LANGUAGE:
4457  appendStringInfoString(&buffer, "language");
4458  break;
4459 
4460  case OCLASS_LARGEOBJECT:
4461  appendStringInfoString(&buffer, "large object");
4462  break;
4463 
4464  case OCLASS_OPERATOR:
4465  appendStringInfoString(&buffer, "operator");
4466  break;
4467 
4468  case OCLASS_OPCLASS:
4469  appendStringInfoString(&buffer, "operator class");
4470  break;
4471 
4472  case OCLASS_OPFAMILY:
4473  appendStringInfoString(&buffer, "operator family");
4474  break;
4475 
4476  case OCLASS_AM:
4477  appendStringInfoString(&buffer, "access method");
4478  break;
4479 
4480  case OCLASS_AMOP:
4481  appendStringInfoString(&buffer, "operator of access method");
4482  break;
4483 
4484  case OCLASS_AMPROC:
4485  appendStringInfoString(&buffer, "function of access method");
4486  break;
4487 
4488  case OCLASS_REWRITE:
4489  appendStringInfoString(&buffer, "rule");
4490  break;
4491 
4492  case OCLASS_TRIGGER:
4493  appendStringInfoString(&buffer, "trigger");
4494  break;
4495 
4496  case OCLASS_SCHEMA:
4497  appendStringInfoString(&buffer, "schema");
4498  break;
4499 
4500  case OCLASS_STATISTIC_EXT:
4501  appendStringInfoString(&buffer, "statistics object");
4502  break;
4503 
4504  case OCLASS_TSPARSER:
4505  appendStringInfoString(&buffer, "text search parser");
4506  break;
4507 
4508  case OCLASS_TSDICT:
4509  appendStringInfoString(&buffer, "text search dictionary");
4510  break;
4511 
4512  case OCLASS_TSTEMPLATE:
4513  appendStringInfoString(&buffer, "text search template");
4514  break;
4515 
4516  case OCLASS_TSCONFIG:
4517  appendStringInfoString(&buffer, "text search configuration");
4518  break;
4519 
4520  case OCLASS_ROLE:
4521  appendStringInfoString(&buffer, "role");
4522  break;
4523 
4525  appendStringInfoString(&buffer, "role membership");
4526  break;
4527 
4528  case OCLASS_DATABASE:
4529  appendStringInfoString(&buffer, "database");
4530  break;
4531 
4532  case OCLASS_TBLSPACE:
4533  appendStringInfoString(&buffer, "tablespace");
4534  break;
4535 
4536  case OCLASS_FDW:
4537  appendStringInfoString(&buffer, "foreign-data wrapper");
4538  break;
4539 
4540  case OCLASS_FOREIGN_SERVER:
4541  appendStringInfoString(&buffer, "server");
4542  break;
4543 
4544  case OCLASS_USER_MAPPING:
4545  appendStringInfoString(&buffer, "user mapping");
4546  break;
4547 
4548  case OCLASS_DEFACL:
4549  appendStringInfoString(&buffer, "default acl");
4550  break;
4551 
4552  case OCLASS_EXTENSION:
4553  appendStringInfoString(&buffer, "extension");
4554  break;
4555 
4556  case OCLASS_EVENT_TRIGGER:
4557  appendStringInfoString(&buffer, "event trigger");
4558  break;
4559 
4560  case OCLASS_PARAMETER_ACL:
4561  appendStringInfoString(&buffer, "parameter ACL");
4562  break;
4563 
4564  case OCLASS_POLICY:
4565  appendStringInfoString(&buffer, "policy");
4566  break;
4567 
4568  case OCLASS_PUBLICATION:
4569  appendStringInfoString(&buffer, "publication");
4570  break;
4571 
4573  appendStringInfoString(&buffer, "publication namespace");
4574  break;
4575 
4577  appendStringInfoString(&buffer, "publication relation");
4578  break;
4579 
4580  case OCLASS_SUBSCRIPTION:
4581  appendStringInfoString(&buffer, "subscription");
4582  break;
4583 
4584  case OCLASS_TRANSFORM:
4585  appendStringInfoString(&buffer, "transform");
4586  break;
4587 
4588  /*
4589  * There's intentionally no default: case here; we want the
4590  * compiler to warn if a new OCLASS hasn't been handled above.
4591  */
4592  }
4593 
4594  /* the result can never be empty */
4595  Assert(buffer.len > 0);
4596 
4597  return buffer.data;
4598 }
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(), StringInfoData::data, getConstraintTypeDescription(), getObjectClass(), getProcedureTypeDescription(), getRelationTypeDescription(), initStringInfo(), StringInfoData::len, ObjectAddress::objectId, ObjectAddress::objectSubId, OCLASS_AM, OCLASS_AMOP, OCLASS_AMPROC, OCLASS_CAST, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONSTRAINT, OCLASS_CONVERSION, OCLASS_DATABASE, OCLASS_DEFACL, OCLASS_DEFAULT, OCLASS_EVENT_TRIGGER, OCLASS_EXTENSION, OCLASS_FDW, OCLASS_FOREIGN_SERVER, OCLASS_LANGUAGE, OCLASS_LARGEOBJECT, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_PARAMETER_ACL, OCLASS_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_NAMESPACE, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, OCLASS_ROLE_MEMBERSHIP, OCLASS_SCHEMA, OCLASS_STATISTIC_EXT, OCLASS_SUBSCRIPTION, OCLASS_TBLSPACE, OCLASS_TRANSFORM, OCLASS_TRIGGER, OCLASS_TSCONFIG, OCLASS_TSDICT, OCLASS_TSPARSER, OCLASS_TSTEMPLATE, OCLASS_TYPE, and OCLASS_USER_MAPPING.

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

◆ is_objectclass_supported()

bool is_objectclass_supported ( Oid  class_id)

Definition at line 2764 of file objectaddress.c.

2765 {
2766  int index;
2767 
2768  for (index = 0; index < lengthof(ObjectProperty); index++)
2769  {
2770  if (ObjectProperty[index].class_oid == class_id)
2771  return true;
2772  }
2773 
2774  return false;
2775 }
#define lengthof(array)
Definition: c.h:772
static const ObjectPropertyType ObjectProperty[]
Definition: type.h:95

References lengthof, and ObjectProperty.

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

◆ read_objtype_from_string()

int read_objtype_from_string ( const char *  objtype)

Definition at line 2635 of file objectaddress.c.

2636 {
2637  int i;
2638 
2639  for (i = 0; i < lengthof(ObjectTypeMap); i++)
2640  {
2641  if (strcmp(ObjectTypeMap[i].tm_name, objtype) == 0)
2642  return ObjectTypeMap[i].tm_type;
2643  }
2644  ereport(ERROR,
2645  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2646  errmsg("unrecognized object type \"%s\"", objtype)));
2647 
2648  return -1; /* keep compiler quiet */
2649 }
int i
Definition: isn.c:73
static const struct object_type_map ObjectTypeMap[]

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

Referenced by pg_get_object_address().

◆ strlist_to_textarray()

struct ArrayType* strlist_to_textarray ( List list)

Definition at line 6048 of file objectaddress.c.

6049 {
6050  ArrayType *arr;
6051  Datum *datums;
6052  bool *nulls;
6053  int j = 0;
6054  ListCell *cell;
6055  MemoryContext memcxt;
6056  MemoryContext oldcxt;
6057  int lb[1];
6058 
6059  /* Work in a temp context; easier than individually pfree'ing the Datums */
6061  "strlist to array",
6063  oldcxt = MemoryContextSwitchTo(memcxt);
6064 
6065  datums = (Datum *) palloc(sizeof(Datum) * list_length(list));
6066  nulls = palloc(sizeof(bool) * list_length(list));
6067 
6068  foreach(cell, list)
6069  {
6070  char *name = lfirst(cell);
6071 
6072  if (name)
6073  {
6074  nulls[j] = false;
6075  datums[j++] = CStringGetTextDatum(name);
6076  }
6077  else
6078  nulls[j] = true;
6079  }
6080 
6081  MemoryContextSwitchTo(oldcxt);
6082 
6083  lb[0] = 1;
6084  arr = construct_md_array(datums, nulls, 1, &j,
6085  lb, TEXTOID, -1, false, TYPALIGN_INT);
6086 
6087  MemoryContextDelete(memcxt);
6088 
6089  return arr;
6090 }
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3465
#define CStringGetTextDatum(s)
Definition: builtins.h:94
const char * name
Definition: encode.c:571
int j
Definition: isn.c:74
MemoryContext CurrentMemoryContext
Definition: mcxt.c:135
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:387
void * palloc(Size size)
Definition: mcxt.c:1210
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:153
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
#define lfirst(lc)
Definition: pg_list.h:172
static int list_length(const List *l)
Definition: pg_list.h:152

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, construct_md_array(), CStringGetTextDatum, CurrentMemoryContext, j, lfirst, sort-test::list, list_length(), MemoryContextDelete(), MemoryContextSwitchTo(), name, and palloc().

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

Variable Documentation

◆ InvalidObjectAddress