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(), ATExecDetachPartitionFinalize(), ATExecDropInherit(), ATExecValidateConstraint(), ATPostAlterTypeCleanup(), CastCreate(), CloneFkReferencing(), ConstraintSetParentConstraint(), CreateConstraintEntry(), CreateProceduralLanguage(), CreatePublication(), CreateSchemaCommand(), CreateStatistics(), CreateSubscription(), CreateTransform(), CreateTriggerFiringOn(), DefineCollation(), DefineIndex(), DefineQueryRewrite(), DefineRelation(), DefineTSConfiguration(), DefineVirtualRelation(), DetachPartitionFinalize(), 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(), recordDependencyOnTablespace(), 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:5443
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:5262
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
bool lo_compat_privileges
Definition: inv_api.c:58
bool pg_largeobject_ownercheck(Oid lobj_oid, Oid roleid)
Definition: aclchk.c:4951
bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid)
Definition: aclchk.c:5101
bool pg_language_ownercheck(Oid lan_oid, Oid roleid)
Definition: aclchk.c:4922
#define castNode(_type_, nodeptr)
Definition: nodes.h:608
bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid)
Definition: aclchk.c:5128
bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5182
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5356
#define strVal(v)
Definition: value.h:54
bool pg_oper_ownercheck(Oid oper_oid, Oid roleid)
Definition: aclchk.c:4870
int errcode(int sqlerrcode)
Definition: elog.c:698
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
bool pg_namespace_ownercheck(Oid nsp_oid, Oid roleid)
Definition: aclchk.c:4994
unsigned int Oid
Definition: postgres_ext.h:31
bool pg_type_ownercheck(Oid type_oid, Oid roleid)
Definition: aclchk.c:4844
#define linitial_node(type, l)
Definition: pg_list.h:177
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3621
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3308
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:5209
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5314
#define RelationGetRelationName(relation)
Definition: rel.h:511
bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid)
Definition: aclchk.c:5020
bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
Definition: aclchk.c:5074
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
Definition: aclchk.c:5236
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
char * NameListToString(List *names)
Definition: namespace.c:3147
#define lsecond_node(type, l)
Definition: pg_list.h:182
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid)
Definition: aclchk.c:5047
bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid)
Definition: aclchk.c:5288
#define ereport(elevel,...)
Definition: elog.h:157
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:4818
bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5155
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define elog(elevel,...)
Definition: elog.h:232
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:477
bool pg_proc_ownercheck(Oid proc_oid, Oid roleid)
Definition: aclchk.c:4896
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:291
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5382
bool pg_statistics_object_ownercheck(Oid stat_oid, Oid roleid)
Definition: aclchk.c:5408

◆ 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:595
Oid get_object_oid_index(Oid class_id)
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:710
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:383
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:502
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
int get_object_catcache_oid(Oid class_id)
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:804
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:175
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define RelationGetRelid(relation)
Definition: rel.h:477
#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:608
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:698
Oid get_ts_config_oid(List *names, bool missing_ok)
Definition: namespace.c:2724
unsigned int Oid
Definition: postgres_ext.h:31
#define linitial_node(type, l)
Definition: pg_list.h:177
static ObjectAddress get_object_address_unqualified(ObjectType objtype, Value *strval, bool missing_ok)
#define OidIsValid(objectId)
Definition: c.h:710
#define lsecond(l)
Definition: pg_list.h:179
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:2471
Oid get_transform_oid(Oid type_id, Oid lang_id, bool missing_ok)
#define ERROR
Definition: elog.h:46
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:2223
Oid get_ts_template_oid(List *names, bool missing_ok)
Definition: namespace.c:2598
#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:182
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:244
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:157
Oid get_ts_parser_oid(List *names, bool missing_ok)
Definition: namespace.c:2345
#define Assert(condition)
Definition: c.h:804
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:3700
bool LargeObjectExists(Oid loid)
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define elog(elevel,...)
Definition: elog.h:232
Oid LookupFuncWithArgs(ObjectType objtype, ObjectWithArgs *func, bool missing_ok)
Definition: parse_func.c:2207
Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok)
Definition: lsyscache.c:1032
Oid get_collation_oid(List *name, bool missing_ok)
Definition: namespace.c:3646
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:539
char * schemaname
Definition: primnodes.h:67
char * relname
Definition: primnodes.h:68
List * lcons(void *datum, List *list)
Definition: list.c:468
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
Definition: objectaddress.c:99
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:544
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
static const ObjectPropertyType * get_object_property_data(Oid class_id)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1388
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:804
AttrNumber attnum_namespace
#define InvalidAttrNumber
Definition: attnum.h:23
#define elog(elevel,...)
Definition: elog.h:232

◆ 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:1974
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 5936 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(), CreateTriggerFiringOn(), currtid_internal(), DefineQueryRewrite(), EnableDisableRule(), ExecCheckRTPerms(), get_object_type(), get_rel_from_relname(), heap_force_common(), LockViewRecurse_walker(), MergeAttributes(), pg_prewarm(), pgrowlocks(), PublicationAddTables(), RangeVarCallbackForAlterRelation(), RangeVarCallbackForDropRelation(), RangeVarCallbackForLockTable(), RangeVarCallbackForPolicy(), RangeVarCallbackForRenameRule(), RangeVarCallbackForRenameTrigger(), RangeVarCallbackOwnsRelation(), RangeVarCallbackOwnsTable(), RangeVarGetAndCheckCreationNamespace(), renameatt_check(), transformTableLikeClause(), and truncate_check_perms().

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

◆ getObjectDescription()

char* getObjectDescription ( const ObjectAddress object,
bool  missing_ok 
)

Definition at line 2857 of file objectaddress.c.

References _, AccessShareLock, AMOID, appendStringInfo(), Assert, attname, BTEqualStrategyNumber, CLAOID, ObjectAddress::classId, CollationIsVisible(), COLLOID, CONSTROID, ConversionIsVisible(), CONVOID, StringInfoData::data, datname, elog, ERROR, EVENTTRIGGEROID, ForeignDataWrapper::fdwname, format_operator(), format_operator_extended(), FORMAT_OPERATOR_INVALID_AS_NULL, FORMAT_PROC_INVALID_AS_NULL, format_procedure(), format_procedure_extended(), format_type_be(), format_type_extended(), FORMAT_TYPE_INVALID_AS_NULL, get_attname(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name(), get_publication_name(), get_subscription_name(), get_tablespace_name(), GetForeignDataWrapperExtended(), GetForeignServer(), GetForeignServerExtended(), getObjectClass(), 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(), proname, PUBLICATIONREL, quote_qualified_identifier(), ReleaseSysCache(), ScanKeyInit(), SearchSysCache1(), ForeignServer::servername, STATEXTOID, StatisticsObjIsVisible(), subname, systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TRFOID, TSConfigIsVisible(), TSCONFIGOID, TSDictionaryIsVisible(), TSDICTOID, TSParserIsVisible(), TSPARSEROID, TSTemplateIsVisible(), TSTEMPLATEOID, typname, USERMAPPINGOID, and username.

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

◆ getObjectDescriptionOids()

char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 3957 of file objectaddress.c.

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

3958 {
3959  ObjectAddress address;
3960 
3961  address.classId = classid;
3962  address.objectId = objid;
3963  address.objectSubId = 0;
3964 
3965  return getObjectDescription(&address, false);
3966 }
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 4655 of file objectaddress.c.

References AccessShareLock, AMOID, appendStringInfo(), appendStringInfoString(), Assert, BTEqualStrategyNumber, CLAOID, ObjectAddress::classId, COLLOID, CONSTROID, CONVOID, StringInfoData::data, datname, elog, ERROR, EVENTTRIGGEROID, ForeignDataWrapper::fdwname, format_operator_extended(), FORMAT_OPERATOR_FORCE_QUALIFY, FORMAT_OPERATOR_INVALID_AS_NULL, format_operator_parts(), FORMAT_PROC_FORCE_QUALIFY, FORMAT_PROC_INVALID_AS_NULL, format_procedure_extended(), format_procedure_parts(), format_type_be_qualified(), format_type_extended(), FORMAT_TYPE_FORCE_QUALIFY, FORMAT_TYPE_INVALID_AS_NULL, get_am_name(), get_attname(), get_catalog_object_by_oid(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name_or_temp(), get_publication_name(), get_subscription_name(), get_tablespace_name(), GetForeignDataWrapperExtended(), GetForeignServer(), GetForeignServerExtended(), getObjectClass(), 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().

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

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

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

◆ strlist_to_textarray()

struct ArrayType* strlist_to_textarray ( List list)

Definition at line 5881 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().

5882 {
5883  ArrayType *arr;
5884  Datum *datums;
5885  bool *nulls;
5886  int j = 0;
5887  ListCell *cell;
5888  MemoryContext memcxt;
5889  MemoryContext oldcxt;
5890  int lb[1];
5891 
5892  /* Work in a temp context; easier than individually pfree'ing the Datums */
5894  "strlist to array",
5896  oldcxt = MemoryContextSwitchTo(memcxt);
5897 
5898  datums = (Datum *) palloc(sizeof(Datum) * list_length(list));
5899  nulls = palloc(sizeof(bool) * list_length(list));
5900 
5901  foreach(cell, list)
5902  {
5903  char *name = lfirst(cell);
5904 
5905  if (name)
5906  {
5907  nulls[j] = false;
5908  datums[j++] = CStringGetTextDatum(name);
5909  }
5910  else
5911  nulls[j] = true;
5912  }
5913 
5914  MemoryContextSwitchTo(oldcxt);
5915 
5916  lb[0] = 1;
5917  arr = construct_md_array(datums, nulls, 1, &j,
5918  lb, TEXTOID, -1, false, TYPALIGN_INT);
5919 
5920  MemoryContextDelete(memcxt);
5921 
5922  return arr;
5923 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:218
#define AllocSetContextCreate
Definition: memutils.h:173
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:195
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
uintptr_t Datum
Definition: postgres.h:411
#define lfirst(lc)
Definition: pg_list.h:169
static int list_length(const List *l)
Definition: pg_list.h:149
const char * name
Definition: encode.c:515
void * palloc(Size size)
Definition: mcxt.c:1062
#define CStringGetTextDatum(s)
Definition: builtins.h:82
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:3353

Variable Documentation

◆ InvalidObjectAddress