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

Go to the source code of this file.

Data Structures

struct  ObjectAddress
 

Macros

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

Typedefs

typedef struct ObjectAddress ObjectAddress
 

Functions

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

Variables

const ObjectAddress InvalidObjectAddress
 

Macro Definition Documentation

◆ ObjectAddressSet

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

Definition at line 40 of file objectaddress.h.

Referenced by addFkRecurseReferenced(), addFkRecurseReferencing(), AddNewAttributeTuples(), AggregateCreate(), AlterCollation(), AlterConstraintNamespaces(), AlterDatabaseOwner(), AlterDomainAddConstraint(), AlterDomainDefault(), AlterDomainDropConstraint(), AlterDomainNotNull(), AlterDomainValidateConstraint(), AlterEnum(), AlterEventTriggerOwner(), AlterExtensionNamespace(), AlterForeignDataWrapper(), AlterForeignDataWrapperOwner(), AlterForeignServer(), AlterForeignServerOwner(), AlterFunction(), AlterPublicationOptions(), AlterPublicationOwner(), AlterSchemaOwner(), AlterSequence(), AlterStatistics(), AlterSubscription(), AlterSubscriptionOwner(), AlterTableNamespace(), AlterTSConfiguration(), AlterTSDictionary(), AlterType(), AlterTypeNamespace(), AlterTypeOwner(), AlterUserMapping(), ATAddCheckConstraint(), ATExecAddInherit(), ATExecAlterConstraint(), ATExecAttachPartition(), ATExecAttachPartitionIdx(), ATExecClusterOn(), ATExecDetachPartition(), ATExecDropInherit(), ATExecValidateConstraint(), ATPostAlterTypeCleanup(), CastCreate(), CloneFkReferencing(), ConstraintSetParentConstraint(), CreateConstraintEntry(), CreateProceduralLanguage(), CreatePublication(), CreateSchemaCommand(), CreateStatistics(), CreateSubscription(), CreateTransform(), CreateTrigger(), DefineCollation(), DefineIndex(), DefineQueryRewrite(), DefineRelation(), DefineTSConfiguration(), DefineVirtualRelation(), domainAddConstraint(), DropClonedTriggersFromPartition(), DropSubscription(), EventTriggerCollectAlterOpFam(), EventTriggerCollectAlterTSConfig(), EventTriggerCollectCreateOpClass(), ExecAlterExtensionStmt(), ExecAlterObjectSchemaStmt(), ExecRefreshMatView(), GenerateTypeDependencies(), get_object_address_defacl(), get_object_address_opf_member(), get_object_address_publication_rel(), get_object_address_usermapping(), heap_create_with_catalog(), index_constraint_create(), index_create(), IndexSetParentIndex(), InsertExtensionTuple(), makeDictionaryDependencies(), makeOperatorDependencies(), makeParserDependencies(), makeTSTemplateDependencies(), pg_event_trigger_ddl_commands(), ProcedureCreate(), publication_add_relation(), PublicationDropTables(), RangeCreate(), rename_constraint_internal(), rename_policy(), RenameDatabase(), RenameRelation(), RenameRewriteRule(), RenameRole(), RenameSchema(), RenameTableSpace(), renametrig(), RenameType(), StorePartitionKey(), tryAttachPartitionForeignKey(), TypeCreate(), and TypeShellMake().

◆ ObjectAddressSubSet

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

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

References aclcheck_error(), aclcheck_error_type(), ACLCHECK_NOT_OWNER, castNode, CONSTROID, elog, ereport, errcode(), errmsg(), ERROR, format_type_be(), GETSTRUCT, has_createrole_privilege(), HeapTupleIsValid, linitial_node, lo_compat_privileges, lsecond_node, NameListToString(), OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_ATTRIBUTE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_VIEW, ObjectAddress::objectId, ObjectIdGetDatum, pg_class_ownercheck(), pg_collation_ownercheck(), pg_conversion_ownercheck(), pg_database_ownercheck(), pg_event_trigger_ownercheck(), pg_extension_ownercheck(), pg_foreign_data_wrapper_ownercheck(), pg_foreign_server_ownercheck(), pg_language_ownercheck(), pg_largeobject_ownercheck(), pg_namespace_ownercheck(), pg_opclass_ownercheck(), pg_oper_ownercheck(), pg_opfamily_ownercheck(), pg_proc_ownercheck(), pg_publication_ownercheck(), pg_statistics_object_ownercheck(), pg_subscription_ownercheck(), pg_tablespace_ownercheck(), pg_ts_config_ownercheck(), pg_ts_dict_ownercheck(), pg_type_ownercheck(), RelationGetRelationName, RelationGetRelid, ReleaseSysCache(), SearchSysCache1(), strVal, superuser_arg(), and typenameTypeId().

Referenced by CommentObject(), ExecAlterExtensionContentsStmt(), ExecAlterObjectDependsStmt(), ExecSecLabelStmt(), and RemoveObjects().

2368 {
2369  switch (objtype)
2370  {
2371  case OBJECT_INDEX:
2372  case OBJECT_SEQUENCE:
2373  case OBJECT_TABLE:
2374  case OBJECT_VIEW:
2375  case OBJECT_MATVIEW:
2376  case OBJECT_FOREIGN_TABLE:
2377  case OBJECT_COLUMN:
2378  case OBJECT_RULE:
2379  case OBJECT_TRIGGER:
2380  case OBJECT_POLICY:
2381  case OBJECT_TABCONSTRAINT:
2382  if (!pg_class_ownercheck(RelationGetRelid(relation), roleid))
2384  RelationGetRelationName(relation));
2385  break;
2386  case OBJECT_DATABASE:
2387  if (!pg_database_ownercheck(address.objectId, roleid))
2389  strVal((Value *) object));
2390  break;
2391  case OBJECT_TYPE:
2392  case OBJECT_DOMAIN:
2393  case OBJECT_ATTRIBUTE:
2394  if (!pg_type_ownercheck(address.objectId, roleid))
2396  break;
2397  case OBJECT_DOMCONSTRAINT:
2398  {
2399  HeapTuple tuple;
2400  Oid contypid;
2401 
2402  tuple = SearchSysCache1(CONSTROID,
2403  ObjectIdGetDatum(address.objectId));
2404  if (!HeapTupleIsValid(tuple))
2405  elog(ERROR, "constraint with OID %u does not exist",
2406  address.objectId);
2407 
2408  contypid = ((Form_pg_constraint) GETSTRUCT(tuple))->contypid;
2409 
2410  ReleaseSysCache(tuple);
2411 
2412  /*
2413  * Fallback to type ownership check in this case as this is
2414  * what domain constraints rely on.
2415  */
2416  if (!pg_type_ownercheck(contypid, roleid))
2418  }
2419  break;
2420  case OBJECT_AGGREGATE:
2421  case OBJECT_FUNCTION:
2422  case OBJECT_PROCEDURE:
2423  case OBJECT_ROUTINE:
2424  if (!pg_proc_ownercheck(address.objectId, roleid))
2426  NameListToString((castNode(ObjectWithArgs, object))->objname));
2427  break;
2428  case OBJECT_OPERATOR:
2429  if (!pg_oper_ownercheck(address.objectId, roleid))
2431  NameListToString((castNode(ObjectWithArgs, object))->objname));
2432  break;
2433  case OBJECT_SCHEMA:
2434  if (!pg_namespace_ownercheck(address.objectId, roleid))
2436  strVal((Value *) object));
2437  break;
2438  case OBJECT_COLLATION:
2439  if (!pg_collation_ownercheck(address.objectId, roleid))
2441  NameListToString(castNode(List, object)));
2442  break;
2443  case OBJECT_CONVERSION:
2444  if (!pg_conversion_ownercheck(address.objectId, roleid))
2446  NameListToString(castNode(List, object)));
2447  break;
2448  case OBJECT_EXTENSION:
2449  if (!pg_extension_ownercheck(address.objectId, roleid))
2451  strVal((Value *) object));
2452  break;
2453  case OBJECT_FDW:
2454  if (!pg_foreign_data_wrapper_ownercheck(address.objectId, roleid))
2456  strVal((Value *) object));
2457  break;
2458  case OBJECT_FOREIGN_SERVER:
2459  if (!pg_foreign_server_ownercheck(address.objectId, roleid))
2461  strVal((Value *) object));
2462  break;
2463  case OBJECT_EVENT_TRIGGER:
2464  if (!pg_event_trigger_ownercheck(address.objectId, roleid))
2466  strVal((Value *) object));
2467  break;
2468  case OBJECT_LANGUAGE:
2469  if (!pg_language_ownercheck(address.objectId, roleid))
2471  strVal((Value *) object));
2472  break;
2473  case OBJECT_OPCLASS:
2474  if (!pg_opclass_ownercheck(address.objectId, roleid))
2476  NameListToString(castNode(List, object)));
2477  break;
2478  case OBJECT_OPFAMILY:
2479  if (!pg_opfamily_ownercheck(address.objectId, roleid))
2481  NameListToString(castNode(List, object)));
2482  break;
2483  case OBJECT_LARGEOBJECT:
2484  if (!lo_compat_privileges &&
2485  !pg_largeobject_ownercheck(address.objectId, roleid))
2486  ereport(ERROR,
2487  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2488  errmsg("must be owner of large object %u",
2489  address.objectId)));
2490  break;
2491  case OBJECT_CAST:
2492  {
2493  /* We can only check permissions on the source/target types */
2494  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2495  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2496  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2497  Oid targettypeid = typenameTypeId(NULL, targettype);
2498 
2499  if (!pg_type_ownercheck(sourcetypeid, roleid)
2500  && !pg_type_ownercheck(targettypeid, roleid))
2501  ereport(ERROR,
2502  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2503  errmsg("must be owner of type %s or type %s",
2504  format_type_be(sourcetypeid),
2505  format_type_be(targettypeid))));
2506  }
2507  break;
2508  case OBJECT_PUBLICATION:
2509  if (!pg_publication_ownercheck(address.objectId, roleid))
2511  strVal((Value *) object));
2512  break;
2513  case OBJECT_SUBSCRIPTION:
2514  if (!pg_subscription_ownercheck(address.objectId, roleid))
2516  strVal((Value *) object));
2517  break;
2518  case OBJECT_TRANSFORM:
2519  {
2520  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2521  Oid typeid = typenameTypeId(NULL, typename);
2522 
2523  if (!pg_type_ownercheck(typeid, roleid))
2525  }
2526  break;
2527  case OBJECT_TABLESPACE:
2528  if (!pg_tablespace_ownercheck(address.objectId, roleid))
2530  strVal((Value *) object));
2531  break;
2532  case OBJECT_TSDICTIONARY:
2533  if (!pg_ts_dict_ownercheck(address.objectId, roleid))
2535  NameListToString(castNode(List, object)));
2536  break;
2538  if (!pg_ts_config_ownercheck(address.objectId, roleid))
2540  NameListToString(castNode(List, object)));
2541  break;
2542  case OBJECT_ROLE:
2543 
2544  /*
2545  * We treat roles as being "owned" by those with CREATEROLE priv,
2546  * except that superusers are only owned by superusers.
2547  */
2548  if (superuser_arg(address.objectId))
2549  {
2550  if (!superuser_arg(roleid))
2551  ereport(ERROR,
2552  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2553  errmsg("must be superuser")));
2554  }
2555  else
2556  {
2557  if (!has_createrole_privilege(roleid))
2558  ereport(ERROR,
2559  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2560  errmsg("must have CREATEROLE privilege")));
2561  }
2562  break;
2563  case OBJECT_TSPARSER:
2564  case OBJECT_TSTEMPLATE:
2565  case OBJECT_ACCESS_METHOD:
2566  /* We treat these object types as being owned by superusers */
2567  if (!superuser_arg(roleid))
2568  ereport(ERROR,
2569  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2570  errmsg("must be superuser")));
2571  break;
2572  case OBJECT_STATISTIC_EXT:
2573  if (!pg_statistics_object_ownercheck(address.objectId, roleid))
2575  break;
2576  default:
2577  elog(ERROR, "unrecognized object type: %d",
2578  (int) objtype);
2579  }
2580 }
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:5312
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:5131
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
bool lo_compat_privileges
Definition: inv_api.c:58
bool pg_largeobject_ownercheck(Oid lobj_oid, Oid roleid)
Definition: aclchk.c:4820
bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid)
Definition: aclchk.c:4970
bool pg_language_ownercheck(Oid lan_oid, Oid roleid)
Definition: aclchk.c:4791
#define castNode(_type_, nodeptr)
Definition: nodes.h:597
bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid)
Definition: aclchk.c:4997
bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5051
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5225
#define strVal(v)
Definition: value.h:54
bool pg_oper_ownercheck(Oid oper_oid, Oid roleid)
Definition: aclchk.c:4739
int errcode(int sqlerrcode)
Definition: elog.c:610
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
bool pg_namespace_ownercheck(Oid nsp_oid, Oid roleid)
Definition: aclchk.c:4863
unsigned int Oid
Definition: postgres_ext.h:31
bool pg_type_ownercheck(Oid type_oid, Oid roleid)
Definition: aclchk.c:4713
#define linitial_node(type, l)
Definition: pg_list.h:197
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3607
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3294
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:5078
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5183
#define RelationGetRelationName(relation)
Definition: rel.h:490
bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid)
Definition: aclchk.c:4889
bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
Definition: aclchk.c:4943
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
Definition: aclchk.c:5105
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
char * NameListToString(List *names)
Definition: namespace.c:3101
#define lsecond_node(type, l)
Definition: pg_list.h:202
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid)
Definition: aclchk.c:4916
bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid)
Definition: aclchk.c:5157
#define ereport(elevel,...)
Definition: elog.h:144
FormData_pg_constraint * Form_pg_constraint
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
Definition: value.h:42
bool pg_class_ownercheck(Oid class_oid, Oid roleid)
Definition: aclchk.c:4687
bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5024
int errmsg(const char *fmt,...)
Definition: elog.c:824
#define elog(elevel,...)
Definition: elog.h:214
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:456
bool pg_proc_ownercheck(Oid proc_oid, Oid roleid)
Definition: aclchk.c:4765
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:291
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5251
bool pg_statistics_object_ownercheck(Oid stat_oid, Oid roleid)
Definition: aclchk.c:5277

◆ get_catalog_object_by_oid()

HeapTuple get_catalog_object_by_oid ( Relation  catalog,
AttrNumber  oidcol,
Oid  objectId 
)

Definition at line 2809 of file objectaddress.c.

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

2810 {
2811  HeapTuple tuple;
2812  Oid classId = RelationGetRelid(catalog);
2813  int oidCacheId = get_object_catcache_oid(classId);
2814 
2815  if (oidCacheId > 0)
2816  {
2817  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2818  if (!HeapTupleIsValid(tuple)) /* should not happen */
2819  return NULL;
2820  }
2821  else
2822  {
2823  Oid oidIndexId = get_object_oid_index(classId);
2824  SysScanDesc scan;
2825  ScanKeyData skey;
2826 
2827  Assert(OidIsValid(oidIndexId));
2828 
2829  ScanKeyInit(&skey,
2830  oidcol,
2831  BTEqualStrategyNumber, F_OIDEQ,
2832  ObjectIdGetDatum(objectId));
2833 
2834  scan = systable_beginscan(catalog, oidIndexId, true,
2835  NULL, 1, &skey);
2836  tuple = systable_getnext(scan);
2837  if (!HeapTupleIsValid(tuple))
2838  {
2839  systable_endscan(scan);
2840  return NULL;
2841  }
2842  tuple = heap_copytuple(tuple);
2843 
2844  systable_endscan(scan);
2845  }
2846 
2847  return tuple;
2848 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:680
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:569
Oid get_object_oid_index(Oid class_id)
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:651
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:357
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:476
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
int get_object_catcache_oid(Oid class_id)
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:745
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:174
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define RelationGetRelid(relation)
Definition: rel.h:456
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ get_object_address()

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

Definition at line 929 of file objectaddress.c.

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_relobject(), get_object_address_type(), get_object_address_unqualified(), get_object_address_usermapping(), get_relation_by_qualified_name(), get_statistics_object_oid(), get_transform_oid(), get_ts_config_oid(), get_ts_dict_oid(), get_ts_parser_oid(), get_ts_template_oid(), InvalidOid, IsSharedRelation(), LargeObjectExists(), linitial_node, LockDatabaseObject(), LockSharedObject(), LookupFuncWithArgs(), LookupOperWithArgs(), LookupTypeNameOid(), lsecond, lsecond_node, NoLock, OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_AMOP, OBJECT_AMPROC, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DEFACL, OBJECT_DEFAULT, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_PUBLICATION_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().

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

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

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

Referenced by ExecAlterObjectDependsStmt().

1227 {
1228  if (rel)
1229  {
1230  object = lcons(makeString(rel->relname), object);
1231  if (rel->schemaname)
1232  object = lcons(makeString(rel->schemaname), object);
1233  if (rel->catalogname)
1234  object = lcons(makeString(rel->catalogname), object);
1235  }
1236 
1237  return get_object_address(objtype, (Node *) object,
1238  relp, lockmode, missing_ok);
1239 }
Value * makeString(char *str)
Definition: value.c:53
Definition: nodes.h:528
char * schemaname
Definition: primnodes.h:67
char * relname
Definition: primnodes.h:68
List * lcons(void *datum, List *list)
Definition: list.c:453
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
char * catalogname
Definition: primnodes.h:66

◆ get_object_attnum_acl()

AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 2712 of file objectaddress.c.

References ObjectPropertyType::attnum_acl, and get_object_property_data().

Referenced by AlterObjectOwner_internal().

2713 {
2714  const ObjectPropertyType *prop = get_object_property_data(class_id);
2715 
2716  return prop->attnum_acl;
2717 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_acl

◆ get_object_attnum_name()

AttrNumber get_object_attnum_name ( Oid  class_id)

Definition at line 2688 of file objectaddress.c.

References ObjectPropertyType::attnum_name, and get_object_property_data().

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

2689 {
2690  const ObjectPropertyType *prop = get_object_property_data(class_id);
2691 
2692  return prop->attnum_name;
2693 }
AttrNumber attnum_name
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_attnum_namespace()

AttrNumber get_object_attnum_namespace ( Oid  class_id)

Definition at line 2696 of file objectaddress.c.

References ObjectPropertyType::attnum_namespace, and get_object_property_data().

Referenced by AlterObjectNamespace_internal(), AlterObjectOwner_internal(), AlterObjectRename_internal(), EventTriggerSQLDropAddObject(), pg_event_trigger_ddl_commands(), and pg_identify_object().

2697 {
2698  const ObjectPropertyType *prop = get_object_property_data(class_id);
2699 
2700  return prop->attnum_namespace;
2701 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_namespace

◆ get_object_attnum_oid()

AttrNumber get_object_attnum_oid ( Oid  class_id)

Definition at line 2680 of file objectaddress.c.

References ObjectPropertyType::attnum_oid, and get_object_property_data().

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

2681 {
2682  const ObjectPropertyType *prop = get_object_property_data(class_id);
2683 
2684  return prop->attnum_oid;
2685 }
AttrNumber attnum_oid
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_attnum_owner()

AttrNumber get_object_attnum_owner ( Oid  class_id)

Definition at line 2704 of file objectaddress.c.

References ObjectPropertyType::attnum_owner, and get_object_property_data().

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

2705 {
2706  const ObjectPropertyType *prop = get_object_property_data(class_id);
2707 
2708  return prop->attnum_owner;
2709 }
AttrNumber attnum_owner
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_catcache_name()

int get_object_catcache_name ( Oid  class_id)

Definition at line 2672 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

2673 {
2674  const ObjectPropertyType *prop = get_object_property_data(class_id);
2675 
2676  return prop->name_catcache_id;
2677 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_catcache_oid()

int get_object_catcache_oid ( Oid  class_id)

Definition at line 2664 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_catcache_id.

Referenced by AlterObjectNamespace_internal(), AlterObjectRename_internal(), DropObjectById(), and get_catalog_object_by_oid().

2665 {
2666  const ObjectPropertyType *prop = get_object_property_data(class_id);
2667 
2668  return prop->oid_catcache_id;
2669 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_class_descr()

const char* get_object_class_descr ( Oid  class_id)

Definition at line 2648 of file objectaddress.c.

References ObjectPropertyType::class_descr, and get_object_property_data().

Referenced by DropObjectById().

2649 {
2650  const ObjectPropertyType *prop = get_object_property_data(class_id);
2651 
2652  return prop->class_descr;
2653 }
const char * class_descr
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_namensp_unique()

bool get_object_namensp_unique ( Oid  class_id)

Definition at line 2745 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::is_nsp_name_unique.

Referenced by EventTriggerSQLDropAddObject(), and pg_identify_object().

2746 {
2747  const ObjectPropertyType *prop = get_object_property_data(class_id);
2748 
2749  return prop->is_nsp_name_unique;
2750 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_namespace()

Oid get_object_namespace ( const ObjectAddress address)

Definition at line 2589 of file objectaddress.c.

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

2590 {
2591  int cache;
2592  HeapTuple tuple;
2593  bool isnull;
2594  Oid oid;
2595  const ObjectPropertyType *property;
2596 
2597  /* If not owned by a namespace, just return InvalidOid. */
2598  property = get_object_property_data(address->classId);
2599  if (property->attnum_namespace == InvalidAttrNumber)
2600  return InvalidOid;
2601 
2602  /* Currently, we can only handle object types with system caches. */
2603  cache = property->oid_catcache_id;
2604  Assert(cache != -1);
2605 
2606  /* Fetch tuple from syscache and extract namespace attribute. */
2607  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2608  if (!HeapTupleIsValid(tuple))
2609  elog(ERROR, "cache lookup failed for cache %d oid %u",
2610  cache, address->objectId);
2611  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2612  tuple,
2613  property->attnum_namespace,
2614  &isnull));
2615  Assert(!isnull);
2616  ReleaseSysCache(tuple);
2617 
2618  return oid;
2619 }
#define DatumGetObjectId(X)
Definition: postgres.h:500
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
static const ObjectPropertyType * get_object_property_data(Oid class_id)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1377
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:745
AttrNumber attnum_namespace
#define InvalidAttrNumber
Definition: attnum.h:23
#define elog(elevel,...)
Definition: elog.h:214

◆ get_object_oid_index()

Oid get_object_oid_index ( Oid  class_id)

Definition at line 2656 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by DropObjectById(), and get_catalog_object_by_oid().

2657 {
2658  const ObjectPropertyType *prop = get_object_property_data(class_id);
2659 
2660  return prop->oid_index_oid;
2661 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_type()

ObjectType get_object_type ( Oid  class_id,
Oid  object_id 
)

Definition at line 2727 of file objectaddress.c.

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

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

◆ get_relkind_objtype()

ObjectType get_relkind_objtype ( char  relkind)

Definition at line 5931 of file objectaddress.c.

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

Referenced by AlterTableMoveAll(), ATExecChangeOwner(), ATSimplePermissions(), checkFkeyPermissions(), CreateStatistics(), CreateTrigger(), currtid_byrelname(), currtid_byreloid(), DefineQueryRewrite(), EnableDisableRule(), ExecCheckRTPerms(), get_object_type(), get_rel_from_relname(), LockViewRecurse_walker(), MergeAttributes(), pg_prewarm(), pgrowlocks(), PublicationAddTables(), RangeVarCallbackForAlterRelation(), RangeVarCallbackForDropRelation(), RangeVarCallbackForLockTable(), RangeVarCallbackForPolicy(), RangeVarCallbackForRenameRule(), RangeVarCallbackForRenameTrigger(), RangeVarCallbackOwnsRelation(), RangeVarCallbackOwnsTable(), RangeVarGetAndCheckCreationNamespace(), renameatt_check(), sanity_check_relation(), transformTableLikeClause(), and truncate_check_perms().

5932 {
5933  switch (relkind)
5934  {
5935  case RELKIND_RELATION:
5936  case RELKIND_PARTITIONED_TABLE:
5937  return OBJECT_TABLE;
5938  case RELKIND_INDEX:
5939  case RELKIND_PARTITIONED_INDEX:
5940  return OBJECT_INDEX;
5941  case RELKIND_SEQUENCE:
5942  return OBJECT_SEQUENCE;
5943  case RELKIND_VIEW:
5944  return OBJECT_VIEW;
5945  case RELKIND_MATVIEW:
5946  return OBJECT_MATVIEW;
5947  case RELKIND_FOREIGN_TABLE:
5948  return OBJECT_FOREIGN_TABLE;
5949  case RELKIND_TOASTVALUE:
5950  return OBJECT_TABLE;
5951  default:
5952  /* Per above, don't raise an error */
5953  return OBJECT_TABLE;
5954  }
5955 }

◆ getObjectDescription()

char* getObjectDescription ( const ObjectAddress object,
bool  missing_ok 
)

Definition at line 2857 of file objectaddress.c.

References _, AccessMethodOperatorOidIndexId, AccessMethodProcedureOidIndexId, AccessShareLock, AMOID, appendStringInfo(), Assert, attname, AttrDefaultOidIndexId, BTEqualStrategyNumber, CastOidIndexId, CLAOID, ObjectAddress::classId, CollationIsVisible(), COLLOID, CONSTROID, ConversionIsVisible(), CONVOID, StringInfoData::data, datname, DefaultAclOidIndexId, elog, ERROR, EVENTTRIGGEROID, ForeignDataWrapper::fdwname, format_operator(), format_operator_extended(), FORMAT_OPERATOR_INVALID_AS_NULL, FORMAT_PROC_INVALID_AS_NULL, format_procedure(), format_procedure_extended(), format_type_be(), format_type_extended(), FORMAT_TYPE_INVALID_AS_NULL, get_attname(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name(), get_publication_name(), get_subscription_name(), get_tablespace_name(), GetForeignDataWrapperExtended(), GetForeignServer(), GetForeignServerExtended(), getObjectClass(), getObjectDescription(), getOpFamilyDescription(), getRelationDescription(), GETSTRUCT, GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), LargeObjectExists(), StringInfoData::len, NameStr, ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, OCLASS_AM, OCLASS_AMOP, OCLASS_AMPROC, OCLASS_CAST, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONSTRAINT, OCLASS_CONVERSION, OCLASS_DATABASE, OCLASS_DEFACL, OCLASS_DEFAULT, OCLASS_EVENT_TRIGGER, OCLASS_EXTENSION, OCLASS_FDW, OCLASS_FOREIGN_SERVER, OCLASS_LANGUAGE, OCLASS_LARGEOBJECT, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, OCLASS_SCHEMA, OCLASS_STATISTIC_EXT, OCLASS_SUBSCRIPTION, OCLASS_TBLSPACE, OCLASS_TRANSFORM, OCLASS_TRIGGER, OCLASS_TSCONFIG, OCLASS_TSDICT, OCLASS_TSPARSER, OCLASS_TSTEMPLATE, OCLASS_TYPE, OCLASS_USER_MAPPING, OidIsValid, OpclassIsVisible(), pfree(), PolicyOidIndexId, proname, PUBLICATIONREL, quote_qualified_identifier(), ReleaseSysCache(), RewriteOidIndexId, ScanKeyInit(), SearchSysCache1(), ForeignServer::servername, STATEXTOID, StatisticsObjIsVisible(), subname, systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TRFOID, TriggerOidIndexId, 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(), getObjectDescription(), getObjectDescriptionOids(), pg_describe_object(), recordDependencyOnCurrentExtension(), reportDependentObjects(), sepgsql_fmgr_hook(), shdepDropOwned(), shdepReassignOwned(), and storeObjectDescription().

2858 {
2859  StringInfoData buffer;
2860 
2861  initStringInfo(&buffer);
2862 
2863  switch (getObjectClass(object))
2864  {
2865  case OCLASS_CLASS:
2866  if (object->objectSubId == 0)
2867  getRelationDescription(&buffer, object->objectId, missing_ok);
2868  else
2869  {
2870  /* column, not whole relation */
2871  StringInfoData rel;
2872  char *attname = get_attname(object->objectId,
2873  object->objectSubId,
2874  missing_ok);
2875  if (!attname)
2876  break;
2877 
2878  initStringInfo(&rel);
2879  getRelationDescription(&rel, object->objectId, missing_ok);
2880  /* translator: second %s is, e.g., "table %s" */
2881  appendStringInfo(&buffer, _("column %s of %s"),
2882  attname, rel.data);
2883  pfree(rel.data);
2884  }
2885  break;
2886 
2887  case OCLASS_PROC:
2888  {
2890  char *proname = format_procedure_extended(object->objectId,
2891  flags);
2892  if (proname == NULL)
2893  break;
2894 
2895  appendStringInfo(&buffer, _("function %s"), proname);
2896  break;
2897  }
2898 
2899  case OCLASS_TYPE:
2900  {
2902  char *typname = format_type_extended(object->objectId, -1,
2903  flags);
2904  if (typname == NULL)
2905  break;
2906 
2907  appendStringInfo(&buffer, _("type %s"), typname);
2908  break;
2909  }
2910 
2911  case OCLASS_CAST:
2912  {
2913  Relation castDesc;
2914  ScanKeyData skey[1];
2915  SysScanDesc rcscan;
2916  HeapTuple tup;
2917  Form_pg_cast castForm;
2918 
2919  castDesc = table_open(CastRelationId, AccessShareLock);
2920 
2921  ScanKeyInit(&skey[0],
2922  Anum_pg_cast_oid,
2923  BTEqualStrategyNumber, F_OIDEQ,
2924  ObjectIdGetDatum(object->objectId));
2925 
2926  rcscan = systable_beginscan(castDesc, CastOidIndexId, true,
2927  NULL, 1, skey);
2928 
2929  tup = systable_getnext(rcscan);
2930 
2931  if (!HeapTupleIsValid(tup))
2932  {
2933  if (!missing_ok)
2934  elog(ERROR, "could not find tuple for cast %u",
2935  object->objectId);
2936 
2937  systable_endscan(rcscan);
2938  table_close(castDesc, AccessShareLock);
2939  break;
2940  }
2941 
2942  castForm = (Form_pg_cast) GETSTRUCT(tup);
2943 
2944  appendStringInfo(&buffer, _("cast from %s to %s"),
2945  format_type_be(castForm->castsource),
2946  format_type_be(castForm->casttarget));
2947 
2948  systable_endscan(rcscan);
2949  table_close(castDesc, AccessShareLock);
2950  break;
2951  }
2952 
2953  case OCLASS_COLLATION:
2954  {
2955  HeapTuple collTup;
2956  Form_pg_collation coll;
2957  char *nspname;
2958 
2959  collTup = SearchSysCache1(COLLOID,
2960  ObjectIdGetDatum(object->objectId));
2961  if (!HeapTupleIsValid(collTup))
2962  {
2963  if (!missing_ok)
2964  elog(ERROR, "cache lookup failed for collation %u",
2965  object->objectId);
2966  break;
2967  }
2968 
2969  coll = (Form_pg_collation) GETSTRUCT(collTup);
2970 
2971  /* Qualify the name if not visible in search path */
2972  if (CollationIsVisible(object->objectId))
2973  nspname = NULL;
2974  else
2975  nspname = get_namespace_name(coll->collnamespace);
2976 
2977  appendStringInfo(&buffer, _("collation %s"),
2979  NameStr(coll->collname)));
2980  ReleaseSysCache(collTup);
2981  break;
2982  }
2983 
2984  case OCLASS_CONSTRAINT:
2985  {
2986  HeapTuple conTup;
2987  Form_pg_constraint con;
2988 
2989  conTup = SearchSysCache1(CONSTROID,
2990  ObjectIdGetDatum(object->objectId));
2991  if (!HeapTupleIsValid(conTup))
2992  {
2993  if (!missing_ok)
2994  elog(ERROR, "cache lookup failed for constraint %u",
2995  object->objectId);
2996  break;
2997  }
2998 
2999  con = (Form_pg_constraint) GETSTRUCT(conTup);
3000 
3001  if (OidIsValid(con->conrelid))
3002  {
3003  StringInfoData rel;
3004 
3005  initStringInfo(&rel);
3006  getRelationDescription(&rel, con->conrelid, false);
3007  /* translator: second %s is, e.g., "table %s" */
3008  appendStringInfo(&buffer, _("constraint %s on %s"),
3009  NameStr(con->conname), rel.data);
3010  pfree(rel.data);
3011  }
3012  else
3013  {
3014  appendStringInfo(&buffer, _("constraint %s"),
3015  NameStr(con->conname));
3016  }
3017 
3018  ReleaseSysCache(conTup);
3019  break;
3020  }
3021 
3022  case OCLASS_CONVERSION:
3023  {
3024  HeapTuple conTup;
3025  Form_pg_conversion conv;
3026  char *nspname;
3027 
3028  conTup = SearchSysCache1(CONVOID,
3029  ObjectIdGetDatum(object->objectId));
3030  if (!HeapTupleIsValid(conTup))
3031  {
3032  if (!missing_ok)
3033  elog(ERROR, "cache lookup failed for conversion %u",
3034  object->objectId);
3035  break;
3036  }
3037 
3038  conv = (Form_pg_conversion) GETSTRUCT(conTup);
3039 
3040  /* Qualify the name if not visible in search path */
3041  if (ConversionIsVisible(object->objectId))
3042  nspname = NULL;
3043  else
3044  nspname = get_namespace_name(conv->connamespace);
3045 
3046  appendStringInfo(&buffer, _("conversion %s"),
3048  NameStr(conv->conname)));
3049  ReleaseSysCache(conTup);
3050  break;
3051  }
3052 
3053  case OCLASS_DEFAULT:
3054  {
3055  Relation attrdefDesc;
3056  ScanKeyData skey[1];
3057  SysScanDesc adscan;
3058  HeapTuple tup;
3059  Form_pg_attrdef attrdef;
3060  ObjectAddress colobject;
3061 
3062  attrdefDesc = table_open(AttrDefaultRelationId, AccessShareLock);
3063 
3064  ScanKeyInit(&skey[0],
3065  Anum_pg_attrdef_oid,
3066  BTEqualStrategyNumber, F_OIDEQ,
3067  ObjectIdGetDatum(object->objectId));
3068 
3069  adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndexId,
3070  true, NULL, 1, skey);
3071 
3072  tup = systable_getnext(adscan);
3073 
3074  if (!HeapTupleIsValid(tup))
3075  {
3076  if (!missing_ok)
3077  elog(ERROR, "could not find tuple for attrdef %u",
3078  object->objectId);
3079 
3080  systable_endscan(adscan);
3081  table_close(attrdefDesc, AccessShareLock);
3082  break;
3083  }
3084 
3085  attrdef = (Form_pg_attrdef) GETSTRUCT(tup);
3086 
3087  colobject.classId = RelationRelationId;
3088  colobject.objectId = attrdef->adrelid;
3089  colobject.objectSubId = attrdef->adnum;
3090 
3091  /* translator: %s is typically "column %s of table %s" */
3092  appendStringInfo(&buffer, _("default value for %s"),
3093  getObjectDescription(&colobject, false));
3094 
3095  systable_endscan(adscan);
3096  table_close(attrdefDesc, AccessShareLock);
3097  break;
3098  }
3099 
3100  case OCLASS_LANGUAGE:
3101  {
3102  char *langname = get_language_name(object->objectId,
3103  missing_ok);
3104 
3105  if (langname)
3106  appendStringInfo(&buffer, _("language %s"),
3107  get_language_name(object->objectId, false));
3108  break;
3109  }
3110 
3111  case OCLASS_LARGEOBJECT:
3112  if (!LargeObjectExists(object->objectId))
3113  break;
3114  appendStringInfo(&buffer, _("large object %u"),
3115  object->objectId);
3116  break;
3117 
3118  case OCLASS_OPERATOR:
3119  {
3121  char *oprname = format_operator_extended(object->objectId,
3122  flags);
3123 
3124  if (oprname == NULL)
3125  break;
3126 
3127  appendStringInfo(&buffer, _("operator %s"), oprname);
3128  break;
3129  }
3130 
3131  case OCLASS_OPCLASS:
3132  {
3133  HeapTuple opcTup;
3134  Form_pg_opclass opcForm;
3135  HeapTuple amTup;
3136  Form_pg_am amForm;
3137  char *nspname;
3138 
3139  opcTup = SearchSysCache1(CLAOID,
3140  ObjectIdGetDatum(object->objectId));
3141  if (!HeapTupleIsValid(opcTup))
3142  {
3143  if (!missing_ok)
3144  elog(ERROR, "cache lookup failed for opclass %u",
3145  object->objectId);
3146  break;
3147  }
3148 
3149  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
3150 
3151  amTup = SearchSysCache1(AMOID,
3152  ObjectIdGetDatum(opcForm->opcmethod));
3153  if (!HeapTupleIsValid(amTup))
3154  elog(ERROR, "cache lookup failed for access method %u",
3155  opcForm->opcmethod);
3156  amForm = (Form_pg_am) GETSTRUCT(amTup);
3157 
3158  /* Qualify the name if not visible in search path */
3159  if (OpclassIsVisible(object->objectId))
3160  nspname = NULL;
3161  else
3162  nspname = get_namespace_name(opcForm->opcnamespace);
3163 
3164  appendStringInfo(&buffer, _("operator class %s for access method %s"),
3166  NameStr(opcForm->opcname)),
3167  NameStr(amForm->amname));
3168 
3169  ReleaseSysCache(amTup);
3170  ReleaseSysCache(opcTup);
3171  break;
3172  }
3173 
3174  case OCLASS_OPFAMILY:
3175  getOpFamilyDescription(&buffer, object->objectId, missing_ok);
3176  break;
3177 
3178  case OCLASS_AM:
3179  {
3180  HeapTuple tup;
3181 
3182  tup = SearchSysCache1(AMOID,
3183  ObjectIdGetDatum(object->objectId));
3184  if (!HeapTupleIsValid(tup))
3185  {
3186  if (!missing_ok)
3187  elog(ERROR, "cache lookup failed for access method %u",
3188  object->objectId);
3189  break;
3190  }
3191 
3192  appendStringInfo(&buffer, _("access method %s"),
3193  NameStr(((Form_pg_am) GETSTRUCT(tup))->amname));
3194  ReleaseSysCache(tup);
3195  break;
3196  }
3197 
3198  case OCLASS_AMOP:
3199  {
3200  Relation amopDesc;
3201  HeapTuple tup;
3202  ScanKeyData skey[1];
3203  SysScanDesc amscan;
3204  Form_pg_amop amopForm;
3205  StringInfoData opfam;
3206 
3207  amopDesc = table_open(AccessMethodOperatorRelationId,
3208  AccessShareLock);
3209 
3210  ScanKeyInit(&skey[0],
3211  Anum_pg_amop_oid,
3212  BTEqualStrategyNumber, F_OIDEQ,
3213  ObjectIdGetDatum(object->objectId));
3214 
3215  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
3216  NULL, 1, skey);
3217 
3218  tup = systable_getnext(amscan);
3219 
3220  if (!HeapTupleIsValid(tup))
3221  {
3222  if (!missing_ok)
3223  elog(ERROR, "could not find tuple for amop entry %u",
3224  object->objectId);
3225 
3226  systable_endscan(amscan);
3227  table_close(amopDesc, AccessShareLock);
3228  break;
3229  }
3230 
3231  amopForm = (Form_pg_amop) GETSTRUCT(tup);
3232 
3233  initStringInfo(&opfam);
3234  getOpFamilyDescription(&opfam, amopForm->amopfamily, false);
3235 
3236  /*------
3237  translator: %d is the operator strategy (a number), the
3238  first two %s's are data type names, the third %s is the
3239  description of the operator family, and the last %s is the
3240  textual form of the operator with arguments. */
3241  appendStringInfo(&buffer, _("operator %d (%s, %s) of %s: %s"),
3242  amopForm->amopstrategy,
3243  format_type_be(amopForm->amoplefttype),
3244  format_type_be(amopForm->amoprighttype),
3245  opfam.data,
3246  format_operator(amopForm->amopopr));
3247 
3248  pfree(opfam.data);
3249 
3250  systable_endscan(amscan);
3251  table_close(amopDesc, AccessShareLock);
3252  break;
3253  }
3254 
3255  case OCLASS_AMPROC:
3256  {
3257  Relation amprocDesc;
3258  ScanKeyData skey[1];
3259  SysScanDesc amscan;
3260  HeapTuple tup;
3261  Form_pg_amproc amprocForm;
3262  StringInfoData opfam;
3263 
3264  amprocDesc = table_open(AccessMethodProcedureRelationId,
3265  AccessShareLock);
3266 
3267  ScanKeyInit(&skey[0],
3268  Anum_pg_amproc_oid,
3269  BTEqualStrategyNumber, F_OIDEQ,
3270  ObjectIdGetDatum(object->objectId));
3271 
3272  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
3273  NULL, 1, skey);
3274 
3275  tup = systable_getnext(amscan);
3276 
3277  if (!HeapTupleIsValid(tup))
3278  {
3279  if (!missing_ok)
3280  elog(ERROR, "could not find tuple for amproc entry %u",
3281  object->objectId);
3282 
3283  systable_endscan(amscan);
3284  table_close(amprocDesc, AccessShareLock);
3285  break;
3286  }
3287 
3288  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
3289 
3290  initStringInfo(&opfam);
3291  getOpFamilyDescription(&opfam, amprocForm->amprocfamily, false);
3292 
3293  /*------
3294  translator: %d is the function number, the first two %s's
3295  are data type names, the third %s is the description of the
3296  operator family, and the last %s is the textual form of the
3297  function with arguments. */
3298  appendStringInfo(&buffer, _("function %d (%s, %s) of %s: %s"),
3299  amprocForm->amprocnum,
3300  format_type_be(amprocForm->amproclefttype),
3301  format_type_be(amprocForm->amprocrighttype),
3302  opfam.data,
3303  format_procedure(amprocForm->amproc));
3304 
3305  pfree(opfam.data);
3306 
3307  systable_endscan(amscan);
3308  table_close(amprocDesc, AccessShareLock);
3309  break;
3310  }
3311 
3312  case OCLASS_REWRITE:
3313  {
3314  Relation ruleDesc;
3315  ScanKeyData skey[1];
3316  SysScanDesc rcscan;
3317  HeapTuple tup;
3319  StringInfoData rel;
3320 
3321  ruleDesc = table_open(RewriteRelationId, AccessShareLock);
3322 
3323  ScanKeyInit(&skey[0],
3324  Anum_pg_rewrite_oid,
3325  BTEqualStrategyNumber, F_OIDEQ,
3326  ObjectIdGetDatum(object->objectId));
3327 
3328  rcscan = systable_beginscan(ruleDesc, RewriteOidIndexId, true,
3329  NULL, 1, skey);
3330 
3331  tup = systable_getnext(rcscan);
3332 
3333  if (!HeapTupleIsValid(tup))
3334  {
3335  if (!missing_ok)
3336  elog(ERROR, "could not find tuple for rule %u",
3337  object->objectId);
3338 
3339  systable_endscan(rcscan);
3340  table_close(ruleDesc, AccessShareLock);
3341  break;
3342  }
3343 
3344  rule = (Form_pg_rewrite) GETSTRUCT(tup);
3345 
3346  initStringInfo(&rel);
3347  getRelationDescription(&rel, rule->ev_class, false);
3348 
3349  /* translator: second %s is, e.g., "table %s" */
3350  appendStringInfo(&buffer, _("rule %s on %s"),
3351  NameStr(rule->rulename), rel.data);
3352  pfree(rel.data);
3353  systable_endscan(rcscan);
3354  table_close(ruleDesc, AccessShareLock);
3355  break;
3356  }
3357 
3358  case OCLASS_TRIGGER:
3359  {
3360  Relation trigDesc;
3361  ScanKeyData skey[1];
3362  SysScanDesc tgscan;
3363  HeapTuple tup;
3364  Form_pg_trigger trig;
3365  StringInfoData rel;
3366 
3367  trigDesc = table_open(TriggerRelationId, AccessShareLock);
3368 
3369  ScanKeyInit(&skey[0],
3370  Anum_pg_trigger_oid,
3371  BTEqualStrategyNumber, F_OIDEQ,
3372  ObjectIdGetDatum(object->objectId));
3373 
3374  tgscan = systable_beginscan(trigDesc, TriggerOidIndexId, true,
3375  NULL, 1, skey);
3376 
3377  tup = systable_getnext(tgscan);
3378 
3379  if (!HeapTupleIsValid(tup))
3380  {
3381  if (!missing_ok)
3382  elog(ERROR, "could not find tuple for trigger %u",
3383  object->objectId);
3384 
3385  systable_endscan(tgscan);
3386  table_close(trigDesc, AccessShareLock);
3387  break;
3388  }
3389 
3390  trig = (Form_pg_trigger) GETSTRUCT(tup);
3391 
3392  initStringInfo(&rel);
3393  getRelationDescription(&rel, trig->tgrelid, false);
3394 
3395  /* translator: second %s is, e.g., "table %s" */
3396  appendStringInfo(&buffer, _("trigger %s on %s"),
3397  NameStr(trig->tgname), rel.data);
3398  pfree(rel.data);
3399  systable_endscan(tgscan);
3400  table_close(trigDesc, AccessShareLock);
3401  break;
3402  }
3403 
3404  case OCLASS_SCHEMA:
3405  {
3406  char *nspname;
3407 
3408  nspname = get_namespace_name(object->objectId);
3409  if (!nspname)
3410  {
3411  if (!missing_ok)
3412  elog(ERROR, "cache lookup failed for namespace %u",
3413  object->objectId);
3414  break;
3415  }
3416  appendStringInfo(&buffer, _("schema %s"), nspname);
3417  break;
3418  }
3419 
3420  case OCLASS_STATISTIC_EXT:
3421  {
3422  HeapTuple stxTup;
3423  Form_pg_statistic_ext stxForm;
3424  char *nspname;
3425 
3426  stxTup = SearchSysCache1(STATEXTOID,
3427  ObjectIdGetDatum(object->objectId));
3428  if (!HeapTupleIsValid(stxTup))
3429  {
3430  if (!missing_ok)
3431  elog(ERROR, "could not find tuple for statistics object %u",
3432  object->objectId);
3433  break;
3434  }
3435 
3436  stxForm = (Form_pg_statistic_ext) GETSTRUCT(stxTup);
3437 
3438  /* Qualify the name if not visible in search path */
3439  if (StatisticsObjIsVisible(object->objectId))
3440  nspname = NULL;
3441  else
3442  nspname = get_namespace_name(stxForm->stxnamespace);
3443 
3444  appendStringInfo(&buffer, _("statistics object %s"),
3446  NameStr(stxForm->stxname)));
3447 
3448  ReleaseSysCache(stxTup);
3449  break;
3450  }
3451 
3452  case OCLASS_TSPARSER:
3453  {
3454  HeapTuple tup;
3455  Form_pg_ts_parser prsForm;
3456  char *nspname;
3457 
3459  ObjectIdGetDatum(object->objectId));
3460  if (!HeapTupleIsValid(tup))
3461  {
3462  if (!missing_ok)
3463  elog(ERROR, "cache lookup failed for text search parser %u",
3464  object->objectId);
3465  break;
3466  }
3467  prsForm = (Form_pg_ts_parser) GETSTRUCT(tup);
3468 
3469  /* Qualify the name if not visible in search path */
3470  if (TSParserIsVisible(object->objectId))
3471  nspname = NULL;
3472  else
3473  nspname = get_namespace_name(prsForm->prsnamespace);
3474 
3475  appendStringInfo(&buffer, _("text search parser %s"),
3477  NameStr(prsForm->prsname)));
3478  ReleaseSysCache(tup);
3479  break;
3480  }
3481 
3482  case OCLASS_TSDICT:
3483  {
3484  HeapTuple tup;
3485  Form_pg_ts_dict dictForm;
3486  char *nspname;
3487 
3488  tup = SearchSysCache1(TSDICTOID,
3489  ObjectIdGetDatum(object->objectId));
3490  if (!HeapTupleIsValid(tup))
3491  {
3492  if (!missing_ok)
3493  elog(ERROR, "cache lookup failed for text search dictionary %u",
3494  object->objectId);
3495  break;
3496  }
3497 
3498  dictForm = (Form_pg_ts_dict) GETSTRUCT(tup);
3499 
3500  /* Qualify the name if not visible in search path */
3501  if (TSDictionaryIsVisible(object->objectId))
3502  nspname = NULL;
3503  else
3504  nspname = get_namespace_name(dictForm->dictnamespace);
3505 
3506  appendStringInfo(&buffer, _("text search dictionary %s"),
3508  NameStr(dictForm->dictname)));
3509  ReleaseSysCache(tup);
3510  break;
3511  }
3512 
3513  case OCLASS_TSTEMPLATE:
3514  {
3515  HeapTuple tup;
3516  Form_pg_ts_template tmplForm;
3517  char *nspname;
3518 
3520  ObjectIdGetDatum(object->objectId));
3521  if (!HeapTupleIsValid(tup))
3522  {
3523  if (!missing_ok)
3524  elog(ERROR, "cache lookup failed for text search template %u",
3525  object->objectId);
3526  break;
3527  }
3528 
3529  tmplForm = (Form_pg_ts_template) GETSTRUCT(tup);
3530 
3531  /* Qualify the name if not visible in search path */
3532  if (TSTemplateIsVisible(object->objectId))
3533  nspname = NULL;
3534  else
3535  nspname = get_namespace_name(tmplForm->tmplnamespace);
3536 
3537  appendStringInfo(&buffer, _("text search template %s"),
3539  NameStr(tmplForm->tmplname)));
3540  ReleaseSysCache(tup);
3541  break;
3542  }
3543 
3544  case OCLASS_TSCONFIG:
3545  {
3546  HeapTuple tup;
3547  Form_pg_ts_config cfgForm;
3548  char *nspname;
3549 
3551  ObjectIdGetDatum(object->objectId));
3552  if (!HeapTupleIsValid(tup))
3553  {
3554  if (!missing_ok)
3555  elog(ERROR, "cache lookup failed for text search configuration %u",
3556  object->objectId);
3557  break;
3558  }
3559 
3560  cfgForm = (Form_pg_ts_config) GETSTRUCT(tup);
3561 
3562  /* Qualify the name if not visible in search path */
3563  if (TSConfigIsVisible(object->objectId))
3564  nspname = NULL;
3565  else
3566  nspname = get_namespace_name(cfgForm->cfgnamespace);
3567 
3568  appendStringInfo(&buffer, _("text search configuration %s"),
3570  NameStr(cfgForm->cfgname)));
3571  ReleaseSysCache(tup);
3572  break;
3573  }
3574 
3575  case OCLASS_ROLE:
3576  {
3577  char *username = GetUserNameFromId(object->objectId,
3578  missing_ok);
3579 
3580  if (username)
3581  appendStringInfo(&buffer, _("role %s"), username);
3582  break;
3583  }
3584 
3585  case OCLASS_DATABASE:
3586  {
3587  char *datname;
3588 
3589  datname = get_database_name(object->objectId);
3590  if (!datname)
3591  {
3592  if (!missing_ok)
3593  elog(ERROR, "cache lookup failed for database %u",
3594  object->objectId);
3595  break;
3596  }
3597  appendStringInfo(&buffer, _("database %s"), datname);
3598  break;
3599  }
3600 
3601  case OCLASS_TBLSPACE:
3602  {
3603  char *tblspace;
3604 
3605  tblspace = get_tablespace_name(object->objectId);
3606  if (!tblspace)
3607  {
3608  if (!missing_ok)
3609  elog(ERROR, "cache lookup failed for tablespace %u",
3610  object->objectId);
3611  break;
3612  }
3613  appendStringInfo(&buffer, _("tablespace %s"), tblspace);
3614  break;
3615  }
3616 
3617  case OCLASS_FDW:
3618  {
3619  ForeignDataWrapper *fdw;
3620 
3622  missing_ok);
3623  if (fdw)
3624  appendStringInfo(&buffer, _("foreign-data wrapper %s"), fdw->fdwname);
3625  break;
3626  }
3627 
3628  case OCLASS_FOREIGN_SERVER:
3629  {
3630  ForeignServer *srv;
3631 
3632  srv = GetForeignServerExtended(object->objectId, missing_ok);
3633  if (srv)
3634  appendStringInfo(&buffer, _("server %s"), srv->servername);
3635  break;
3636  }
3637 
3638  case OCLASS_USER_MAPPING:
3639  {
3640  HeapTuple tup;
3641  Oid useid;
3642  char *usename;
3643  Form_pg_user_mapping umform;
3644  ForeignServer *srv;
3645 
3647  ObjectIdGetDatum(object->objectId));
3648  if (!HeapTupleIsValid(tup))
3649  {
3650  if (!missing_ok)
3651  elog(ERROR, "cache lookup failed for user mapping %u",
3652  object->objectId);
3653  break;
3654  }
3655 
3656  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
3657  useid = umform->umuser;
3658  srv = GetForeignServer(umform->umserver);
3659 
3660  ReleaseSysCache(tup);
3661 
3662  if (OidIsValid(useid))
3663  usename = GetUserNameFromId(useid, false);
3664  else
3665  usename = "public";
3666 
3667  appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
3668  srv->servername);
3669  break;
3670  }
3671 
3672  case OCLASS_DEFACL:
3673  {
3674  Relation defaclrel;
3675  ScanKeyData skey[1];
3676  SysScanDesc rcscan;
3677  HeapTuple tup;
3678  Form_pg_default_acl defacl;
3679  char *rolename;
3680  char *nspname;
3681 
3682  defaclrel = table_open(DefaultAclRelationId, AccessShareLock);
3683 
3684  ScanKeyInit(&skey[0],
3685  Anum_pg_default_acl_oid,
3686  BTEqualStrategyNumber, F_OIDEQ,
3687  ObjectIdGetDatum(object->objectId));
3688 
3689  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
3690  true, NULL, 1, skey);
3691 
3692  tup = systable_getnext(rcscan);
3693 
3694  if (!HeapTupleIsValid(tup))
3695  {
3696  if (!missing_ok)
3697  elog(ERROR, "could not find tuple for default ACL %u",
3698  object->objectId);
3699 
3700  systable_endscan(rcscan);
3701  table_close(defaclrel, AccessShareLock);
3702  break;
3703  }
3704 
3705  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
3706 
3707  rolename = GetUserNameFromId(defacl->defaclrole, false);
3708 
3709  if (OidIsValid(defacl->defaclnamespace))
3710  nspname = get_namespace_name(defacl->defaclnamespace);
3711  else
3712  nspname = NULL;
3713 
3714  switch (defacl->defaclobjtype)
3715  {
3716  case DEFACLOBJ_RELATION:
3717  if (nspname)
3718  appendStringInfo(&buffer,
3719  _("default privileges on new relations belonging to role %s in schema %s"),
3720  rolename, nspname);
3721  else
3722  appendStringInfo(&buffer,
3723  _("default privileges on new relations belonging to role %s"),
3724  rolename);
3725  break;
3726  case DEFACLOBJ_SEQUENCE:
3727  if (nspname)
3728  appendStringInfo(&buffer,
3729  _("default privileges on new sequences belonging to role %s in schema %s"),
3730  rolename, nspname);
3731  else
3732  appendStringInfo(&buffer,
3733  _("default privileges on new sequences belonging to role %s"),
3734  rolename);
3735  break;
3736  case DEFACLOBJ_FUNCTION:
3737  if (nspname)
3738  appendStringInfo(&buffer,
3739  _("default privileges on new functions belonging to role %s in schema %s"),
3740  rolename, nspname);
3741  else
3742  appendStringInfo(&buffer,
3743  _("default privileges on new functions belonging to role %s"),
3744  rolename);
3745  break;
3746  case DEFACLOBJ_TYPE:
3747  if (nspname)
3748  appendStringInfo(&buffer,
3749  _("default privileges on new types belonging to role %s in schema %s"),
3750  rolename, nspname);
3751  else
3752  appendStringInfo(&buffer,
3753  _("default privileges on new types belonging to role %s"),
3754  rolename);
3755  break;
3756  case DEFACLOBJ_NAMESPACE:
3757  Assert(!nspname);
3758  appendStringInfo(&buffer,
3759  _("default privileges on new schemas belonging to role %s"),
3760  rolename);
3761  break;
3762  default:
3763  /* shouldn't get here */
3764  if (nspname)
3765  appendStringInfo(&buffer,
3766  _("default privileges belonging to role %s in schema %s"),
3767  rolename, nspname);
3768  else
3769  appendStringInfo(&buffer,
3770  _("default privileges belonging to role %s"),
3771  rolename);
3772  break;
3773  }
3774 
3775  systable_endscan(rcscan);
3776  table_close(defaclrel, AccessShareLock);
3777  break;
3778  }
3779 
3780  case OCLASS_EXTENSION:
3781  {
3782  char *extname;
3783 
3784  extname = get_extension_name(object->objectId);
3785  if (!extname)
3786  {
3787  if (!missing_ok)
3788  elog(ERROR, "cache lookup failed for extension %u",
3789  object->objectId);
3790  break;
3791  }
3792  appendStringInfo(&buffer, _("extension %s"), extname);
3793  break;
3794  }
3795 
3796  case OCLASS_EVENT_TRIGGER:
3797  {
3798  HeapTuple tup;
3799 
3801  ObjectIdGetDatum(object->objectId));
3802  if (!HeapTupleIsValid(tup))
3803  {
3804  if (!missing_ok)
3805  elog(ERROR, "cache lookup failed for event trigger %u",
3806  object->objectId);
3807  break;
3808  }
3809  appendStringInfo(&buffer, _("event trigger %s"),
3810  NameStr(((Form_pg_event_trigger) GETSTRUCT(tup))->evtname));
3811  ReleaseSysCache(tup);
3812  break;
3813  }
3814 
3815  case OCLASS_POLICY:
3816  {
3817  Relation policy_rel;
3818  ScanKeyData skey[1];
3819  SysScanDesc sscan;
3820  HeapTuple tuple;
3821  Form_pg_policy form_policy;
3822  StringInfoData rel;
3823 
3824  policy_rel = table_open(PolicyRelationId, AccessShareLock);
3825 
3826  ScanKeyInit(&skey[0],
3827  Anum_pg_policy_oid,
3828  BTEqualStrategyNumber, F_OIDEQ,
3829  ObjectIdGetDatum(object->objectId));
3830 
3831  sscan = systable_beginscan(policy_rel, PolicyOidIndexId,
3832  true, NULL, 1, skey);
3833 
3834  tuple = systable_getnext(sscan);
3835 
3836  if (!HeapTupleIsValid(tuple))
3837  {
3838  if (!missing_ok)
3839  elog(ERROR, "could not find tuple for policy %u",
3840  object->objectId);
3841 
3842  systable_endscan(sscan);
3843  table_close(policy_rel, AccessShareLock);
3844  break;
3845  }
3846 
3847  form_policy = (Form_pg_policy) GETSTRUCT(tuple);
3848 
3849  initStringInfo(&rel);
3850  getRelationDescription(&rel, form_policy->polrelid, false);
3851 
3852  /* translator: second %s is, e.g., "table %s" */
3853  appendStringInfo(&buffer, _("policy %s on %s"),
3854  NameStr(form_policy->polname), rel.data);
3855  pfree(rel.data);
3856  systable_endscan(sscan);
3857  table_close(policy_rel, AccessShareLock);
3858  break;
3859  }
3860 
3861  case OCLASS_PUBLICATION:
3862  {
3863  char *pubname = get_publication_name(object->objectId,
3864  missing_ok);
3865  if (pubname)
3866  appendStringInfo(&buffer, _("publication %s"), pubname);
3867  break;
3868  }
3869 
3871  {
3872  HeapTuple tup;
3873  char *pubname;
3874  Form_pg_publication_rel prform;
3875  StringInfoData rel;
3876 
3878  ObjectIdGetDatum(object->objectId));
3879  if (!HeapTupleIsValid(tup))
3880  {
3881  if (!missing_ok)
3882  elog(ERROR, "cache lookup failed for publication table %u",
3883  object->objectId);
3884  break;
3885  }
3886 
3887  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
3888  pubname = get_publication_name(prform->prpubid, false);
3889 
3890  initStringInfo(&rel);
3891  getRelationDescription(&rel, prform->prrelid, false);
3892 
3893  /* translator: first %s is, e.g., "table %s" */
3894  appendStringInfo(&buffer, _("publication of %s in publication %s"),
3895  rel.data, pubname);
3896  pfree(rel.data);
3897  ReleaseSysCache(tup);
3898  break;
3899  }
3900 
3901  case OCLASS_SUBSCRIPTION:
3902  {
3903  char *subname = get_subscription_name(object->objectId,
3904  missing_ok);
3905  if (subname)
3906  appendStringInfo(&buffer, _("subscription %s"), subname);
3907  break;
3908  }
3909 
3910  case OCLASS_TRANSFORM:
3911  {
3912  HeapTuple trfTup;
3913  Form_pg_transform trfForm;
3914 
3915  trfTup = SearchSysCache1(TRFOID,
3916  ObjectIdGetDatum(object->objectId));
3917  if (!HeapTupleIsValid(trfTup))
3918  {
3919  if (!missing_ok)
3920  elog(ERROR, "could not find tuple for transform %u",
3921  object->objectId);
3922  break;
3923  }
3924 
3925  trfForm = (Form_pg_transform) GETSTRUCT(trfTup);
3926 
3927  appendStringInfo(&buffer, _("transform for %s language %s"),
3928  format_type_be(trfForm->trftype),
3929  get_language_name(trfForm->trflang, false));
3930 
3931  ReleaseSysCache(trfTup);
3932  break;
3933  }
3934 
3935  /*
3936  * There's intentionally no default: case here; we want the
3937  * compiler to warn if a new OCLASS hasn't been handled above.
3938  */
3939  }
3940 
3941  /* an empty buffer is equivalent to no object found */
3942  if (buffer.len == 0)
3943  return NULL;
3944 
3945  return buffer.data;
3946 }
#define RewriteOidIndexId
Definition: indexing.h:226
#define TriggerOidIndexId
Definition: indexing.h:266
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
NameData proname
Definition: pg_proc.h:35
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:569
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
Definition: syscache.h:36
char * get_language_name(Oid langoid, bool missing_ok)
Definition: lsyscache.c:1100
FormData_pg_ts_config * Form_pg_ts_config
Definition: pg_ts_config.h:48
uint16 bits16
Definition: c.h:382
char * fdwname
Definition: foreign.h:28
#define PolicyOidIndexId
Definition: indexing.h:342
FormData_pg_amproc * Form_pg_amproc
Definition: pg_amproc.h:68
char * get_extension_name(Oid ext_oid)
Definition: extension.c:185
#define DefaultAclOidIndexId
Definition: indexing.h:322
static void getOpFamilyDescription(StringInfo buffer, Oid opfid, bool missing_ok)
static void getRelationDescription(StringInfo buffer, Oid relid, bool missing_ok)
#define AccessShareLock
Definition: lockdefs.h:36
bool StatisticsObjIsVisible(Oid relid)
Definition: namespace.c:2234
#define AttrDefaultOidIndexId
Definition: indexing.h:102
#define AccessMethodOperatorOidIndexId
Definition: indexing.h:92
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
NameData datname
Definition: pg_database.h:35
char * format_operator(Oid operator_oid)
Definition: regproc.c:851
unsigned int Oid
Definition: postgres_ext.h:31
NameData subname
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2722
#define OidIsValid(objectId)
Definition: c.h:651
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:357
char * get_publication_name(Oid pubid, bool missing_ok)
char * format_operator_extended(Oid operator_oid, bits16 flags)
Definition: regproc.c:780
Definition: localtime.c:72
char * get_subscription_name(Oid subid, bool missing_ok)
#define AccessMethodProcedureOidIndexId
Definition: indexing.h:97
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:476
void pfree(void *pointer)
Definition: mcxt.c:1057
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
FormData_pg_transform * Form_pg_transform
Definition: pg_transform.h:43
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
NameData attname
Definition: pg_attribute.h:40
bool TSConfigIsVisible(Oid cfgid)
Definition: namespace.c:2736
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2155
FormData_pg_user_mapping * Form_pg_user_mapping
FormData_pg_ts_dict * Form_pg_ts_dict
Definition: pg_ts_dict.h:52
FormData_pg_default_acl * Form_pg_default_acl
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3191
#define CastOidIndexId
Definition: indexing.h:120
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2047
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:57
NameData typname
Definition: pg_type.h:41
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
FormData_pg_attrdef * Form_pg_attrdef
Definition: pg_attrdef.h:47
bool TSDictionaryIsVisible(Oid dictId)
Definition: namespace.c:2483
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10795
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
#define FORMAT_TYPE_INVALID_AS_NULL
Definition: builtins.h:115
#define FORMAT_OPERATOR_INVALID_AS_NULL
Definition: regproc.h:24
ForeignServer * GetForeignServer(Oid serverid)
Definition: foreign.c:109
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
FormData_pg_ts_parser * Form_pg_ts_parser
Definition: pg_ts_parser.h:55
FormData_pg_conversion * Form_pg_conversion
Definition: pg_conversion.h:61
char * format_procedure_extended(Oid procedure_oid, bits16 flags)
Definition: regproc.c:349
bool OpclassIsVisible(Oid opcid)
Definition: namespace.c:1832
static char * username
Definition: initdb.c:134
FormData_pg_policy * Form_pg_policy
Definition: pg_policy.h:50
ForeignServer * GetForeignServerExtended(Oid serverid, bits16 flags)
Definition: foreign.c:121
char * format_procedure(Oid procedure_oid)
Definition: regproc.c:322
#define FORMAT_PROC_INVALID_AS_NULL
Definition: regproc.h:19
bool ConversionIsVisible(Oid conid)
Definition: namespace.c:2130
FormData_pg_constraint * Form_pg_constraint
FormData_pg_event_trigger * Form_pg_event_trigger
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:891
#define Assert(condition)
Definition: c.h:745
FormData_pg_trigger * Form_pg_trigger
Definition: pg_trigger.h:73
char * format_type_extended(Oid type_oid, int32 typemod, bits16 flags)
Definition: format_type.c:111
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:51
FormData_pg_rewrite * Form_pg_rewrite
Definition: pg_rewrite.h:52
bool TSTemplateIsVisible(Oid tmplId)
Definition: namespace.c:2610
FormData_pg_am * Form_pg_am
Definition: pg_am.h:48
bool LargeObjectExists(Oid loid)
bool TSParserIsVisible(Oid prsId)
Definition: namespace.c:2357
ForeignDataWrapper * GetForeignDataWrapperExtended(Oid fdwid, bits16 flags)
Definition: foreign.c:47
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:88
char * get_tablespace_name(Oid spc_oid)
Definition: tablespace.c:1467
char * servername
Definition: foreign.h:39
FormData_pg_ts_template * Form_pg_ts_template
#define elog(elevel,...)
Definition: elog.h:214
FormData_pg_publication_rel * Form_pg_publication_rel
#define NameStr(name)
Definition: c.h:622
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition: lsyscache.c:825
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
FormData_pg_opclass * Form_pg_opclass
Definition: pg_opclass.h:83
#define _(x)
Definition: elog.c:88
#define BTEqualStrategyNumber
Definition: stratnum.h:31
FormData_pg_statistic_ext * Form_pg_statistic_ext

◆ getObjectDescriptionOids()

char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 3952 of file objectaddress.c.

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

3953 {
3954  ObjectAddress address;
3955 
3956  address.classId = classid;
3957  address.objectId = objid;
3958  address.objectSubId = 0;
3959 
3960  return getObjectDescription(&address, false);
3961 }
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)

◆ getObjectIdentity()

◆ getObjectIdentityParts()

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

Definition at line 4651 of file objectaddress.c.

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

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

4654 {
4655  StringInfoData buffer;
4656 
4657  initStringInfo(&buffer);
4658 
4659  /*
4660  * Make sure that both objname and objargs were passed, or none was; and
4661  * initialize them to empty lists. For objname this is useless because it
4662  * will be initialized in all cases inside the switch; but we do it anyway
4663  * so that we can test below that no branch leaves it unset.
4664  */
4665  Assert(PointerIsValid(objname) == PointerIsValid(objargs));
4666  if (objname)
4667  {
4668  *objname = NIL;
4669  *objargs = NIL;
4670  }
4671 
4672  switch (getObjectClass(object))
4673  {
4674  case OCLASS_CLASS:
4675  {
4676  char *attr = NULL;
4677 
4678  /*
4679  * Check for the attribute first, so as if it is missing we
4680  * can skip the entire relation description.
4681  */
4682  if (object->objectSubId != 0)
4683  {
4684  attr = get_attname(object->objectId,
4685  object->objectSubId,
4686  missing_ok);
4687 
4688  if (missing_ok && attr == NULL)
4689  break;
4690  }
4691 
4692  getRelationIdentity(&buffer, object->objectId, objname,
4693  missing_ok);
4694  if (objname && *objname == NIL)
4695  break;
4696 
4697  if (attr)
4698  {
4699  appendStringInfo(&buffer, ".%s",
4700  quote_identifier(attr));
4701  if (objname)
4702  *objname = lappend(*objname, attr);
4703  }
4704  }
4705  break;
4706 
4707  case OCLASS_PROC:
4708  {
4710  char *proname = format_procedure_extended(object->objectId,
4711  flags);
4712  if (proname == NULL)
4713  break;
4714 
4715  appendStringInfoString(&buffer, proname);
4716  if (objname)
4717  format_procedure_parts(object->objectId, objname, objargs,
4718  missing_ok);
4719  break;
4720  }
4721 
4722  case OCLASS_TYPE:
4723  {
4725  char *typeout;
4726 
4727  typeout = format_type_extended(object->objectId, -1, flags);
4728 
4729  if (typeout == NULL)
4730  break;
4731 
4732  appendStringInfoString(&buffer, typeout);
4733  if (objname)
4734  *objname = list_make1(typeout);
4735  }
4736  break;
4737 
4738  case OCLASS_CAST:
4739  {
4740  Relation castRel;
4741  HeapTuple tup;
4742  Form_pg_cast castForm;
4743 
4744  castRel = table_open(CastRelationId, AccessShareLock);
4745 
4746  tup = get_catalog_object_by_oid(castRel, Anum_pg_cast_oid,
4747  object->objectId);
4748 
4749  if (!HeapTupleIsValid(tup))
4750  {
4751  if (!missing_ok)
4752  elog(ERROR, "could not find tuple for cast %u",
4753  object->objectId);
4754 
4755  table_close(castRel, AccessShareLock);
4756  break;
4757  }
4758 
4759  castForm = (Form_pg_cast) GETSTRUCT(tup);
4760 
4761  appendStringInfo(&buffer, "(%s AS %s)",
4762  format_type_be_qualified(castForm->castsource),
4763  format_type_be_qualified(castForm->casttarget));
4764 
4765  if (objname)
4766  {
4767  *objname = list_make1(format_type_be_qualified(castForm->castsource));
4768  *objargs = list_make1(format_type_be_qualified(castForm->casttarget));
4769  }
4770 
4771  table_close(castRel, AccessShareLock);
4772  break;
4773  }
4774 
4775  case OCLASS_COLLATION:
4776  {
4777  HeapTuple collTup;
4778  Form_pg_collation coll;
4779  char *schema;
4780 
4781  collTup = SearchSysCache1(COLLOID,
4782  ObjectIdGetDatum(object->objectId));
4783  if (!HeapTupleIsValid(collTup))
4784  {
4785  if (!missing_ok)
4786  elog(ERROR, "cache lookup failed for collation %u",
4787  object->objectId);
4788  break;
4789  }
4790  coll = (Form_pg_collation) GETSTRUCT(collTup);
4791  schema = get_namespace_name_or_temp(coll->collnamespace);
4792  appendStringInfoString(&buffer,
4794  NameStr(coll->collname)));
4795  if (objname)
4796  *objname = list_make2(schema,
4797  pstrdup(NameStr(coll->collname)));
4798  ReleaseSysCache(collTup);
4799  break;
4800  }
4801 
4802  case OCLASS_CONSTRAINT:
4803  {
4804  HeapTuple conTup;
4805  Form_pg_constraint con;
4806 
4807  conTup = SearchSysCache1(CONSTROID,
4808  ObjectIdGetDatum(object->objectId));
4809  if (!HeapTupleIsValid(conTup))
4810  {
4811  if (!missing_ok)
4812  elog(ERROR, "cache lookup failed for constraint %u",
4813  object->objectId);
4814  break;
4815  }
4816  con = (Form_pg_constraint) GETSTRUCT(conTup);
4817 
4818  if (OidIsValid(con->conrelid))
4819  {
4820  appendStringInfo(&buffer, "%s on ",
4821  quote_identifier(NameStr(con->conname)));
4822  getRelationIdentity(&buffer, con->conrelid, objname,
4823  false);
4824  if (objname)
4825  *objname = lappend(*objname, pstrdup(NameStr(con->conname)));
4826  }
4827  else
4828  {
4829  ObjectAddress domain;
4830 
4831  Assert(OidIsValid(con->contypid));
4832  domain.classId = TypeRelationId;
4833  domain.objectId = con->contypid;
4834  domain.objectSubId = 0;
4835 
4836  appendStringInfo(&buffer, "%s on %s",
4837  quote_identifier(NameStr(con->conname)),
4838  getObjectIdentityParts(&domain, objname,
4839  objargs, false));
4840 
4841  if (objname)
4842  *objargs = lappend(*objargs, pstrdup(NameStr(con->conname)));
4843  }
4844 
4845  ReleaseSysCache(conTup);
4846  break;
4847  }
4848 
4849  case OCLASS_CONVERSION:
4850  {
4851  HeapTuple conTup;
4852  Form_pg_conversion conForm;
4853  char *schema;
4854 
4855  conTup = SearchSysCache1(CONVOID,
4856  ObjectIdGetDatum(object->objectId));
4857  if (!HeapTupleIsValid(conTup))
4858  {
4859  if (!missing_ok)
4860  elog(ERROR, "cache lookup failed for conversion %u",
4861  object->objectId);
4862  break;
4863  }
4864  conForm = (Form_pg_conversion) GETSTRUCT(conTup);
4865  schema = get_namespace_name_or_temp(conForm->connamespace);
4866  appendStringInfoString(&buffer,
4868  NameStr(conForm->conname)));
4869  if (objname)
4870  *objname = list_make2(schema,
4871  pstrdup(NameStr(conForm->conname)));
4872  ReleaseSysCache(conTup);
4873  break;
4874  }
4875 
4876  case OCLASS_DEFAULT:
4877  {
4878  Relation attrdefDesc;
4879  ScanKeyData skey[1];
4880  SysScanDesc adscan;
4881 
4882  HeapTuple tup;
4883  Form_pg_attrdef attrdef;
4884  ObjectAddress colobject;
4885 
4886  attrdefDesc = table_open(AttrDefaultRelationId, AccessShareLock);
4887 
4888  ScanKeyInit(&skey[0],
4889  Anum_pg_attrdef_oid,
4890  BTEqualStrategyNumber, F_OIDEQ,
4891  ObjectIdGetDatum(object->objectId));
4892 
4893  adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndexId,
4894  true, NULL, 1, skey);
4895 
4896  tup = systable_getnext(adscan);
4897 
4898  if (!HeapTupleIsValid(tup))
4899  {
4900  if (!missing_ok)
4901  elog(ERROR, "could not find tuple for attrdef %u",
4902  object->objectId);
4903 
4904  systable_endscan(adscan);
4905  table_close(attrdefDesc, AccessShareLock);
4906  break;
4907  }
4908 
4909  attrdef = (Form_pg_attrdef) GETSTRUCT(tup);
4910 
4911  colobject.classId = RelationRelationId;
4912  colobject.objectId = attrdef->adrelid;
4913  colobject.objectSubId = attrdef->adnum;
4914 
4915  appendStringInfo(&buffer, "for %s",
4916  getObjectIdentityParts(&colobject,
4917  objname, objargs,
4918  false));
4919 
4920  systable_endscan(adscan);
4921  table_close(attrdefDesc, AccessShareLock);
4922  break;
4923  }
4924 
4925  case OCLASS_LANGUAGE:
4926  {
4927  HeapTuple langTup;
4928  Form_pg_language langForm;
4929 
4930  langTup = SearchSysCache1(LANGOID,
4931  ObjectIdGetDatum(object->objectId));
4932  if (!HeapTupleIsValid(langTup))
4933  {
4934  if (!missing_ok)
4935  elog(ERROR, "cache lookup failed for language %u",
4936  object->objectId);
4937  break;
4938  }
4939  langForm = (Form_pg_language) GETSTRUCT(langTup);
4940  appendStringInfoString(&buffer,
4941  quote_identifier(NameStr(langForm->lanname)));
4942  if (objname)
4943  *objname = list_make1(pstrdup(NameStr(langForm->lanname)));
4944  ReleaseSysCache(langTup);
4945  break;
4946  }
4947  case OCLASS_LARGEOBJECT:
4948  if (!LargeObjectExists(object->objectId))
4949  break;
4950  appendStringInfo(&buffer, "%u",
4951  object->objectId);
4952  if (objname)
4953  *objname = list_make1(psprintf("%u", object->objectId));
4954  break;
4955 
4956  case OCLASS_OPERATOR:
4957  {
4959  char *oprname = format_operator_extended(object->objectId,
4960  flags);
4961  if (oprname == NULL)
4962  break;
4963 
4964  appendStringInfoString(&buffer, oprname);
4965  if (objname)
4966  format_operator_parts(object->objectId, objname, objargs, missing_ok);
4967  break;
4968  }
4969 
4970  case OCLASS_OPCLASS:
4971  {
4972  HeapTuple opcTup;
4973  Form_pg_opclass opcForm;
4974  HeapTuple amTup;
4975  Form_pg_am amForm;
4976  char *schema;
4977 
4978  opcTup = SearchSysCache1(CLAOID,
4979  ObjectIdGetDatum(object->objectId));
4980  if (!HeapTupleIsValid(opcTup))
4981  {
4982  if (!missing_ok)
4983  elog(ERROR, "cache lookup failed for opclass %u",
4984  object->objectId);
4985  break;
4986  }
4987  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
4988  schema = get_namespace_name_or_temp(opcForm->opcnamespace);
4989 
4990  amTup = SearchSysCache1(AMOID,
4991  ObjectIdGetDatum(opcForm->opcmethod));
4992  if (!HeapTupleIsValid(amTup))
4993  elog(ERROR, "cache lookup failed for access method %u",
4994  opcForm->opcmethod);
4995  amForm = (Form_pg_am) GETSTRUCT(amTup);
4996 
4997  appendStringInfo(&buffer, "%s USING %s",
4999  NameStr(opcForm->opcname)),
5000  quote_identifier(NameStr(amForm->amname)));
5001  if (objname)
5002  *objname = list_make3(pstrdup(NameStr(amForm->amname)),
5003  schema,
5004  pstrdup(NameStr(opcForm->opcname)));
5005 
5006  ReleaseSysCache(amTup);
5007  ReleaseSysCache(opcTup);
5008  break;
5009  }
5010 
5011  case OCLASS_OPFAMILY:
5012  getOpFamilyIdentity(&buffer, object->objectId, objname,
5013  missing_ok);
5014  break;
5015 
5016  case OCLASS_AM:
5017  {
5018  char *amname;
5019 
5020  amname = get_am_name(object->objectId);
5021  if (!amname)
5022  {
5023  if (!missing_ok)
5024  elog(ERROR, "cache lookup failed for access method %u",
5025  object->objectId);
5026  break;
5027  }
5028  appendStringInfoString(&buffer, quote_identifier(amname));
5029  if (objname)
5030  *objname = list_make1(amname);
5031  }
5032  break;
5033 
5034  case OCLASS_AMOP:
5035  {
5036  Relation amopDesc;
5037  HeapTuple tup;
5038  ScanKeyData skey[1];
5039  SysScanDesc amscan;
5040  Form_pg_amop amopForm;
5041  StringInfoData opfam;
5042  char *ltype;
5043  char *rtype;
5044 
5045  amopDesc = table_open(AccessMethodOperatorRelationId,
5046  AccessShareLock);
5047 
5048  ScanKeyInit(&skey[0],
5049  Anum_pg_amop_oid,
5050  BTEqualStrategyNumber, F_OIDEQ,
5051  ObjectIdGetDatum(object->objectId));
5052 
5053  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
5054  NULL, 1, skey);
5055 
5056  tup = systable_getnext(amscan);
5057 
5058  if (!HeapTupleIsValid(tup))
5059  {
5060  if (!missing_ok)
5061  elog(ERROR, "could not find tuple for amop entry %u",
5062  object->objectId);
5063 
5064  systable_endscan(amscan);
5065  table_close(amopDesc, AccessShareLock);
5066  break;
5067  }
5068 
5069  amopForm = (Form_pg_amop) GETSTRUCT(tup);
5070 
5071  initStringInfo(&opfam);
5072  getOpFamilyIdentity(&opfam, amopForm->amopfamily, objname,
5073  false);
5074 
5075  ltype = format_type_be_qualified(amopForm->amoplefttype);
5076  rtype = format_type_be_qualified(amopForm->amoprighttype);
5077 
5078  if (objname)
5079  {
5080  *objname = lappend(*objname,
5081  psprintf("%d", amopForm->amopstrategy));
5082  *objargs = list_make2(ltype, rtype);
5083  }
5084 
5085  appendStringInfo(&buffer, "operator %d (%s, %s) of %s",
5086  amopForm->amopstrategy,
5087  ltype, rtype, opfam.data);
5088 
5089  pfree(opfam.data);
5090 
5091  systable_endscan(amscan);
5092  table_close(amopDesc, AccessShareLock);
5093  break;
5094  }
5095 
5096  case OCLASS_AMPROC:
5097  {
5098  Relation amprocDesc;
5099  ScanKeyData skey[1];
5100  SysScanDesc amscan;
5101  HeapTuple tup;
5102  Form_pg_amproc amprocForm;
5103  StringInfoData opfam;
5104  char *ltype;
5105  char *rtype;
5106 
5107  amprocDesc = table_open(AccessMethodProcedureRelationId,
5108  AccessShareLock);
5109 
5110  ScanKeyInit(&skey[0],
5111  Anum_pg_amproc_oid,
5112  BTEqualStrategyNumber, F_OIDEQ,
5113  ObjectIdGetDatum(object->objectId));
5114 
5115  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
5116  NULL, 1, skey);
5117 
5118  tup = systable_getnext(amscan);
5119 
5120  if (!HeapTupleIsValid(tup))
5121  {
5122  if (!missing_ok)
5123  elog(ERROR, "could not find tuple for amproc entry %u",
5124  object->objectId);
5125 
5126  systable_endscan(amscan);
5127  table_close(amprocDesc, AccessShareLock);
5128  break;
5129  }
5130 
5131  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
5132 
5133  initStringInfo(&opfam);
5134  getOpFamilyIdentity(&opfam, amprocForm->amprocfamily, objname,
5135  false);
5136 
5137  ltype = format_type_be_qualified(amprocForm->amproclefttype);
5138  rtype = format_type_be_qualified(amprocForm->amprocrighttype);
5139 
5140  if (objname)
5141  {
5142  *objname = lappend(*objname,
5143  psprintf("%d", amprocForm->amprocnum));
5144  *objargs = list_make2(ltype, rtype);
5145  }
5146 
5147  appendStringInfo(&buffer, "function %d (%s, %s) of %s",
5148  amprocForm->amprocnum,
5149  ltype, rtype, opfam.data);
5150 
5151  pfree(opfam.data);
5152 
5153  systable_endscan(amscan);
5154  table_close(amprocDesc, AccessShareLock);
5155  break;
5156  }
5157 
5158  case OCLASS_REWRITE:
5159  {
5160  Relation ruleDesc;
5161  HeapTuple tup;
5163 
5164  ruleDesc = table_open(RewriteRelationId, AccessShareLock);
5165 
5166  tup = get_catalog_object_by_oid(ruleDesc, Anum_pg_rewrite_oid,
5167  object->objectId);
5168 
5169  if (!HeapTupleIsValid(tup))
5170  {
5171  if (!missing_ok)
5172  elog(ERROR, "could not find tuple for rule %u",
5173  object->objectId);
5174 
5175  table_close(ruleDesc, AccessShareLock);
5176  break;
5177  }
5178 
5179  rule = (Form_pg_rewrite) GETSTRUCT(tup);
5180 
5181  appendStringInfo(&buffer, "%s on ",
5182  quote_identifier(NameStr(rule->rulename)));
5183  getRelationIdentity(&buffer, rule->ev_class, objname, false);
5184  if (objname)
5185  *objname = lappend(*objname, pstrdup(NameStr(rule->rulename)));
5186 
5187  table_close(ruleDesc, AccessShareLock);
5188  break;
5189  }
5190 
5191  case OCLASS_TRIGGER:
5192  {
5193  Relation trigDesc;
5194  HeapTuple tup;
5195  Form_pg_trigger trig;
5196 
5197  trigDesc = table_open(TriggerRelationId, AccessShareLock);
5198 
5199  tup = get_catalog_object_by_oid(trigDesc, Anum_pg_trigger_oid,
5200  object->objectId);
5201 
5202  if (!HeapTupleIsValid(tup))
5203  {
5204  if (!missing_ok)
5205  elog(ERROR, "could not find tuple for trigger %u",
5206  object->objectId);
5207 
5208  table_close(trigDesc, AccessShareLock);
5209  break;
5210  }
5211 
5212  trig = (Form_pg_trigger) GETSTRUCT(tup);
5213 
5214  appendStringInfo(&buffer, "%s on ",
5215  quote_identifier(NameStr(trig->tgname)));
5216  getRelationIdentity(&buffer, trig->tgrelid, objname, false);
5217  if (objname)
5218  *objname = lappend(*objname, pstrdup(NameStr(trig->tgname)));
5219 
5220  table_close(trigDesc, AccessShareLock);
5221  break;
5222  }
5223 
5224  case OCLASS_SCHEMA:
5225  {
5226  char *nspname;
5227 
5228  nspname = get_namespace_name_or_temp(object->objectId);
5229  if (!nspname)
5230  {
5231  if (!missing_ok)
5232  elog(ERROR, "cache lookup failed for namespace %u",
5233  object->objectId);
5234  break;
5235  }
5236  appendStringInfoString(&buffer,
5237  quote_identifier(nspname));
5238  if (objname)
5239  *objname = list_make1(nspname);
5240  break;
5241  }
5242 
5243  case OCLASS_STATISTIC_EXT:
5244  {
5245  HeapTuple tup;
5246  Form_pg_statistic_ext formStatistic;
5247  char *schema;
5248 
5250  ObjectIdGetDatum(object->objectId));
5251  if (!HeapTupleIsValid(tup))
5252  {
5253  if (!missing_ok)
5254  elog(ERROR, "cache lookup failed for statistics object %u",
5255  object->objectId);
5256  break;
5257  }
5258  formStatistic = (Form_pg_statistic_ext) GETSTRUCT(tup);
5259  schema = get_namespace_name_or_temp(formStatistic->stxnamespace);
5260  appendStringInfoString(&buffer,
5262  NameStr(formStatistic->stxname)));
5263  if (objname)
5264  *objname = list_make2(schema,
5265  pstrdup(NameStr(formStatistic->stxname)));
5266  ReleaseSysCache(tup);
5267  }
5268  break;
5269 
5270  case OCLASS_TSPARSER:
5271  {
5272  HeapTuple tup;
5273  Form_pg_ts_parser formParser;
5274  char *schema;
5275 
5277  ObjectIdGetDatum(object->objectId));
5278  if (!HeapTupleIsValid(tup))
5279  {
5280  if (!missing_ok)
5281  elog(ERROR, "cache lookup failed for text search parser %u",
5282  object->objectId);
5283  break;
5284  }
5285  formParser = (Form_pg_ts_parser) GETSTRUCT(tup);
5286  schema = get_namespace_name_or_temp(formParser->prsnamespace);
5287  appendStringInfoString(&buffer,
5289  NameStr(formParser->prsname)));
5290  if (objname)
5291  *objname = list_make2(schema,
5292  pstrdup(NameStr(formParser->prsname)));
5293  ReleaseSysCache(tup);
5294  break;
5295  }
5296 
5297  case OCLASS_TSDICT:
5298  {
5299  HeapTuple tup;
5300  Form_pg_ts_dict formDict;
5301  char *schema;
5302 
5303  tup = SearchSysCache1(TSDICTOID,
5304  ObjectIdGetDatum(object->objectId));
5305  if (!HeapTupleIsValid(tup))
5306  {
5307  if (!missing_ok)
5308  elog(ERROR, "cache lookup failed for text search dictionary %u",
5309  object->objectId);
5310  break;
5311  }
5312  formDict = (Form_pg_ts_dict) GETSTRUCT(tup);
5313  schema = get_namespace_name_or_temp(formDict->dictnamespace);
5314  appendStringInfoString(&buffer,
5316  NameStr(formDict->dictname)));
5317  if (objname)
5318  *objname = list_make2(schema,
5319  pstrdup(NameStr(formDict->dictname)));
5320  ReleaseSysCache(tup);
5321  break;
5322  }
5323 
5324  case OCLASS_TSTEMPLATE:
5325  {
5326  HeapTuple tup;
5327  Form_pg_ts_template formTmpl;
5328  char *schema;
5329 
5331  ObjectIdGetDatum(object->objectId));
5332  if (!HeapTupleIsValid(tup))
5333  {
5334  if (!missing_ok)
5335  elog(ERROR, "cache lookup failed for text search template %u",
5336  object->objectId);
5337  break;
5338  }
5339  formTmpl = (Form_pg_ts_template) GETSTRUCT(tup);
5340  schema = get_namespace_name_or_temp(formTmpl->tmplnamespace);
5341  appendStringInfoString(&buffer,
5343  NameStr(formTmpl->tmplname)));
5344  if (objname)
5345  *objname = list_make2(schema,
5346  pstrdup(NameStr(formTmpl->tmplname)));
5347  ReleaseSysCache(tup);
5348  break;
5349  }
5350 
5351  case OCLASS_TSCONFIG:
5352  {
5353  HeapTuple tup;
5354  Form_pg_ts_config formCfg;
5355  char *schema;
5356 
5358  ObjectIdGetDatum(object->objectId));
5359  if (!HeapTupleIsValid(tup))
5360  {
5361  if (!missing_ok)
5362  elog(ERROR, "cache lookup failed for text search configuration %u",
5363  object->objectId);
5364  break;
5365  }
5366  formCfg = (Form_pg_ts_config) GETSTRUCT(tup);
5367  schema = get_namespace_name_or_temp(formCfg->cfgnamespace);
5368  appendStringInfoString(&buffer,
5370  NameStr(formCfg->cfgname)));
5371  if (objname)
5372  *objname = list_make2(schema,
5373  pstrdup(NameStr(formCfg->cfgname)));
5374  ReleaseSysCache(tup);
5375  break;
5376  }
5377 
5378  case OCLASS_ROLE:
5379  {
5380  char *username;
5381 
5382  username = GetUserNameFromId(object->objectId, missing_ok);
5383  if (!username)
5384  break;
5385  if (objname)
5386  *objname = list_make1(username);
5387  appendStringInfoString(&buffer,
5388  quote_identifier(username));
5389  break;
5390  }
5391 
5392  case OCLASS_DATABASE:
5393  {
5394  char *datname;
5395 
5396  datname = get_database_name(object->objectId);
5397  if (!datname)
5398  {
5399  if (!missing_ok)
5400  elog(ERROR, "cache lookup failed for database %u",
5401  object->objectId);
5402  break;
5403  }
5404  if (objname)
5405  *objname = list_make1(datname);
5406  appendStringInfoString(&buffer,
5407  quote_identifier(datname));
5408  break;
5409  }
5410 
5411  case OCLASS_TBLSPACE:
5412  {
5413  char *tblspace;
5414 
5415  tblspace = get_tablespace_name(object->objectId);
5416  if (!tblspace)
5417  {
5418  if (!missing_ok)
5419  elog(ERROR, "cache lookup failed for tablespace %u",
5420  object->objectId);
5421  break;
5422  }
5423  if (objname)
5424  *objname = list_make1(tblspace);
5425  appendStringInfoString(&buffer,
5426  quote_identifier(tblspace));
5427  break;
5428  }
5429 
5430  case OCLASS_FDW:
5431  {
5432  ForeignDataWrapper *fdw;
5433 
5434  fdw = GetForeignDataWrapperExtended(object->objectId,
5435  missing_ok);
5436  if (fdw)
5437  {
5439  if (objname)
5440  *objname = list_make1(pstrdup(fdw->fdwname));
5441  }
5442  break;
5443  }
5444 
5445  case OCLASS_FOREIGN_SERVER:
5446  {
5447  ForeignServer *srv;
5448 
5449  srv = GetForeignServerExtended(object->objectId,
5450  missing_ok);
5451  if (srv)
5452  {
5453  appendStringInfoString(&buffer,
5455  if (objname)
5456  *objname = list_make1(pstrdup(srv->servername));
5457  }
5458  break;
5459  }
5460 
5461  case OCLASS_USER_MAPPING:
5462  {
5463  HeapTuple tup;
5464  Oid useid;
5465  Form_pg_user_mapping umform;
5466  ForeignServer *srv;
5467  const char *usename;
5468 
5470  ObjectIdGetDatum(object->objectId));
5471  if (!HeapTupleIsValid(tup))
5472  {
5473  if (!missing_ok)
5474  elog(ERROR, "cache lookup failed for user mapping %u",
5475  object->objectId);
5476  break;
5477  }
5478  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
5479  useid = umform->umuser;
5480  srv = GetForeignServer(umform->umserver);
5481 
5482  ReleaseSysCache(tup);
5483 
5484  if (OidIsValid(useid))
5485  usename = GetUserNameFromId(useid, false);
5486  else
5487  usename = "public";
5488 
5489  if (objname)
5490  {
5491  *objname = list_make1(pstrdup(usename));
5492  *objargs = list_make1(pstrdup(srv->servername));
5493  }
5494 
5495  appendStringInfo(&buffer, "%s on server %s",
5496  quote_identifier(usename),
5497  srv->servername);
5498  break;
5499  }
5500 
5501  case OCLASS_DEFACL:
5502  {
5503  Relation defaclrel;
5504  ScanKeyData skey[1];
5505  SysScanDesc rcscan;
5506  HeapTuple tup;
5507  Form_pg_default_acl defacl;
5508  char *schema;
5509  char *username;
5510 
5511  defaclrel = table_open(DefaultAclRelationId, AccessShareLock);
5512 
5513  ScanKeyInit(&skey[0],
5514  Anum_pg_default_acl_oid,
5515  BTEqualStrategyNumber, F_OIDEQ,
5516  ObjectIdGetDatum(object->objectId));
5517 
5518  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
5519  true, NULL, 1, skey);
5520 
5521  tup = systable_getnext(rcscan);
5522 
5523  if (!HeapTupleIsValid(tup))
5524  {
5525  if (!missing_ok)
5526  elog(ERROR, "could not find tuple for default ACL %u",
5527  object->objectId);
5528 
5529  systable_endscan(rcscan);
5530  table_close(defaclrel, AccessShareLock);
5531  break;
5532 
5533  }
5534 
5535  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
5536 
5537  username = GetUserNameFromId(defacl->defaclrole, false);
5538  appendStringInfo(&buffer,
5539  "for role %s",
5540  quote_identifier(username));
5541 
5542  if (OidIsValid(defacl->defaclnamespace))
5543  {
5544  schema = get_namespace_name_or_temp(defacl->defaclnamespace);
5545  appendStringInfo(&buffer,
5546  " in schema %s",
5547  quote_identifier(schema));
5548  }
5549  else
5550  schema = NULL;
5551 
5552  switch (defacl->defaclobjtype)
5553  {
5554  case DEFACLOBJ_RELATION:
5555  appendStringInfoString(&buffer,
5556  " on tables");
5557  break;
5558  case DEFACLOBJ_SEQUENCE:
5559  appendStringInfoString(&buffer,
5560  " on sequences");
5561  break;
5562  case DEFACLOBJ_FUNCTION:
5563  appendStringInfoString(&buffer,
5564  " on functions");
5565  break;
5566  case DEFACLOBJ_TYPE:
5567  appendStringInfoString(&buffer,
5568  " on types");
5569  break;
5570  case DEFACLOBJ_NAMESPACE:
5571  appendStringInfoString(&buffer,
5572  " on schemas");
5573  break;
5574  }
5575 
5576  if (objname)
5577  {
5578  *objname = list_make1(username);
5579  if (schema)
5580  *objname = lappend(*objname, schema);
5581  *objargs = list_make1(psprintf("%c", defacl->defaclobjtype));
5582  }
5583 
5584  systable_endscan(rcscan);
5585  table_close(defaclrel, AccessShareLock);
5586  break;
5587  }
5588 
5589  case OCLASS_EXTENSION:
5590  {
5591  char *extname;
5592 
5593  extname = get_extension_name(object->objectId);
5594  if (!extname)
5595  {
5596  if (!missing_ok)
5597  elog(ERROR, "cache lookup failed for extension %u",
5598  object->objectId);
5599  break;
5600  }
5601  appendStringInfoString(&buffer, quote_identifier(extname));
5602  if (objname)
5603  *objname = list_make1(extname);
5604  break;
5605  }
5606 
5607  case OCLASS_EVENT_TRIGGER:
5608  {
5609  HeapTuple tup;
5610  Form_pg_event_trigger trigForm;
5611 
5612  /* no objname support here */
5613  if (objname)
5614  *objname = NIL;
5615 
5617  ObjectIdGetDatum(object->objectId));
5618  if (!HeapTupleIsValid(tup))
5619  {
5620  if (!missing_ok)
5621  elog(ERROR, "cache lookup failed for event trigger %u",
5622  object->objectId);
5623  break;
5624  }
5625  trigForm = (Form_pg_event_trigger) GETSTRUCT(tup);
5626  appendStringInfoString(&buffer,
5627  quote_identifier(NameStr(trigForm->evtname)));
5628  ReleaseSysCache(tup);
5629  break;
5630  }
5631 
5632  case OCLASS_POLICY:
5633  {
5634  Relation polDesc;
5635  HeapTuple tup;
5636  Form_pg_policy policy;
5637 
5638  polDesc = table_open(PolicyRelationId, AccessShareLock);
5639 
5640  tup = get_catalog_object_by_oid(polDesc, Anum_pg_policy_oid,
5641  object->objectId);
5642 
5643  if (!HeapTupleIsValid(tup))
5644  {
5645  if (!missing_ok)
5646  elog(ERROR, "could not find tuple for policy %u",
5647  object->objectId);
5648 
5649  table_close(polDesc, AccessShareLock);
5650  break;
5651  }
5652 
5653  policy = (Form_pg_policy) GETSTRUCT(tup);
5654 
5655  appendStringInfo(&buffer, "%s on ",
5656  quote_identifier(NameStr(policy->polname)));
5657  getRelationIdentity(&buffer, policy->polrelid, objname, false);
5658  if (objname)
5659  *objname = lappend(*objname, pstrdup(NameStr(policy->polname)));
5660 
5661  table_close(polDesc, AccessShareLock);
5662  break;
5663  }
5664 
5665  case OCLASS_PUBLICATION:
5666  {
5667  char *pubname;
5668 
5669  pubname = get_publication_name(object->objectId, missing_ok);
5670  if (pubname)
5671  {
5672  appendStringInfoString(&buffer,
5673  quote_identifier(pubname));
5674  if (objname)
5675  *objname = list_make1(pubname);
5676  }
5677  break;
5678  }
5679 
5681  {
5682  HeapTuple tup;
5683  char *pubname;
5684  Form_pg_publication_rel prform;
5685 
5687  ObjectIdGetDatum(object->objectId));
5688  if (!HeapTupleIsValid(tup))
5689  {
5690  if (!missing_ok)
5691  elog(ERROR, "cache lookup failed for publication table %u",
5692  object->objectId);
5693  break;
5694  }
5695 
5696  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
5697  pubname = get_publication_name(prform->prpubid, false);
5698 
5699  getRelationIdentity(&buffer, prform->prrelid, objname, false);
5700  appendStringInfo(&buffer, " in publication %s", pubname);
5701 
5702  if (objargs)
5703  *objargs = list_make1(pubname);
5704 
5705  ReleaseSysCache(tup);
5706  break;
5707  }
5708 
5709  case OCLASS_SUBSCRIPTION:
5710  {
5711  char *subname;
5712 
5713  subname = get_subscription_name(object->objectId, missing_ok);
5714  if (subname)
5715  {
5716  appendStringInfoString(&buffer,
5717  quote_identifier(subname));
5718  if (objname)
5719  *objname = list_make1(subname);
5720  }
5721  break;
5722  }
5723 
5724  case OCLASS_TRANSFORM:
5725  {
5726  Relation transformDesc;
5727  HeapTuple tup;
5728  Form_pg_transform transform;
5729  char *transformLang;
5730  char *transformType;
5731 
5732  transformDesc = table_open(TransformRelationId, AccessShareLock);
5733 
5734  tup = get_catalog_object_by_oid(transformDesc,
5735  Anum_pg_transform_oid,
5736  object->objectId);
5737 
5738  if (!HeapTupleIsValid(tup))
5739  {
5740  if (!missing_ok)
5741  elog(ERROR, "could not find tuple for transform %u",
5742  object->objectId);
5743 
5744  table_close(transformDesc, AccessShareLock);
5745  break;
5746  }
5747 
5748  transform = (Form_pg_transform) GETSTRUCT(tup);
5749 
5750  transformType = format_type_be_qualified(transform->trftype);
5751  transformLang = get_language_name(transform->trflang, false);
5752 
5753  appendStringInfo(&buffer, "for %s on language %s",
5754  transformType,
5755  transformLang);
5756  if (objname)
5757  {
5758  *objname = list_make1(transformType);
5759  *objargs = list_make1(pstrdup(transformLang));
5760  }
5761 
5762  table_close(transformDesc, AccessShareLock);
5763  }
5764  break;
5765 
5766  /*
5767  * There's intentionally no default: case here; we want the
5768  * compiler to warn if a new OCLASS hasn't been handled above.
5769  */
5770  }
5771 
5772  if (!missing_ok)
5773  {
5774  /*
5775  * If a get_object_address() representation was requested, make sure
5776  * we are providing one. We don't check objargs, because many of the
5777  * cases above leave it as NIL.
5778  */
5779  if (objname && *objname == NIL)
5780  elog(ERROR, "requested object address for unsupported object class %d: text result \"%s\"",
5781  (int) getObjectClass(object), buffer.data);
5782  }
5783  else
5784  {
5785  /* an empty buffer is equivalent to no object found */
5786  if (buffer.len == 0)
5787  {
5788  Assert((objname == NULL || *objname == NIL) &&
5789  (objargs == NULL || *objargs == NIL));
5790  return NULL;
5791  }
5792  }
5793 
5794  return buffer.data;
5795 }
#define list_make2(x1, x2)
Definition: pg_list.h:228
#define list_make3(x1, x2, x3)
Definition: pg_list.h:230
#define NIL
Definition: pg_list.h:65
char * getObjectIdentityParts(const ObjectAddress *object, List **objname, List **objargs, bool missing_ok)
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
NameData proname
Definition: pg_proc.h:35
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:569
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
Definition: syscache.h:36
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10711
char * get_language_name(Oid langoid, bool missing_ok)
Definition: lsyscache.c:1100
FormData_pg_ts_config * Form_pg_ts_config
Definition: pg_ts_config.h:48
uint16 bits16
Definition: c.h:382
char * fdwname
Definition: foreign.h:28
static void getOpFamilyIdentity(StringInfo buffer, Oid opfid, List **object, bool missing_ok)
FormData_pg_amproc * Form_pg_amproc
Definition: pg_amproc.h:68
char * pstrdup(const char *in)
Definition: mcxt.c:1187
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
char * get_extension_name(Oid ext_oid)
Definition: extension.c:185
#define DefaultAclOidIndexId
Definition: indexing.h:322
#define AccessShareLock
Definition: lockdefs.h:36
#define AttrDefaultOidIndexId
Definition: indexing.h:102
#define AccessMethodOperatorOidIndexId
Definition: indexing.h:92
NameData datname
Definition: pg_database.h:35
unsigned int Oid
Definition: postgres_ext.h:31
NameData subname
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2722
#define OidIsValid(objectId)
Definition: c.h:651
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:357
char * get_publication_name(Oid pubid, bool missing_ok)
char * format_operator_extended(Oid operator_oid, bits16 flags)
Definition: regproc.c:780
Definition: localtime.c:72
char * get_subscription_name(Oid subid, bool missing_ok)
#define AccessMethodProcedureOidIndexId
Definition: indexing.h:97
#define list_make1(x1)
Definition: pg_list.h:226
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:476
void pfree(void *pointer)
Definition: mcxt.c:1057
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
FormData_pg_transform * Form_pg_transform
Definition: pg_transform.h:43
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2155
FormData_pg_user_mapping * Form_pg_user_mapping
FormData_pg_ts_dict * Form_pg_ts_dict
Definition: pg_ts_dict.h:52
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
FormData_pg_default_acl * Form_pg_default_acl
char * get_am_name(Oid amOid)
Definition: amcmds.c:192
#define FORMAT_TYPE_FORCE_QUALIFY
Definition: builtins.h:114
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:57
List * lappend(List *list, void *datum)
Definition: list.c:321
static void getRelationIdentity(StringInfo buffer, Oid relid, List **object, bool missing_ok)
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
FormData_pg_attrdef * Form_pg_attrdef
Definition: pg_attrdef.h:47
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10795
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
#define FORMAT_TYPE_INVALID_AS_NULL
Definition: builtins.h:115
#define FORMAT_OPERATOR_INVALID_AS_NULL
Definition: regproc.h:24
ForeignServer * GetForeignServer(Oid serverid)
Definition: foreign.c:109
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
FormData_pg_ts_parser * Form_pg_ts_parser
Definition: pg_ts_parser.h:55
FormData_pg_conversion * Form_pg_conversion
Definition: pg_conversion.h:61
char * format_procedure_extended(Oid procedure_oid, bits16 flags)
Definition: regproc.c:349
void format_procedure_parts(Oid procedure_oid, List **objnames, List **objargs, bool missing_ok)
Definition: regproc.c:421
static char * username
Definition: initdb.c:134
FormData_pg_policy * Form_pg_policy
Definition: pg_policy.h:50
ForeignServer * GetForeignServerExtended(Oid serverid, bits16 flags)
Definition: foreign.c:121
#define FORMAT_PROC_INVALID_AS_NULL
Definition: regproc.h:19
FormData_pg_constraint * Form_pg_constraint
FormData_pg_event_trigger * Form_pg_event_trigger
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:891
#define Assert(condition)
Definition: c.h:745
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:349
FormData_pg_trigger * Form_pg_trigger
Definition: pg_trigger.h:73
char * format_type_extended(Oid type_oid, int32 typemod, bits16 flags)
Definition: format_type.c:111
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:51
FormData_pg_rewrite * Form_pg_rewrite
Definition: pg_rewrite.h:52
#define FORMAT_PROC_FORCE_QUALIFY
Definition: regproc.h:20
FormData_pg_am * Form_pg_am
Definition: pg_am.h:48
bool LargeObjectExists(Oid loid)
void format_operator_parts(Oid operator_oid, List **objnames, List **objargs, bool missing_ok)
Definition: regproc.c:864
FormData_pg_language * Form_pg_language
Definition: pg_language.h:65
ForeignDataWrapper * GetForeignDataWrapperExtended(Oid fdwid, bits16 flags)
Definition: foreign.c:47
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3215
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:88
char * get_tablespace_name(Oid spc_oid)
Definition: tablespace.c:1467
char * servername
Definition: foreign.h:39
FormData_pg_ts_template * Form_pg_ts_template
#define elog(elevel,...)
Definition: elog.h:214
FormData_pg_publication_rel * Form_pg_publication_rel
#define NameStr(name)
Definition: c.h:622
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition: lsyscache.c:825
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
FormData_pg_opclass * Form_pg_opclass
Definition: pg_opclass.h:83
#define PointerIsValid(pointer)
Definition: c.h:639
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define FORMAT_OPERATOR_FORCE_QUALIFY
Definition: regproc.h:25
FormData_pg_statistic_ext * Form_pg_statistic_ext

◆ getObjectTypeDescription()

char* getObjectTypeDescription ( const ObjectAddress object,
bool  missing_ok 
)

Definition at line 4318 of file objectaddress.c.

References appendStringInfoString(), StringInfoData::data, getConstraintTypeDescription(), getObjectClass(), getProcedureTypeDescription(), getRelationTypeDescription(), initStringInfo(), StringInfoData::len, ObjectAddress::objectId, ObjectAddress::objectSubId, OCLASS_AM, OCLASS_AMOP, OCLASS_AMPROC, OCLASS_CAST, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONSTRAINT, OCLASS_CONVERSION, OCLASS_DATABASE, OCLASS_DEFACL, OCLASS_DEFAULT, OCLASS_EVENT_TRIGGER, OCLASS_EXTENSION, OCLASS_FDW, OCLASS_FOREIGN_SERVER, OCLASS_LANGUAGE, OCLASS_LARGEOBJECT, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_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().

4319 {
4320  StringInfoData buffer;
4321 
4322  initStringInfo(&buffer);
4323 
4324  switch (getObjectClass(object))
4325  {
4326  case OCLASS_CLASS:
4327  getRelationTypeDescription(&buffer, object->objectId,
4328  object->objectSubId,
4329  missing_ok);
4330  break;
4331 
4332  case OCLASS_PROC:
4333  getProcedureTypeDescription(&buffer, object->objectId,
4334  missing_ok);
4335  break;
4336 
4337  case OCLASS_TYPE:
4338  appendStringInfoString(&buffer, "type");
4339  break;
4340 
4341  case OCLASS_CAST:
4342  appendStringInfoString(&buffer, "cast");
4343  break;
4344 
4345  case OCLASS_COLLATION:
4346  appendStringInfoString(&buffer, "collation");
4347  break;
4348 
4349  case OCLASS_CONSTRAINT:
4350  getConstraintTypeDescription(&buffer, object->objectId,
4351  missing_ok);
4352  break;
4353 
4354  case OCLASS_CONVERSION:
4355  appendStringInfoString(&buffer, "conversion");
4356  break;
4357 
4358  case OCLASS_DEFAULT:
4359  appendStringInfoString(&buffer, "default value");
4360  break;
4361 
4362  case OCLASS_LANGUAGE:
4363  appendStringInfoString(&buffer, "language");
4364  break;
4365 
4366  case OCLASS_LARGEOBJECT:
4367  appendStringInfoString(&buffer, "large object");
4368  break;
4369 
4370  case OCLASS_OPERATOR:
4371  appendStringInfoString(&buffer, "operator");
4372  break;
4373 
4374  case OCLASS_OPCLASS:
4375  appendStringInfoString(&buffer, "operator class");
4376  break;
4377 
4378  case OCLASS_OPFAMILY:
4379  appendStringInfoString(&buffer, "operator family");
4380  break;
4381 
4382  case OCLASS_AM:
4383  appendStringInfoString(&buffer, "access method");
4384  break;
4385 
4386  case OCLASS_AMOP:
4387  appendStringInfoString(&buffer, "operator of access method");
4388  break;
4389 
4390  case OCLASS_AMPROC:
4391  appendStringInfoString(&buffer, "function of access method");
4392  break;
4393 
4394  case OCLASS_REWRITE:
4395  appendStringInfoString(&buffer, "rule");
4396  break;
4397 
4398  case OCLASS_TRIGGER:
4399  appendStringInfoString(&buffer, "trigger");
4400  break;
4401 
4402  case OCLASS_SCHEMA:
4403  appendStringInfoString(&buffer, "schema");
4404  break;
4405 
4406  case OCLASS_STATISTIC_EXT:
4407  appendStringInfoString(&buffer, "statistics object");
4408  break;
4409 
4410  case OCLASS_TSPARSER:
4411  appendStringInfoString(&buffer, "text search parser");
4412  break;
4413 
4414  case OCLASS_TSDICT:
4415  appendStringInfoString(&buffer, "text search dictionary");
4416  break;
4417 
4418  case OCLASS_TSTEMPLATE:
4419  appendStringInfoString(&buffer, "text search template");
4420  break;
4421 
4422  case OCLASS_TSCONFIG:
4423  appendStringInfoString(&buffer, "text search configuration");
4424  break;
4425 
4426  case OCLASS_ROLE:
4427  appendStringInfoString(&buffer, "role");
4428  break;
4429 
4430  case OCLASS_DATABASE:
4431  appendStringInfoString(&buffer, "database");
4432  break;
4433 
4434  case OCLASS_TBLSPACE:
4435  appendStringInfoString(&buffer, "tablespace");
4436  break;
4437 
4438  case OCLASS_FDW:
4439  appendStringInfoString(&buffer, "foreign-data wrapper");
4440  break;
4441 
4442  case OCLASS_FOREIGN_SERVER:
4443  appendStringInfoString(&buffer, "server");
4444  break;
4445 
4446  case OCLASS_USER_MAPPING:
4447  appendStringInfoString(&buffer, "user mapping");
4448  break;
4449 
4450  case OCLASS_DEFACL:
4451  appendStringInfoString(&buffer, "default acl");
4452  break;
4453 
4454  case OCLASS_EXTENSION:
4455  appendStringInfoString(&buffer, "extension");
4456  break;
4457 
4458  case OCLASS_EVENT_TRIGGER:
4459  appendStringInfoString(&buffer, "event trigger");
4460  break;
4461 
4462  case OCLASS_POLICY:
4463  appendStringInfoString(&buffer, "policy");
4464  break;
4465 
4466  case OCLASS_PUBLICATION:
4467  appendStringInfoString(&buffer, "publication");
4468  break;
4469 
4471  appendStringInfoString(&buffer, "publication relation");
4472  break;
4473 
4474  case OCLASS_SUBSCRIPTION:
4475  appendStringInfoString(&buffer, "subscription");
4476  break;
4477 
4478  case OCLASS_TRANSFORM:
4479  appendStringInfoString(&buffer, "transform");
4480  break;
4481 
4482  /*
4483  * There's intentionally no default: case here; we want the
4484  * compiler to warn if a new OCLASS hasn't been handled above.
4485  */
4486  }
4487 
4488  /* an empty string is equivalent to no object found */
4489  if (buffer.len == 0)
4490  return NULL;
4491 
4492  return buffer.data;
4493 }
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2722
static void getRelationTypeDescription(StringInfo buffer, Oid relid, int32 objectSubId, bool missing_ok)
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
static void getConstraintTypeDescription(StringInfo buffer, Oid constroid, bool missing_ok)
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
static void getProcedureTypeDescription(StringInfo buffer, Oid procid, bool missing_ok)

◆ is_objectclass_supported()

bool is_objectclass_supported ( Oid  class_id)

Definition at line 2757 of file objectaddress.c.

References lengthof.

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

2758 {
2759  int index;
2760 
2761  for (index = 0; index < lengthof(ObjectProperty); index++)
2762  {
2763  if (ObjectProperty[index].class_oid == class_id)
2764  return true;
2765  }
2766 
2767  return false;
2768 }
#define lengthof(array)
Definition: c.h:675
Definition: type.h:89
static const ObjectPropertyType ObjectProperty[]

◆ read_objtype_from_string()

int read_objtype_from_string ( const char *  objtype)

Definition at line 2628 of file objectaddress.c.

References ereport, errcode(), errmsg(), ERROR, i, lengthof, ObjectTypeMap, object_type_map::tm_name, and object_type_map::tm_type.

Referenced by pg_get_object_address().

2629 {
2630  int i;
2631 
2632  for (i = 0; i < lengthof(ObjectTypeMap); i++)
2633  {
2634  if (strcmp(ObjectTypeMap[i].tm_name, objtype) == 0)
2635  return ObjectTypeMap[i].tm_type;
2636  }
2637  ereport(ERROR,
2638  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2639  errmsg("unrecognized object type \"%s\"", objtype)));
2640 
2641  return -1; /* keep compiler quiet */
2642 }
int errcode(int sqlerrcode)
Definition: elog.c:610
#define lengthof(array)
Definition: c.h:675
#define ERROR
Definition: elog.h:43
static const struct object_type_map ObjectTypeMap[]
#define ereport(elevel,...)
Definition: elog.h:144
int errmsg(const char *fmt,...)
Definition: elog.c:824
int i

◆ strlist_to_textarray()

struct ArrayType* strlist_to_textarray ( List list)

Definition at line 5876 of file objectaddress.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, construct_md_array(), CStringGetTextDatum, CurrentMemoryContext, lfirst, list_length(), MemoryContextDelete(), MemoryContextSwitchTo(), name, and palloc().

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

5877 {
5878  ArrayType *arr;
5879  Datum *datums;
5880  bool *nulls;
5881  int j = 0;
5882  ListCell *cell;
5883  MemoryContext memcxt;
5884  MemoryContext oldcxt;
5885  int lb[1];
5886 
5887  /* Work in a temp context; easier than individually pfree'ing the Datums */
5889  "strlist to array",
5891  oldcxt = MemoryContextSwitchTo(memcxt);
5892 
5893  datums = (Datum *) palloc(sizeof(Datum) * list_length(list));
5894  nulls = palloc(sizeof(bool) * list_length(list));
5895 
5896  foreach(cell, list)
5897  {
5898  char *name = lfirst(cell);
5899 
5900  if (name)
5901  {
5902  nulls[j] = false;
5903  datums[j++] = CStringGetTextDatum(name);
5904  }
5905  else
5906  nulls[j] = true;
5907  }
5908 
5909  MemoryContextSwitchTo(oldcxt);
5910 
5911  lb[0] = 1;
5912  arr = construct_md_array(datums, nulls, 1, &j,
5913  lb, TEXTOID, -1, false, TYPALIGN_INT);
5914 
5915  MemoryContextDelete(memcxt);
5916 
5917  return arr;
5918 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:212
#define AllocSetContextCreate
Definition: memutils.h:170
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
uintptr_t Datum
Definition: postgres.h:367
#define lfirst(lc)
Definition: pg_list.h:189
static int list_length(const List *l)
Definition: pg_list.h:169
const char * name
Definition: encode.c:561
void * palloc(Size size)
Definition: mcxt.c:950
#define CStringGetTextDatum(s)
Definition: builtins.h:86
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:3348

Variable Documentation

◆ InvalidObjectAddress