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

PGDLLIMPORT const ObjectAddress InvalidObjectAddress
 

Macro Definition Documentation

◆ ObjectAddressSet

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

Definition at line 40 of file objectaddress.h.

◆ ObjectAddressSubSet

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

Definition at line 33 of file objectaddress.h.

Typedef Documentation

◆ ObjectAddress

typedef struct ObjectAddress ObjectAddress

Function Documentation

◆ check_object_ownership()

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

Definition at line 2401 of file objectaddress.c.

2403 {
2404  switch (objtype)
2405  {
2406  case OBJECT_INDEX:
2407  case OBJECT_SEQUENCE:
2408  case OBJECT_TABLE:
2409  case OBJECT_VIEW:
2410  case OBJECT_MATVIEW:
2411  case OBJECT_FOREIGN_TABLE:
2412  case OBJECT_COLUMN:
2413  case OBJECT_RULE:
2414  case OBJECT_TRIGGER:
2415  case OBJECT_POLICY:
2416  case OBJECT_TABCONSTRAINT:
2417  if (!pg_class_ownercheck(RelationGetRelid(relation), roleid))
2419  RelationGetRelationName(relation));
2420  break;
2421  case OBJECT_DATABASE:
2422  if (!pg_database_ownercheck(address.objectId, roleid))
2424  strVal(object));
2425  break;
2426  case OBJECT_TYPE:
2427  case OBJECT_DOMAIN:
2428  case OBJECT_ATTRIBUTE:
2429  if (!pg_type_ownercheck(address.objectId, roleid))
2431  break;
2432  case OBJECT_DOMCONSTRAINT:
2433  {
2434  HeapTuple tuple;
2435  Oid contypid;
2436 
2437  tuple = SearchSysCache1(CONSTROID,
2438  ObjectIdGetDatum(address.objectId));
2439  if (!HeapTupleIsValid(tuple))
2440  elog(ERROR, "constraint with OID %u does not exist",
2441  address.objectId);
2442 
2443  contypid = ((Form_pg_constraint) GETSTRUCT(tuple))->contypid;
2444 
2445  ReleaseSysCache(tuple);
2446 
2447  /*
2448  * Fallback to type ownership check in this case as this is
2449  * what domain constraints rely on.
2450  */
2451  if (!pg_type_ownercheck(contypid, roleid))
2453  }
2454  break;
2455  case OBJECT_AGGREGATE:
2456  case OBJECT_FUNCTION:
2457  case OBJECT_PROCEDURE:
2458  case OBJECT_ROUTINE:
2459  if (!pg_proc_ownercheck(address.objectId, roleid))
2461  NameListToString((castNode(ObjectWithArgs, object))->objname));
2462  break;
2463  case OBJECT_OPERATOR:
2464  if (!pg_oper_ownercheck(address.objectId, roleid))
2466  NameListToString((castNode(ObjectWithArgs, object))->objname));
2467  break;
2468  case OBJECT_SCHEMA:
2469  if (!pg_namespace_ownercheck(address.objectId, roleid))
2471  strVal(object));
2472  break;
2473  case OBJECT_COLLATION:
2474  if (!pg_collation_ownercheck(address.objectId, roleid))
2476  NameListToString(castNode(List, object)));
2477  break;
2478  case OBJECT_CONVERSION:
2479  if (!pg_conversion_ownercheck(address.objectId, roleid))
2481  NameListToString(castNode(List, object)));
2482  break;
2483  case OBJECT_EXTENSION:
2484  if (!pg_extension_ownercheck(address.objectId, roleid))
2486  strVal(object));
2487  break;
2488  case OBJECT_FDW:
2489  if (!pg_foreign_data_wrapper_ownercheck(address.objectId, roleid))
2491  strVal(object));
2492  break;
2493  case OBJECT_FOREIGN_SERVER:
2494  if (!pg_foreign_server_ownercheck(address.objectId, roleid))
2496  strVal(object));
2497  break;
2498  case OBJECT_EVENT_TRIGGER:
2499  if (!pg_event_trigger_ownercheck(address.objectId, roleid))
2501  strVal(object));
2502  break;
2503  case OBJECT_LANGUAGE:
2504  if (!pg_language_ownercheck(address.objectId, roleid))
2506  strVal(object));
2507  break;
2508  case OBJECT_OPCLASS:
2509  if (!pg_opclass_ownercheck(address.objectId, roleid))
2511  NameListToString(castNode(List, object)));
2512  break;
2513  case OBJECT_OPFAMILY:
2514  if (!pg_opfamily_ownercheck(address.objectId, roleid))
2516  NameListToString(castNode(List, object)));
2517  break;
2518  case OBJECT_LARGEOBJECT:
2519  if (!lo_compat_privileges &&
2520  !pg_largeobject_ownercheck(address.objectId, roleid))
2521  ereport(ERROR,
2522  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2523  errmsg("must be owner of large object %u",
2524  address.objectId)));
2525  break;
2526  case OBJECT_CAST:
2527  {
2528  /* We can only check permissions on the source/target types */
2529  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2530  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2531  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2532  Oid targettypeid = typenameTypeId(NULL, targettype);
2533 
2534  if (!pg_type_ownercheck(sourcetypeid, roleid)
2535  && !pg_type_ownercheck(targettypeid, roleid))
2536  ereport(ERROR,
2537  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2538  errmsg("must be owner of type %s or type %s",
2539  format_type_be(sourcetypeid),
2540  format_type_be(targettypeid))));
2541  }
2542  break;
2543  case OBJECT_PUBLICATION:
2544  if (!pg_publication_ownercheck(address.objectId, roleid))
2546  strVal(object));
2547  break;
2548  case OBJECT_SUBSCRIPTION:
2549  if (!pg_subscription_ownercheck(address.objectId, roleid))
2551  strVal(object));
2552  break;
2553  case OBJECT_TRANSFORM:
2554  {
2555  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2556  Oid typeid = typenameTypeId(NULL, typename);
2557 
2558  if (!pg_type_ownercheck(typeid, roleid))
2560  }
2561  break;
2562  case OBJECT_TABLESPACE:
2563  if (!pg_tablespace_ownercheck(address.objectId, roleid))
2565  strVal(object));
2566  break;
2567  case OBJECT_TSDICTIONARY:
2568  if (!pg_ts_dict_ownercheck(address.objectId, roleid))
2570  NameListToString(castNode(List, object)));
2571  break;
2573  if (!pg_ts_config_ownercheck(address.objectId, roleid))
2575  NameListToString(castNode(List, object)));
2576  break;
2577  case OBJECT_ROLE:
2578 
2579  /*
2580  * We treat roles as being "owned" by those with CREATEROLE priv,
2581  * except that superusers are only owned by superusers.
2582  */
2583  if (superuser_arg(address.objectId))
2584  {
2585  if (!superuser_arg(roleid))
2586  ereport(ERROR,
2587  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2588  errmsg("must be superuser")));
2589  }
2590  else
2591  {
2592  if (!has_createrole_privilege(roleid))
2593  ereport(ERROR,
2594  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2595  errmsg("must have CREATEROLE privilege")));
2596  }
2597  break;
2598  case OBJECT_TSPARSER:
2599  case OBJECT_TSTEMPLATE:
2600  case OBJECT_ACCESS_METHOD:
2601  case OBJECT_PARAMETER_ACL:
2602  /* We treat these object types as being owned by superusers */
2603  if (!superuser_arg(roleid))
2604  ereport(ERROR,
2605  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2606  errmsg("must be superuser")));
2607  break;
2608  case OBJECT_STATISTIC_EXT:
2609  if (!pg_statistics_object_ownercheck(address.objectId, roleid))
2611  NameListToString(castNode(List, object)));
2612  break;
2613  default:
2614  elog(ERROR, "unrecognized object type: %d",
2615  (int) objtype);
2616  }
2617 }
@ ACLCHECK_NOT_OWNER
Definition: acl.h:184
bool pg_language_ownercheck(Oid lan_oid, Oid roleid)
Definition: aclchk.c:5275
bool pg_namespace_ownercheck(Oid nsp_oid, Oid roleid)
Definition: aclchk.c:5347
bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5508
bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid)
Definition: aclchk.c:5454
bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid)
Definition: aclchk.c:5481
bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid)
Definition: aclchk.c:5400
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5735
bool pg_proc_ownercheck(Oid proc_oid, Oid roleid)
Definition: aclchk.c:5249
bool pg_largeobject_ownercheck(Oid lobj_oid, Oid roleid)
Definition: aclchk.c:5304
bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid)
Definition: aclchk.c:5373
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:5615
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5667
bool pg_type_ownercheck(Oid type_oid, Oid roleid)
Definition: aclchk.c:5197
bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5535
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
Definition: aclchk.c:5589
bool pg_class_ownercheck(Oid class_oid, Oid roleid)
Definition: aclchk.c:5171
bool pg_oper_ownercheck(Oid oper_oid, Oid roleid)
Definition: aclchk.c:5223
bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
Definition: aclchk.c:5427
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:5562
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3512
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3831
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:5796
bool pg_statistics_object_ownercheck(Oid stat_oid, Oid roleid)
Definition: aclchk.c:5761
bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid)
Definition: aclchk.c:5641
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5709
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:143
char * format_type_be(Oid type_oid)
Definition: format_type.c:343
#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:3148
#define castNode(_type_, nodeptr)
Definition: nodes.h:643
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:291
@ OBJECT_EVENT_TRIGGER
Definition: parsenodes.h:2149
@ OBJECT_FDW
Definition: parsenodes.h:2151
@ OBJECT_TSPARSER
Definition: parsenodes.h:2182
@ OBJECT_COLLATION
Definition: parsenodes.h:2142
@ OBJECT_ACCESS_METHOD
Definition: parsenodes.h:2135
@ OBJECT_OPCLASS
Definition: parsenodes.h:2159
@ OBJECT_AGGREGATE
Definition: parsenodes.h:2136
@ OBJECT_MATVIEW
Definition: parsenodes.h:2158
@ OBJECT_SCHEMA
Definition: parsenodes.h:2171
@ OBJECT_POLICY
Definition: parsenodes.h:2163
@ OBJECT_OPERATOR
Definition: parsenodes.h:2160
@ OBJECT_FOREIGN_TABLE
Definition: parsenodes.h:2153
@ OBJECT_TSCONFIGURATION
Definition: parsenodes.h:2180
@ OBJECT_OPFAMILY
Definition: parsenodes.h:2161
@ OBJECT_DOMAIN
Definition: parsenodes.h:2147
@ OBJECT_COLUMN
Definition: parsenodes.h:2141
@ OBJECT_TABLESPACE
Definition: parsenodes.h:2177
@ OBJECT_ROLE
Definition: parsenodes.h:2168
@ OBJECT_ROUTINE
Definition: parsenodes.h:2169
@ OBJECT_LARGEOBJECT
Definition: parsenodes.h:2157
@ OBJECT_PROCEDURE
Definition: parsenodes.h:2164
@ OBJECT_EXTENSION
Definition: parsenodes.h:2150
@ OBJECT_INDEX
Definition: parsenodes.h:2155
@ OBJECT_DATABASE
Definition: parsenodes.h:2144
@ OBJECT_SEQUENCE
Definition: parsenodes.h:2172
@ OBJECT_TSTEMPLATE
Definition: parsenodes.h:2183
@ OBJECT_LANGUAGE
Definition: parsenodes.h:2156
@ OBJECT_FOREIGN_SERVER
Definition: parsenodes.h:2152
@ OBJECT_TSDICTIONARY
Definition: parsenodes.h:2181
@ OBJECT_ATTRIBUTE
Definition: parsenodes.h:2139
@ OBJECT_PUBLICATION
Definition: parsenodes.h:2165
@ OBJECT_RULE
Definition: parsenodes.h:2170
@ OBJECT_CONVERSION
Definition: parsenodes.h:2143
@ OBJECT_TABLE
Definition: parsenodes.h:2176
@ OBJECT_VIEW
Definition: parsenodes.h:2186
@ OBJECT_PARAMETER_ACL
Definition: parsenodes.h:2162
@ OBJECT_TYPE
Definition: parsenodes.h:2184
@ OBJECT_FUNCTION
Definition: parsenodes.h:2154
@ OBJECT_TABCONSTRAINT
Definition: parsenodes.h:2175
@ OBJECT_DOMCONSTRAINT
Definition: parsenodes.h:2148
@ OBJECT_SUBSCRIPTION
Definition: parsenodes.h:2173
@ OBJECT_STATISTIC_EXT
Definition: parsenodes.h:2174
@ OBJECT_CAST
Definition: parsenodes.h:2140
@ OBJECT_TRIGGER
Definition: parsenodes.h:2179
@ OBJECT_TRANSFORM
Definition: parsenodes.h:2178
FormData_pg_constraint * Form_pg_constraint
#define linitial_node(type, l)
Definition: pg_list.h:179
#define lsecond_node(type, l)
Definition: pg_list.h:184
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
unsigned int Oid
Definition: postgres_ext.h:31
#define RelationGetRelid(relation)
Definition: rel.h:488
#define RelationGetRelationName(relation)
Definition: rel.h:522
Definition: pg_list.h:52
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1221
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1173
@ 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_PARAMETER_ACL, 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 2846 of file objectaddress.c.

2847 {
2848  HeapTuple tuple;
2849  Oid classId = RelationGetRelid(catalog);
2850  int oidCacheId = get_object_catcache_oid(classId);
2851 
2852  if (oidCacheId > 0)
2853  {
2854  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2855  if (!HeapTupleIsValid(tuple)) /* should not happen */
2856  return NULL;
2857  }
2858  else
2859  {
2860  Oid oidIndexId = get_object_oid_index(classId);
2861  SysScanDesc scan;
2862  ScanKeyData skey;
2863 
2864  Assert(OidIsValid(oidIndexId));
2865 
2866  ScanKeyInit(&skey,
2867  oidcol,
2868  BTEqualStrategyNumber, F_OIDEQ,
2869  ObjectIdGetDatum(objectId));
2870 
2871  scan = systable_beginscan(catalog, oidIndexId, true,
2872  NULL, 1, &skey);
2873  tuple = systable_getnext(scan);
2874  if (!HeapTupleIsValid(tuple))
2875  {
2876  systable_endscan(scan);
2877  return NULL;
2878  }
2879  tuple = heap_copytuple(tuple);
2880 
2881  systable_endscan(scan);
2882  }
2883 
2884  return tuple;
2885 }
#define OidIsValid(objectId)
Definition: c.h:721
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:179

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

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

◆ get_object_address()

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

Definition at line 941 of file objectaddress.c.

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

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

◆ get_object_address_rv()

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

Definition at line 1240 of file objectaddress.c.

1243 {
1244  if (rel)
1245  {
1246  object = lcons(makeString(rel->relname), object);
1247  if (rel->schemaname)
1248  object = lcons(makeString(rel->schemaname), object);
1249  if (rel->catalogname)
1250  object = lcons(makeString(rel->catalogname), object);
1251  }
1252 
1253  return get_object_address(objtype, (Node *) object,
1254  relp, lockmode, missing_ok);
1255 }
List * lcons(void *datum, List *list)
Definition: list.c:494
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
Definition: nodes.h:575
char * relname
Definition: primnodes.h:74
char * catalogname
Definition: primnodes.h:68
char * schemaname
Definition: primnodes.h:71
String * makeString(char *str)
Definition: value.c:63

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

Referenced by ExecAlterObjectDependsStmt().

◆ get_object_attnum_acl()

AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 2749 of file objectaddress.c.

2750 {
2751  const ObjectPropertyType *prop = get_object_property_data(class_id);
2752 
2753  return prop->attnum_acl;
2754 }
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 2741 of file objectaddress.c.

2742 {
2743  const ObjectPropertyType *prop = get_object_property_data(class_id);
2744 
2745  return prop->attnum_owner;
2746 }
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 2709 of file objectaddress.c.

2710 {
2711  const ObjectPropertyType *prop = get_object_property_data(class_id);
2712 
2713  return prop->name_catcache_id;
2714 }

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

2686 {
2687  const ObjectPropertyType *prop = get_object_property_data(class_id);
2688 
2689  return prop->class_descr;
2690 }
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 2782 of file objectaddress.c.

2783 {
2784  const ObjectPropertyType *prop = get_object_property_data(class_id);
2785 
2786  return prop->is_nsp_name_unique;
2787 }

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

2627 {
2628  int cache;
2629  HeapTuple tuple;
2630  bool isnull;
2631  Oid oid;
2632  const ObjectPropertyType *property;
2633 
2634  /* If not owned by a namespace, just return InvalidOid. */
2635  property = get_object_property_data(address->classId);
2636  if (property->attnum_namespace == InvalidAttrNumber)
2637  return InvalidOid;
2638 
2639  /* Currently, we can only handle object types with system caches. */
2640  cache = property->oid_catcache_id;
2641  Assert(cache != -1);
2642 
2643  /* Fetch tuple from syscache and extract namespace attribute. */
2644  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2645  if (!HeapTupleIsValid(tuple))
2646  elog(ERROR, "cache lookup failed for cache %d oid %u",
2647  cache, address->objectId);
2648  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2649  tuple,
2650  property->attnum_namespace,
2651  &isnull));
2652  Assert(!isnull);
2653  ReleaseSysCache(tuple);
2654 
2655  return oid;
2656 }
#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:1434

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

2694 {
2695  const ObjectPropertyType *prop = get_object_property_data(class_id);
2696 
2697  return prop->oid_index_oid;
2698 }

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

2765 {
2766  const ObjectPropertyType *prop = get_object_property_data(class_id);
2767 
2768  if (prop->objtype == OBJECT_TABLE)
2769  {
2770  /*
2771  * If the property data says it's a table, dig a little deeper to get
2772  * the real relation kind, so that callers can produce more precise
2773  * error messages.
2774  */
2775  return get_relkind_objtype(get_rel_relkind(object_id));
2776  }
2777  else
2778  return prop->objtype;
2779 }
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1984
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 6068 of file objectaddress.c.

6069 {
6070  switch (relkind)
6071  {
6072  case RELKIND_RELATION:
6073  case RELKIND_PARTITIONED_TABLE:
6074  return OBJECT_TABLE;
6075  case RELKIND_INDEX:
6076  case RELKIND_PARTITIONED_INDEX:
6077  return OBJECT_INDEX;
6078  case RELKIND_SEQUENCE:
6079  return OBJECT_SEQUENCE;
6080  case RELKIND_VIEW:
6081  return OBJECT_VIEW;
6082  case RELKIND_MATVIEW:
6083  return OBJECT_MATVIEW;
6084  case RELKIND_FOREIGN_TABLE:
6085  return OBJECT_FOREIGN_TABLE;
6086  case RELKIND_TOASTVALUE:
6087  return OBJECT_TABLE;
6088  default:
6089  /* Per above, don't raise an error */
6090  return OBJECT_TABLE;
6091  }
6092 }

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

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

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

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

4059 {
4060  ObjectAddress address;
4061 
4062  address.classId = classid;
4063  address.objectId = objid;
4064  address.objectSubId = 0;
4065 
4066  return getObjectDescription(&address, false);
4067 }

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

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

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

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

◆ getObjectTypeDescription()

char* getObjectTypeDescription ( const ObjectAddress object,
bool  missing_ok 
)

Definition at line 4424 of file objectaddress.c.

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

References appendStringInfoString(), Assert(), StringInfoData::data, getConstraintTypeDescription(), getObjectClass(), getProcedureTypeDescription(), getRelationTypeDescription(), initStringInfo(), StringInfoData::len, ObjectAddress::objectId, ObjectAddress::objectSubId, OCLASS_AM, OCLASS_AMOP, OCLASS_AMPROC, OCLASS_CAST, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONSTRAINT, OCLASS_CONVERSION, OCLASS_DATABASE, OCLASS_DEFACL, OCLASS_DEFAULT, OCLASS_EVENT_TRIGGER, OCLASS_EXTENSION, OCLASS_FDW, OCLASS_FOREIGN_SERVER, OCLASS_LANGUAGE, OCLASS_LARGEOBJECT, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_PARAMETER_ACL, OCLASS_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_NAMESPACE, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, OCLASS_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 2794 of file objectaddress.c.

2795 {
2796  int index;
2797 
2798  for (index = 0; index < lengthof(ObjectProperty); index++)
2799  {
2800  if (ObjectProperty[index].class_oid == class_id)
2801  return true;
2802  }
2803 
2804  return false;
2805 }
#define lengthof(array)
Definition: c.h:745
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 2665 of file objectaddress.c.

2666 {
2667  int i;
2668 
2669  for (i = 0; i < lengthof(ObjectTypeMap); i++)
2670  {
2671  if (strcmp(ObjectTypeMap[i].tm_name, objtype) == 0)
2672  return ObjectTypeMap[i].tm_type;
2673  }
2674  ereport(ERROR,
2675  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2676  errmsg("unrecognized object type \"%s\"", objtype)));
2677 
2678  return -1; /* keep compiler quiet */
2679 }
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 6013 of file objectaddress.c.

6014 {
6015  ArrayType *arr;
6016  Datum *datums;
6017  bool *nulls;
6018  int j = 0;
6019  ListCell *cell;
6020  MemoryContext memcxt;
6021  MemoryContext oldcxt;
6022  int lb[1];
6023 
6024  /* Work in a temp context; easier than individually pfree'ing the Datums */
6026  "strlist to array",
6028  oldcxt = MemoryContextSwitchTo(memcxt);
6029 
6030  datums = (Datum *) palloc(sizeof(Datum) * list_length(list));
6031  nulls = palloc(sizeof(bool) * list_length(list));
6032 
6033  foreach(cell, list)
6034  {
6035  char *name = lfirst(cell);
6036 
6037  if (name)
6038  {
6039  nulls[j] = false;
6040  datums[j++] = CStringGetTextDatum(name);
6041  }
6042  else
6043  nulls[j] = true;
6044  }
6045 
6046  MemoryContextSwitchTo(oldcxt);
6047 
6048  lb[0] = 1;
6049  arr = construct_md_array(datums, nulls, 1, &j,
6050  lb, TEXTOID, -1, false, TYPALIGN_INT);
6051 
6052  MemoryContextDelete(memcxt);
6053 
6054  return arr;
6055 }
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:3440
#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:1068
#define AllocSetContextCreate
Definition: memutils.h:173
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:197
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define lfirst(lc)
Definition: pg_list.h:170
static int list_length(const List *l)
Definition: pg_list.h:150

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