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 *address, bool missing_ok)
 
char * getObjectIdentityParts (const ObjectAddress *address, List **objname, List **objargs, bool missing_ok)
 
struct ArrayTypestrlist_to_textarray (List *list)
 
ObjectType get_relkind_objtype (char relkind)
 

Variables

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

2424 {
2425  switch (objtype)
2426  {
2427  case OBJECT_INDEX:
2428  case OBJECT_SEQUENCE:
2429  case OBJECT_TABLE:
2430  case OBJECT_VIEW:
2431  case OBJECT_MATVIEW:
2432  case OBJECT_FOREIGN_TABLE:
2433  case OBJECT_COLUMN:
2434  case OBJECT_RULE:
2435  case OBJECT_TRIGGER:
2436  case OBJECT_POLICY:
2437  case OBJECT_TABCONSTRAINT:
2438  if (!pg_class_ownercheck(RelationGetRelid(relation), roleid))
2440  RelationGetRelationName(relation));
2441  break;
2442  case OBJECT_DATABASE:
2443  if (!pg_database_ownercheck(address.objectId, roleid))
2445  strVal(object));
2446  break;
2447  case OBJECT_TYPE:
2448  case OBJECT_DOMAIN:
2449  case OBJECT_ATTRIBUTE:
2450  if (!pg_type_ownercheck(address.objectId, roleid))
2452  break;
2453  case OBJECT_DOMCONSTRAINT:
2454  {
2455  HeapTuple tuple;
2456  Oid contypid;
2457 
2458  tuple = SearchSysCache1(CONSTROID,
2459  ObjectIdGetDatum(address.objectId));
2460  if (!HeapTupleIsValid(tuple))
2461  elog(ERROR, "constraint with OID %u does not exist",
2462  address.objectId);
2463 
2464  contypid = ((Form_pg_constraint) GETSTRUCT(tuple))->contypid;
2465 
2466  ReleaseSysCache(tuple);
2467 
2468  /*
2469  * Fallback to type ownership check in this case as this is
2470  * what domain constraints rely on.
2471  */
2472  if (!pg_type_ownercheck(contypid, roleid))
2474  }
2475  break;
2476  case OBJECT_AGGREGATE:
2477  case OBJECT_FUNCTION:
2478  case OBJECT_PROCEDURE:
2479  case OBJECT_ROUTINE:
2480  if (!pg_proc_ownercheck(address.objectId, roleid))
2482  NameListToString((castNode(ObjectWithArgs, object))->objname));
2483  break;
2484  case OBJECT_OPERATOR:
2485  if (!pg_oper_ownercheck(address.objectId, roleid))
2487  NameListToString((castNode(ObjectWithArgs, object))->objname));
2488  break;
2489  case OBJECT_SCHEMA:
2490  if (!pg_namespace_ownercheck(address.objectId, roleid))
2492  strVal(object));
2493  break;
2494  case OBJECT_COLLATION:
2495  if (!pg_collation_ownercheck(address.objectId, roleid))
2497  NameListToString(castNode(List, object)));
2498  break;
2499  case OBJECT_CONVERSION:
2500  if (!pg_conversion_ownercheck(address.objectId, roleid))
2502  NameListToString(castNode(List, object)));
2503  break;
2504  case OBJECT_EXTENSION:
2505  if (!pg_extension_ownercheck(address.objectId, roleid))
2507  strVal(object));
2508  break;
2509  case OBJECT_FDW:
2510  if (!pg_foreign_data_wrapper_ownercheck(address.objectId, roleid))
2512  strVal(object));
2513  break;
2514  case OBJECT_FOREIGN_SERVER:
2515  if (!pg_foreign_server_ownercheck(address.objectId, roleid))
2517  strVal(object));
2518  break;
2519  case OBJECT_EVENT_TRIGGER:
2520  if (!pg_event_trigger_ownercheck(address.objectId, roleid))
2522  strVal(object));
2523  break;
2524  case OBJECT_LANGUAGE:
2525  if (!pg_language_ownercheck(address.objectId, roleid))
2527  strVal(object));
2528  break;
2529  case OBJECT_OPCLASS:
2530  if (!pg_opclass_ownercheck(address.objectId, roleid))
2532  NameListToString(castNode(List, object)));
2533  break;
2534  case OBJECT_OPFAMILY:
2535  if (!pg_opfamily_ownercheck(address.objectId, roleid))
2537  NameListToString(castNode(List, object)));
2538  break;
2539  case OBJECT_LARGEOBJECT:
2540  if (!lo_compat_privileges &&
2541  !pg_largeobject_ownercheck(address.objectId, roleid))
2542  ereport(ERROR,
2543  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2544  errmsg("must be owner of large object %u",
2545  address.objectId)));
2546  break;
2547  case OBJECT_CAST:
2548  {
2549  /* We can only check permissions on the source/target types */
2550  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2551  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2552  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2553  Oid targettypeid = typenameTypeId(NULL, targettype);
2554 
2555  if (!pg_type_ownercheck(sourcetypeid, roleid)
2556  && !pg_type_ownercheck(targettypeid, roleid))
2557  ereport(ERROR,
2558  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2559  errmsg("must be owner of type %s or type %s",
2560  format_type_be(sourcetypeid),
2561  format_type_be(targettypeid))));
2562  }
2563  break;
2564  case OBJECT_PUBLICATION:
2565  if (!pg_publication_ownercheck(address.objectId, roleid))
2567  strVal(object));
2568  break;
2569  case OBJECT_SUBSCRIPTION:
2570  if (!pg_subscription_ownercheck(address.objectId, roleid))
2572  strVal(object));
2573  break;
2574  case OBJECT_TRANSFORM:
2575  {
2576  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2577  Oid typeid = typenameTypeId(NULL, typename);
2578 
2579  if (!pg_type_ownercheck(typeid, roleid))
2581  }
2582  break;
2583  case OBJECT_TABLESPACE:
2584  if (!pg_tablespace_ownercheck(address.objectId, roleid))
2586  strVal(object));
2587  break;
2588  case OBJECT_TSDICTIONARY:
2589  if (!pg_ts_dict_ownercheck(address.objectId, roleid))
2591  NameListToString(castNode(List, object)));
2592  break;
2594  if (!pg_ts_config_ownercheck(address.objectId, roleid))
2596  NameListToString(castNode(List, object)));
2597  break;
2598  case OBJECT_ROLE:
2599 
2600  /*
2601  * We treat roles as being "owned" by those with CREATEROLE priv,
2602  * except that superusers are only owned by superusers.
2603  */
2604  if (superuser_arg(address.objectId))
2605  {
2606  if (!superuser_arg(roleid))
2607  ereport(ERROR,
2608  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2609  errmsg("must be superuser")));
2610  }
2611  else
2612  {
2613  if (!has_createrole_privilege(roleid))
2614  ereport(ERROR,
2615  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2616  errmsg("must have CREATEROLE privilege")));
2617  }
2618  break;
2619  case OBJECT_TSPARSER:
2620  case OBJECT_TSTEMPLATE:
2621  case OBJECT_ACCESS_METHOD:
2622  /* We treat these object types as being owned by superusers */
2623  if (!superuser_arg(roleid))
2624  ereport(ERROR,
2625  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2626  errmsg("must be superuser")));
2627  break;
2628  case OBJECT_STATISTIC_EXT:
2629  if (!pg_statistics_object_ownercheck(address.objectId, roleid))
2631  NameListToString(castNode(List, object)));
2632  break;
2633  default:
2634  elog(ERROR, "unrecognized object type: %d",
2635  (int) objtype);
2636  }
2637 }
@ ACLCHECK_NOT_OWNER
Definition: acl.h:181
bool pg_language_ownercheck(Oid lan_oid, Oid roleid)
Definition: aclchk.c:4924
bool pg_namespace_ownercheck(Oid nsp_oid, Oid roleid)
Definition: aclchk.c:4996
bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5157
bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid)
Definition: aclchk.c:5103
bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid)
Definition: aclchk.c:5130
bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid)
Definition: aclchk.c:5049
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5384
bool pg_proc_ownercheck(Oid proc_oid, Oid roleid)
Definition: aclchk.c:4898
bool pg_largeobject_ownercheck(Oid lobj_oid, Oid roleid)
Definition: aclchk.c:4953
bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid)
Definition: aclchk.c:5022
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:5264
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5316
bool pg_type_ownercheck(Oid type_oid, Oid roleid)
Definition: aclchk.c:4846
bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5184
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
Definition: aclchk.c:5238
bool pg_class_ownercheck(Oid class_oid, Oid roleid)
Definition: aclchk.c:4820
bool pg_oper_ownercheck(Oid oper_oid, Oid roleid)
Definition: aclchk.c:4872
bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
Definition: aclchk.c:5076
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:5211
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3308
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3623
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:5445
bool pg_statistics_object_ownercheck(Oid stat_oid, Oid roleid)
Definition: aclchk.c:5410
bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid)
Definition: aclchk.c:5290
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5358
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ERROR
Definition: elog.h:33
#define elog(elevel,...)
Definition: elog.h:218
#define ereport(elevel,...)
Definition: elog.h:143
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:649
bool lo_compat_privileges
Definition: inv_api.c:58
char * NameListToString(List *names)
Definition: namespace.c:3147
#define castNode(_type_, nodeptr)
Definition: nodes.h:608
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:291
@ OBJECT_EVENT_TRIGGER
Definition: parsenodes.h:1803
@ OBJECT_FDW
Definition: parsenodes.h:1805
@ OBJECT_TSPARSER
Definition: parsenodes.h:1835
@ OBJECT_COLLATION
Definition: parsenodes.h:1796
@ OBJECT_ACCESS_METHOD
Definition: parsenodes.h:1789
@ OBJECT_OPCLASS
Definition: parsenodes.h:1813
@ OBJECT_AGGREGATE
Definition: parsenodes.h:1790
@ OBJECT_MATVIEW
Definition: parsenodes.h:1812
@ OBJECT_SCHEMA
Definition: parsenodes.h:1824
@ OBJECT_POLICY
Definition: parsenodes.h:1816
@ OBJECT_OPERATOR
Definition: parsenodes.h:1814
@ OBJECT_FOREIGN_TABLE
Definition: parsenodes.h:1807
@ OBJECT_TSCONFIGURATION
Definition: parsenodes.h:1833
@ OBJECT_OPFAMILY
Definition: parsenodes.h:1815
@ OBJECT_DOMAIN
Definition: parsenodes.h:1801
@ OBJECT_COLUMN
Definition: parsenodes.h:1795
@ OBJECT_TABLESPACE
Definition: parsenodes.h:1830
@ OBJECT_ROLE
Definition: parsenodes.h:1821
@ OBJECT_ROUTINE
Definition: parsenodes.h:1822
@ OBJECT_LARGEOBJECT
Definition: parsenodes.h:1811
@ OBJECT_PROCEDURE
Definition: parsenodes.h:1817
@ OBJECT_EXTENSION
Definition: parsenodes.h:1804
@ OBJECT_INDEX
Definition: parsenodes.h:1809
@ OBJECT_DATABASE
Definition: parsenodes.h:1798
@ OBJECT_SEQUENCE
Definition: parsenodes.h:1825
@ OBJECT_TSTEMPLATE
Definition: parsenodes.h:1836
@ OBJECT_LANGUAGE
Definition: parsenodes.h:1810
@ OBJECT_FOREIGN_SERVER
Definition: parsenodes.h:1806
@ OBJECT_TSDICTIONARY
Definition: parsenodes.h:1834
@ OBJECT_ATTRIBUTE
Definition: parsenodes.h:1793
@ OBJECT_PUBLICATION
Definition: parsenodes.h:1818
@ OBJECT_RULE
Definition: parsenodes.h:1823
@ OBJECT_CONVERSION
Definition: parsenodes.h:1797
@ OBJECT_TABLE
Definition: parsenodes.h:1829
@ OBJECT_VIEW
Definition: parsenodes.h:1839
@ OBJECT_TYPE
Definition: parsenodes.h:1837
@ OBJECT_FUNCTION
Definition: parsenodes.h:1808
@ OBJECT_TABCONSTRAINT
Definition: parsenodes.h:1828
@ OBJECT_DOMCONSTRAINT
Definition: parsenodes.h:1802
@ OBJECT_SUBSCRIPTION
Definition: parsenodes.h:1826
@ OBJECT_STATISTIC_EXT
Definition: parsenodes.h:1827
@ OBJECT_CAST
Definition: parsenodes.h:1794
@ OBJECT_TRIGGER
Definition: parsenodes.h:1832
@ OBJECT_TRANSFORM
Definition: parsenodes.h:1831
FormData_pg_constraint * Form_pg_constraint
#define linitial_node(type, l)
Definition: pg_list.h:177
#define lsecond_node(type, l)
Definition: pg_list.h:182
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
unsigned int Oid
Definition: postgres_ext.h:31
#define RelationGetRelid(relation)
Definition: rel.h:478
#define RelationGetRelationName(relation)
Definition: rel.h:512
Definition: pg_list.h:51
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1198
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1150
@ CONSTROID
Definition: syscache.h:53
#define strVal(v)
Definition: value.h:72

References aclcheck_error(), aclcheck_error_type(), ACLCHECK_NOT_OWNER, castNode, CONSTROID, elog, ereport, errcode(), errmsg(), ERROR, format_type_be(), GETSTRUCT, has_createrole_privilege(), HeapTupleIsValid, linitial_node, lo_compat_privileges, lsecond_node, NameListToString(), OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_ATTRIBUTE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, 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_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, 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_VIEW, ObjectAddress::objectId, ObjectIdGetDatum, pg_class_ownercheck(), pg_collation_ownercheck(), pg_conversion_ownercheck(), pg_database_ownercheck(), pg_event_trigger_ownercheck(), pg_extension_ownercheck(), pg_foreign_data_wrapper_ownercheck(), pg_foreign_server_ownercheck(), pg_language_ownercheck(), pg_largeobject_ownercheck(), pg_namespace_ownercheck(), pg_opclass_ownercheck(), pg_oper_ownercheck(), pg_opfamily_ownercheck(), pg_proc_ownercheck(), pg_publication_ownercheck(), pg_statistics_object_ownercheck(), pg_subscription_ownercheck(), pg_tablespace_ownercheck(), pg_ts_config_ownercheck(), pg_ts_dict_ownercheck(), pg_type_ownercheck(), 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 2866 of file objectaddress.c.

2867 {
2868  HeapTuple tuple;
2869  Oid classId = RelationGetRelid(catalog);
2870  int oidCacheId = get_object_catcache_oid(classId);
2871 
2872  if (oidCacheId > 0)
2873  {
2874  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2875  if (!HeapTupleIsValid(tuple)) /* should not happen */
2876  return NULL;
2877  }
2878  else
2879  {
2880  Oid oidIndexId = get_object_oid_index(classId);
2881  SysScanDesc scan;
2882  ScanKeyData skey;
2883 
2884  Assert(OidIsValid(oidIndexId));
2885 
2886  ScanKeyInit(&skey,
2887  oidcol,
2888  BTEqualStrategyNumber, F_OIDEQ,
2889  ObjectIdGetDatum(objectId));
2890 
2891  scan = systable_beginscan(catalog, oidIndexId, true,
2892  NULL, 1, &skey);
2893  tuple = systable_getnext(scan);
2894  if (!HeapTupleIsValid(tuple))
2895  {
2896  systable_endscan(scan);
2897  return NULL;
2898  }
2899  tuple = heap_copytuple(tuple);
2900 
2901  systable_endscan(scan);
2902  }
2903 
2904  return tuple;
2905 }
#define OidIsValid(objectId)
Definition: c.h:710
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:598
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:505
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:386
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:177

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

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

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

1238 {
1239  if (rel)
1240  {
1241  object = lcons(makeString(rel->relname), object);
1242  if (rel->schemaname)
1243  object = lcons(makeString(rel->schemaname), object);
1244  if (rel->catalogname)
1245  object = lcons(makeString(rel->catalogname), object);
1246  }
1247 
1248  return get_object_address(objtype, (Node *) object,
1249  relp, lockmode, missing_ok);
1250 }
List * lcons(void *datum, List *list)
Definition: list.c:474
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
Definition: nodes.h:540
char * relname
Definition: primnodes.h:68
char * catalogname
Definition: primnodes.h:66
char * schemaname
Definition: primnodes.h:67
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 2769 of file objectaddress.c.

2770 {
2771  const ObjectPropertyType *prop = get_object_property_data(class_id);
2772 
2773  return prop->attnum_acl;
2774 }
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().

◆ 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)

Definition at line 2761 of file objectaddress.c.

2762 {
2763  const ObjectPropertyType *prop = get_object_property_data(class_id);
2764 
2765  return prop->attnum_owner;
2766 }
AttrNumber attnum_owner

References ObjectPropertyType::attnum_owner, and get_object_property_data().

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

◆ get_object_catcache_name()

int get_object_catcache_name ( Oid  class_id)

Definition at line 2729 of file objectaddress.c.

2730 {
2731  const ObjectPropertyType *prop = get_object_property_data(class_id);
2732 
2733  return prop->name_catcache_id;
2734 }

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

◆ get_object_catcache_oid()

int get_object_catcache_oid ( Oid  class_id)

◆ get_object_class_descr()

const char* get_object_class_descr ( Oid  class_id)

Definition at line 2705 of file objectaddress.c.

2706 {
2707  const ObjectPropertyType *prop = get_object_property_data(class_id);
2708 
2709  return prop->class_descr;
2710 }
const char * class_descr

References ObjectPropertyType::class_descr, and get_object_property_data().

Referenced by DropObjectById().

◆ get_object_namensp_unique()

bool get_object_namensp_unique ( Oid  class_id)

Definition at line 2802 of file objectaddress.c.

2803 {
2804  const ObjectPropertyType *prop = get_object_property_data(class_id);
2805 
2806  return prop->is_nsp_name_unique;
2807 }

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

2647 {
2648  int cache;
2649  HeapTuple tuple;
2650  bool isnull;
2651  Oid oid;
2652  const ObjectPropertyType *property;
2653 
2654  /* If not owned by a namespace, just return InvalidOid. */
2655  property = get_object_property_data(address->classId);
2656  if (property->attnum_namespace == InvalidAttrNumber)
2657  return InvalidOid;
2658 
2659  /* Currently, we can only handle object types with system caches. */
2660  cache = property->oid_catcache_id;
2661  Assert(cache != -1);
2662 
2663  /* Fetch tuple from syscache and extract namespace attribute. */
2664  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2665  if (!HeapTupleIsValid(tuple))
2666  elog(ERROR, "cache lookup failed for cache %d oid %u",
2667  cache, address->objectId);
2668  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2669  tuple,
2670  property->attnum_namespace,
2671  &isnull));
2672  Assert(!isnull);
2673  ReleaseSysCache(tuple);
2674 
2675  return oid;
2676 }
#define InvalidAttrNumber
Definition: attnum.h:23
#define DatumGetObjectId(X)
Definition: postgres.h:544
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1411

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

2714 {
2715  const ObjectPropertyType *prop = get_object_property_data(class_id);
2716 
2717  return prop->oid_index_oid;
2718 }

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by DropObjectById(), and get_catalog_object_by_oid().

◆ get_object_type()

ObjectType get_object_type ( Oid  class_id,
Oid  object_id 
)

Definition at line 2784 of file objectaddress.c.

2785 {
2786  const ObjectPropertyType *prop = get_object_property_data(class_id);
2787 
2788  if (prop->objtype == OBJECT_TABLE)
2789  {
2790  /*
2791  * If the property data says it's a table, dig a little deeper to get
2792  * the real relation kind, so that callers can produce more precise
2793  * error messages.
2794  */
2795  return get_relkind_objtype(get_rel_relkind(object_id));
2796  }
2797  else
2798  return prop->objtype;
2799 }
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1974
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(), and AlterObjectRename_internal().

◆ get_relkind_objtype()

ObjectType get_relkind_objtype ( char  relkind)

Definition at line 6086 of file objectaddress.c.

6087 {
6088  switch (relkind)
6089  {
6090  case RELKIND_RELATION:
6091  case RELKIND_PARTITIONED_TABLE:
6092  return OBJECT_TABLE;
6093  case RELKIND_INDEX:
6094  case RELKIND_PARTITIONED_INDEX:
6095  return OBJECT_INDEX;
6096  case RELKIND_SEQUENCE:
6097  return OBJECT_SEQUENCE;
6098  case RELKIND_VIEW:
6099  return OBJECT_VIEW;
6100  case RELKIND_MATVIEW:
6101  return OBJECT_MATVIEW;
6102  case RELKIND_FOREIGN_TABLE:
6103  return OBJECT_FOREIGN_TABLE;
6104  case RELKIND_TOASTVALUE:
6105  return OBJECT_TABLE;
6106  default:
6107  /* Per above, don't raise an error */
6108  return OBJECT_TABLE;
6109  }
6110 }

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(), ExecCheckRTPerms(), 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(), RangeVarCallbackOwnsTable(), RangeVarGetAndCheckCreationNamespace(), renameatt_check(), TargetPrivilegesCheck(), transformTableLikeClause(), and truncate_check_perms().

◆ getObjectDescription()

char* getObjectDescription ( const ObjectAddress object,
bool  missing_ok 
)

Definition at line 2963 of file objectaddress.c.

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

References _, AccessShareLock, AMOID, appendStringInfo(), Assert(), attname, BTEqualStrategyNumber, CLAOID, ObjectAddress::classId, 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(), 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_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_NAMESPACE, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, 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(), pfree(), proname, PUBLICATIONREL, quote_qualified_identifier(), ReleaseSysCache(), ScanKeyInit(), SearchSysCache1(), ForeignServer::servername, STATEXTOID, StatisticsObjIsVisible(), subname, systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TRFOID, TSConfigIsVisible(), TSCONFIGOID, TSDictionaryIsVisible(), TSDICTOID, TSParserIsVisible(), TSPARSEROID, TSTemplateIsVisible(), TSTEMPLATEOID, typname, USERMAPPINGOID, and username.

Referenced by AlterExtensionNamespace(), ATExecAlterColumnType(), changeDependenciesOn(), check_relation_privileges(), checkSharedDependencies(), ExecAlterExtensionContentsStmt(), findDependentObjects(), 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 4079 of file objectaddress.c.

4080 {
4081  ObjectAddress address;
4082 
4083  address.classId = classid;
4084  address.objectId = objid;
4085  address.objectSubId = 0;
4086 
4087  return getObjectDescription(&address, false);
4088 }

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

◆ getObjectIdentity()

◆ getObjectIdentityParts()

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

Definition at line 4781 of file objectaddress.c.

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

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

2815 {
2816  int index;
2817 
2818  for (index = 0; index < lengthof(ObjectProperty); index++)
2819  {
2820  if (ObjectProperty[index].class_oid == class_id)
2821  return true;
2822  }
2823 
2824  return false;
2825 }
#define lengthof(array)
Definition: c.h:734
static const ObjectPropertyType ObjectProperty[]
Definition: type.h:90

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

2686 {
2687  int i;
2688 
2689  for (i = 0; i < lengthof(ObjectTypeMap); i++)
2690  {
2691  if (strcmp(ObjectTypeMap[i].tm_name, objtype) == 0)
2692  return ObjectTypeMap[i].tm_type;
2693  }
2694  ereport(ERROR,
2695  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2696  errmsg("unrecognized object type \"%s\"", objtype)));
2697 
2698  return -1; /* keep compiler quiet */
2699 }
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 6031 of file objectaddress.c.

6032 {
6033  ArrayType *arr;
6034  Datum *datums;
6035  bool *nulls;
6036  int j = 0;
6037  ListCell *cell;
6038  MemoryContext memcxt;
6039  MemoryContext oldcxt;
6040  int lb[1];
6041 
6042  /* Work in a temp context; easier than individually pfree'ing the Datums */
6044  "strlist to array",
6046  oldcxt = MemoryContextSwitchTo(memcxt);
6047 
6048  datums = (Datum *) palloc(sizeof(Datum) * list_length(list));
6049  nulls = palloc(sizeof(bool) * list_length(list));
6050 
6051  foreach(cell, list)
6052  {
6053  char *name = lfirst(cell);
6054 
6055  if (name)
6056  {
6057  nulls[j] = false;
6058  datums[j++] = CStringGetTextDatum(name);
6059  }
6060  else
6061  nulls[j] = true;
6062  }
6063 
6064  MemoryContextSwitchTo(oldcxt);
6065 
6066  lb[0] = 1;
6067  arr = construct_md_array(datums, nulls, 1, &j,
6068  lb, TEXTOID, -1, false, TYPALIGN_INT);
6069 
6070  MemoryContextDelete(memcxt);
6071 
6072  return arr;
6073 }
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:3354
#define CStringGetTextDatum(s)
Definition: builtins.h:85
const char * name
Definition: encode.c:561
int j
Definition: isn.c:74
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:218
void * palloc(Size size)
Definition: mcxt.c:1062
#define AllocSetContextCreate
Definition: memutils.h:173
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:195
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define lfirst(lc)
Definition: pg_list.h:169
static int list_length(const List *l)
Definition: pg_list.h:149
uintptr_t Datum
Definition: postgres.h:411

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