PostgreSQL Source Code  git master
objectaddress.h File Reference
#include "nodes/pg_list.h"
#include "storage/lockdefs.h"
#include "utils/acl.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)
 
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)
 
char * getObjectDescriptionOids (Oid classid, Oid objid)
 
int read_objtype_from_string (const char *objtype)
 
char * getObjectTypeDescription (const ObjectAddress *object)
 
char * getObjectIdentity (const ObjectAddress *address)
 
char * getObjectIdentityParts (const ObjectAddress *address, List **objname, List **objargs)
 
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(), AlterCollation(), AlterDatabaseOwner(), AlterDomainAddConstraint(), AlterDomainDefault(), AlterDomainDropConstraint(), AlterDomainNotNull(), AlterDomainValidateConstraint(), AlterEnum(), AlterEventTriggerOwner(), AlterExtensionNamespace(), AlterForeignDataWrapper(), AlterForeignDataWrapperOwner(), AlterForeignServer(), AlterForeignServerOwner(), AlterFunction(), AlterPublicationOptions(), AlterPublicationOwner(), AlterSchemaOwner(), AlterSequence(), AlterStatistics(), AlterSubscription(), AlterSubscriptionOwner(), AlterTableNamespace(), AlterTSConfiguration(), AlterTSDictionary(), AlterTypeNamespace(), AlterTypeOwner(), AlterUserMapping(), ATAddCheckConstraint(), ATExecAddInherit(), ATExecAlterConstraint(), ATExecAttachPartition(), ATExecAttachPartitionIdx(), ATExecClusterOn(), ATExecDetachPartition(), ATExecDropInherit(), ATExecValidateConstraint(), ATPostAlterTypeCleanup(), CloneFkReferencing(), ConstraintSetParentConstraint(), CreatePublication(), CreateSchemaCommand(), CreateStatistics(), CreateSubscription(), CreateTrigger(), DefineCollation(), DefineIndex(), DefineQueryRewrite(), DefineRelation(), DefineTSConfiguration(), DefineVirtualRelation(), domainAddConstraint(), DropSubscription(), EventTriggerCollectAlterOpFam(), EventTriggerCollectAlterTSConfig(), EventTriggerCollectCreateOpClass(), ExecAlterExtensionStmt(), ExecAlterObjectSchemaStmt(), ExecRefreshMatView(), get_object_address_defacl(), get_object_address_opf_member(), get_object_address_publication_rel(), get_object_address_usermapping(), index_constraint_create(), IndexSetParentIndex(), pg_event_trigger_ddl_commands(), publication_add_relation(), PublicationDropTables(), rename_constraint_internal(), rename_policy(), RenameDatabase(), RenameRelation(), RenameRewriteRule(), RenameRole(), RenameSchema(), RenameTableSpace(), renametrig(), RenameType(), SetFunctionArgType(), SetFunctionReturnType(), tryAttachPartitionForeignKey(), TypeCreate(), and TypeShellMake().

◆ ObjectAddressSubSet

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

Definition at line 33 of file objectaddress.h.

Referenced by ATExecAddColumn(), ATExecAddIdentity(), ATExecAlterColumnGenericOptions(), ATExecAlterColumnType(), ATExecColumnDefault(), ATExecDropIdentity(), ATExecDropNotNull(), ATExecSetIdentity(), ATExecSetNotNull(), ATExecSetOptions(), ATExecSetStatistics(), ATExecSetStorage(), CreateStatistics(), and renameatt().

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 2270 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(), ExecSecLabelStmt(), and RemoveObjects().

2272 {
2273  switch (objtype)
2274  {
2275  case OBJECT_INDEX:
2276  case OBJECT_SEQUENCE:
2277  case OBJECT_TABLE:
2278  case OBJECT_VIEW:
2279  case OBJECT_MATVIEW:
2280  case OBJECT_FOREIGN_TABLE:
2281  case OBJECT_COLUMN:
2282  case OBJECT_RULE:
2283  case OBJECT_TRIGGER:
2284  case OBJECT_POLICY:
2285  case OBJECT_TABCONSTRAINT:
2286  if (!pg_class_ownercheck(RelationGetRelid(relation), roleid))
2288  RelationGetRelationName(relation));
2289  break;
2290  case OBJECT_DATABASE:
2291  if (!pg_database_ownercheck(address.objectId, roleid))
2293  strVal((Value *) object));
2294  break;
2295  case OBJECT_TYPE:
2296  case OBJECT_DOMAIN:
2297  case OBJECT_ATTRIBUTE:
2298  if (!pg_type_ownercheck(address.objectId, roleid))
2300  break;
2301  case OBJECT_DOMCONSTRAINT:
2302  {
2303  HeapTuple tuple;
2304  Oid contypid;
2305 
2306  tuple = SearchSysCache1(CONSTROID,
2307  ObjectIdGetDatum(address.objectId));
2308  if (!HeapTupleIsValid(tuple))
2309  elog(ERROR, "constraint with OID %u does not exist",
2310  address.objectId);
2311 
2312  contypid = ((Form_pg_constraint) GETSTRUCT(tuple))->contypid;
2313 
2314  ReleaseSysCache(tuple);
2315 
2316  /*
2317  * Fallback to type ownership check in this case as this is
2318  * what domain constraints rely on.
2319  */
2320  if (!pg_type_ownercheck(contypid, roleid))
2322  }
2323  break;
2324  case OBJECT_AGGREGATE:
2325  case OBJECT_FUNCTION:
2326  case OBJECT_PROCEDURE:
2327  case OBJECT_ROUTINE:
2328  if (!pg_proc_ownercheck(address.objectId, roleid))
2330  NameListToString((castNode(ObjectWithArgs, object))->objname));
2331  break;
2332  case OBJECT_OPERATOR:
2333  if (!pg_oper_ownercheck(address.objectId, roleid))
2335  NameListToString((castNode(ObjectWithArgs, object))->objname));
2336  break;
2337  case OBJECT_SCHEMA:
2338  if (!pg_namespace_ownercheck(address.objectId, roleid))
2340  strVal((Value *) object));
2341  break;
2342  case OBJECT_COLLATION:
2343  if (!pg_collation_ownercheck(address.objectId, roleid))
2345  NameListToString(castNode(List, object)));
2346  break;
2347  case OBJECT_CONVERSION:
2348  if (!pg_conversion_ownercheck(address.objectId, roleid))
2350  NameListToString(castNode(List, object)));
2351  break;
2352  case OBJECT_EXTENSION:
2353  if (!pg_extension_ownercheck(address.objectId, roleid))
2355  strVal((Value *) object));
2356  break;
2357  case OBJECT_FDW:
2358  if (!pg_foreign_data_wrapper_ownercheck(address.objectId, roleid))
2360  strVal((Value *) object));
2361  break;
2362  case OBJECT_FOREIGN_SERVER:
2363  if (!pg_foreign_server_ownercheck(address.objectId, roleid))
2365  strVal((Value *) object));
2366  break;
2367  case OBJECT_EVENT_TRIGGER:
2368  if (!pg_event_trigger_ownercheck(address.objectId, roleid))
2370  strVal((Value *) object));
2371  break;
2372  case OBJECT_LANGUAGE:
2373  if (!pg_language_ownercheck(address.objectId, roleid))
2375  strVal((Value *) object));
2376  break;
2377  case OBJECT_OPCLASS:
2378  if (!pg_opclass_ownercheck(address.objectId, roleid))
2380  NameListToString(castNode(List, object)));
2381  break;
2382  case OBJECT_OPFAMILY:
2383  if (!pg_opfamily_ownercheck(address.objectId, roleid))
2385  NameListToString(castNode(List, object)));
2386  break;
2387  case OBJECT_LARGEOBJECT:
2388  if (!lo_compat_privileges &&
2389  !pg_largeobject_ownercheck(address.objectId, roleid))
2390  ereport(ERROR,
2391  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2392  errmsg("must be owner of large object %u",
2393  address.objectId)));
2394  break;
2395  case OBJECT_CAST:
2396  {
2397  /* We can only check permissions on the source/target types */
2398  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2399  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2400  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2401  Oid targettypeid = typenameTypeId(NULL, targettype);
2402 
2403  if (!pg_type_ownercheck(sourcetypeid, roleid)
2404  && !pg_type_ownercheck(targettypeid, roleid))
2405  ereport(ERROR,
2406  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2407  errmsg("must be owner of type %s or type %s",
2408  format_type_be(sourcetypeid),
2409  format_type_be(targettypeid))));
2410  }
2411  break;
2412  case OBJECT_PUBLICATION:
2413  if (!pg_publication_ownercheck(address.objectId, roleid))
2415  strVal((Value *) object));
2416  break;
2417  case OBJECT_SUBSCRIPTION:
2418  if (!pg_subscription_ownercheck(address.objectId, roleid))
2420  strVal((Value *) object));
2421  break;
2422  case OBJECT_TRANSFORM:
2423  {
2424  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2425  Oid typeid = typenameTypeId(NULL, typename);
2426 
2427  if (!pg_type_ownercheck(typeid, roleid))
2429  }
2430  break;
2431  case OBJECT_TABLESPACE:
2432  if (!pg_tablespace_ownercheck(address.objectId, roleid))
2434  strVal((Value *) object));
2435  break;
2436  case OBJECT_TSDICTIONARY:
2437  if (!pg_ts_dict_ownercheck(address.objectId, roleid))
2439  NameListToString(castNode(List, object)));
2440  break;
2442  if (!pg_ts_config_ownercheck(address.objectId, roleid))
2444  NameListToString(castNode(List, object)));
2445  break;
2446  case OBJECT_ROLE:
2447 
2448  /*
2449  * We treat roles as being "owned" by those with CREATEROLE priv,
2450  * except that superusers are only owned by superusers.
2451  */
2452  if (superuser_arg(address.objectId))
2453  {
2454  if (!superuser_arg(roleid))
2455  ereport(ERROR,
2456  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2457  errmsg("must be superuser")));
2458  }
2459  else
2460  {
2461  if (!has_createrole_privilege(roleid))
2462  ereport(ERROR,
2463  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2464  errmsg("must have CREATEROLE privilege")));
2465  }
2466  break;
2467  case OBJECT_TSPARSER:
2468  case OBJECT_TSTEMPLATE:
2469  case OBJECT_ACCESS_METHOD:
2470  /* We treat these object types as being owned by superusers */
2471  if (!superuser_arg(roleid))
2472  ereport(ERROR,
2473  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2474  errmsg("must be superuser")));
2475  break;
2476  case OBJECT_STATISTIC_EXT:
2477  if (!pg_statistics_object_ownercheck(address.objectId, roleid))
2479  break;
2480  default:
2481  elog(ERROR, "unrecognized object type: %d",
2482  (int) objtype);
2483  }
2484 }
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:5379
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:5198
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
bool lo_compat_privileges
Definition: inv_api.c:57
bool pg_largeobject_ownercheck(Oid lobj_oid, Oid roleid)
Definition: aclchk.c:4887
bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid)
Definition: aclchk.c:5037
bool pg_language_ownercheck(Oid lan_oid, Oid roleid)
Definition: aclchk.c:4858
#define castNode(_type_, nodeptr)
Definition: nodes.h:594
bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid)
Definition: aclchk.c:5064
bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5118
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5292
#define strVal(v)
Definition: value.h:54
bool pg_oper_ownercheck(Oid oper_oid, Oid roleid)
Definition: aclchk.c:4806
int errcode(int sqlerrcode)
Definition: elog.c:608
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
bool pg_namespace_ownercheck(Oid nsp_oid, Oid roleid)
Definition: aclchk.c:4930
unsigned int Oid
Definition: postgres_ext.h:31
bool pg_type_ownercheck(Oid type_oid, Oid roleid)
Definition: aclchk.c:4780
#define linitial_node(type, l)
Definition: pg_list.h:198
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3665
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3352
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:5145
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5250
#define RelationGetRelationName(relation)
Definition: rel.h:457
bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid)
Definition: aclchk.c:4956
bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
Definition: aclchk.c:5010
#define ereport(elevel, rest)
Definition: elog.h:141
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
Definition: aclchk.c:5172
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
char * NameListToString(List *names)
Definition: namespace.c:3094
#define lsecond_node(type, l)
Definition: pg_list.h:203
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid)
Definition: aclchk.c:4983
bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid)
Definition: aclchk.c:5224
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:4754
bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5091
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define elog(elevel,...)
Definition: elog.h:228
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:423
bool pg_proc_ownercheck(Oid proc_oid, Oid roleid)
Definition: aclchk.c:4832
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:291
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5318
bool pg_statistics_object_ownercheck(Oid stat_oid, Oid roleid)
Definition: aclchk.c:5344

◆ get_catalog_object_by_oid()

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

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

2706 {
2707  HeapTuple tuple;
2708  Oid classId = RelationGetRelid(catalog);
2709  int oidCacheId = get_object_catcache_oid(classId);
2710 
2711  if (oidCacheId > 0)
2712  {
2713  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2714  if (!HeapTupleIsValid(tuple)) /* should not happen */
2715  return NULL;
2716  }
2717  else
2718  {
2719  Oid oidIndexId = get_object_oid_index(classId);
2720  SysScanDesc scan;
2721  ScanKeyData skey;
2722 
2723  Assert(OidIsValid(oidIndexId));
2724 
2725  ScanKeyInit(&skey,
2726  oidcol,
2727  BTEqualStrategyNumber, F_OIDEQ,
2728  ObjectIdGetDatum(objectId));
2729 
2730  scan = systable_beginscan(catalog, oidIndexId, true,
2731  NULL, 1, &skey);
2732  tuple = systable_getnext(scan);
2733  if (!HeapTupleIsValid(tuple))
2734  {
2735  systable_endscan(scan);
2736  return NULL;
2737  }
2738  tuple = heap_copytuple(tuple);
2739 
2740  systable_endscan(scan);
2741  }
2742 
2743  return tuple;
2744 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:680
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:525
Oid get_object_oid_index(Oid class_id)
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:639
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:352
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:444
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
int get_object_catcache_oid(Oid class_id)
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:733
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:174
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define RelationGetRelid(relation)
Definition: rel.h:423
#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 833 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().

835 {
836  ObjectAddress address;
837  ObjectAddress old_address = {InvalidOid, InvalidOid, 0};
838  Relation relation = NULL;
839  uint64 inval_count;
840 
841  /* Some kind of lock must be taken. */
842  Assert(lockmode != NoLock);
843 
844  for (;;)
845  {
846  /*
847  * Remember this value, so that, after looking up the object name and
848  * locking it, we can check whether any invalidation messages have
849  * been processed that might require a do-over.
850  */
851  inval_count = SharedInvalidMessageCounter;
852 
853  /* Look up object address. */
854  switch (objtype)
855  {
856  case OBJECT_INDEX:
857  case OBJECT_SEQUENCE:
858  case OBJECT_TABLE:
859  case OBJECT_VIEW:
860  case OBJECT_MATVIEW:
862  address =
863  get_relation_by_qualified_name(objtype, castNode(List, object),
864  &relation, lockmode,
865  missing_ok);
866  break;
867  case OBJECT_COLUMN:
868  address =
869  get_object_address_attribute(objtype, castNode(List, object),
870  &relation, lockmode,
871  missing_ok);
872  break;
873  case OBJECT_DEFAULT:
874  address =
875  get_object_address_attrdef(objtype, castNode(List, object),
876  &relation, lockmode,
877  missing_ok);
878  break;
879  case OBJECT_RULE:
880  case OBJECT_TRIGGER:
882  case OBJECT_POLICY:
883  address = get_object_address_relobject(objtype, castNode(List, object),
884  &relation, missing_ok);
885  break;
887  {
888  List *objlist;
889  ObjectAddress domaddr;
890  char *constrname;
891 
892  objlist = castNode(List, object);
894  linitial_node(TypeName, objlist),
895  missing_ok);
896  constrname = strVal(lsecond(objlist));
897 
898  address.classId = ConstraintRelationId;
899  address.objectId = get_domain_constraint_oid(domaddr.objectId,
900  constrname, missing_ok);
901  address.objectSubId = 0;
902 
903  }
904  break;
905  case OBJECT_DATABASE:
906  case OBJECT_EXTENSION:
907  case OBJECT_TABLESPACE:
908  case OBJECT_ROLE:
909  case OBJECT_SCHEMA:
910  case OBJECT_LANGUAGE:
911  case OBJECT_FDW:
915  case OBJECT_PUBLICATION:
916  case OBJECT_SUBSCRIPTION:
917  address = get_object_address_unqualified(objtype,
918  (Value *) object, missing_ok);
919  break;
920  case OBJECT_TYPE:
921  case OBJECT_DOMAIN:
922  address = get_object_address_type(objtype, castNode(TypeName, object), missing_ok);
923  break;
924  case OBJECT_AGGREGATE:
925  case OBJECT_FUNCTION:
926  case OBJECT_PROCEDURE:
927  case OBJECT_ROUTINE:
928  address.classId = ProcedureRelationId;
929  address.objectId = LookupFuncWithArgs(objtype, castNode(ObjectWithArgs, object), missing_ok);
930  address.objectSubId = 0;
931  break;
932  case OBJECT_OPERATOR:
933  address.classId = OperatorRelationId;
934  address.objectId = LookupOperWithArgs(castNode(ObjectWithArgs, object), missing_ok);
935  address.objectSubId = 0;
936  break;
937  case OBJECT_COLLATION:
938  address.classId = CollationRelationId;
939  address.objectId = get_collation_oid(castNode(List, object), missing_ok);
940  address.objectSubId = 0;
941  break;
942  case OBJECT_CONVERSION:
943  address.classId = ConversionRelationId;
944  address.objectId = get_conversion_oid(castNode(List, object), missing_ok);
945  address.objectSubId = 0;
946  break;
947  case OBJECT_OPCLASS:
948  case OBJECT_OPFAMILY:
949  address = get_object_address_opcf(objtype, castNode(List, object), missing_ok);
950  break;
951  case OBJECT_AMOP:
952  case OBJECT_AMPROC:
953  address = get_object_address_opf_member(objtype, castNode(List, object), missing_ok);
954  break;
955  case OBJECT_LARGEOBJECT:
956  address.classId = LargeObjectRelationId;
957  address.objectId = oidparse(object);
958  address.objectSubId = 0;
959  if (!LargeObjectExists(address.objectId))
960  {
961  if (!missing_ok)
962  ereport(ERROR,
963  (errcode(ERRCODE_UNDEFINED_OBJECT),
964  errmsg("large object %u does not exist",
965  address.objectId)));
966  }
967  break;
968  case OBJECT_CAST:
969  {
970  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
971  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
972  Oid sourcetypeid;
973  Oid targettypeid;
974 
975  sourcetypeid = LookupTypeNameOid(NULL, sourcetype, missing_ok);
976  targettypeid = LookupTypeNameOid(NULL, targettype, missing_ok);
977  address.classId = CastRelationId;
978  address.objectId =
979  get_cast_oid(sourcetypeid, targettypeid, missing_ok);
980  address.objectSubId = 0;
981  }
982  break;
983  case OBJECT_TRANSFORM:
984  {
985  TypeName *typename = linitial_node(TypeName, castNode(List, object));
986  char *langname = strVal(lsecond(castNode(List, object)));
987  Oid type_id = LookupTypeNameOid(NULL, typename, missing_ok);
988  Oid lang_id = get_language_oid(langname, missing_ok);
989 
990  address.classId = TransformRelationId;
991  address.objectId =
992  get_transform_oid(type_id, lang_id, missing_ok);
993  address.objectSubId = 0;
994  }
995  break;
996  case OBJECT_TSPARSER:
997  address.classId = TSParserRelationId;
998  address.objectId = get_ts_parser_oid(castNode(List, object), missing_ok);
999  address.objectSubId = 0;
1000  break;
1001  case OBJECT_TSDICTIONARY:
1002  address.classId = TSDictionaryRelationId;
1003  address.objectId = get_ts_dict_oid(castNode(List, object), missing_ok);
1004  address.objectSubId = 0;
1005  break;
1006  case OBJECT_TSTEMPLATE:
1007  address.classId = TSTemplateRelationId;
1008  address.objectId = get_ts_template_oid(castNode(List, object), missing_ok);
1009  address.objectSubId = 0;
1010  break;
1012  address.classId = TSConfigRelationId;
1013  address.objectId = get_ts_config_oid(castNode(List, object), missing_ok);
1014  address.objectSubId = 0;
1015  break;
1016  case OBJECT_USER_MAPPING:
1017  address = get_object_address_usermapping(castNode(List, object),
1018  missing_ok);
1019  break;
1022  &relation,
1023  missing_ok);
1024  break;
1025  case OBJECT_DEFACL:
1026  address = get_object_address_defacl(castNode(List, object),
1027  missing_ok);
1028  break;
1029  case OBJECT_STATISTIC_EXT:
1030  address.classId = StatisticExtRelationId;
1031  address.objectId = get_statistics_object_oid(castNode(List, object),
1032  missing_ok);
1033  address.objectSubId = 0;
1034  break;
1035  default:
1036  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1037  /* placate compiler, in case it thinks elog might return */
1038  address.classId = InvalidOid;
1039  address.objectId = InvalidOid;
1040  address.objectSubId = 0;
1041  }
1042 
1043  /*
1044  * If we could not find the supplied object, return without locking.
1045  */
1046  if (!OidIsValid(address.objectId))
1047  {
1048  Assert(missing_ok);
1049  return address;
1050  }
1051 
1052  /*
1053  * If we're retrying, see if we got the same answer as last time. If
1054  * so, we're done; if not, we locked the wrong thing, so give up our
1055  * lock.
1056  */
1057  if (OidIsValid(old_address.classId))
1058  {
1059  if (old_address.classId == address.classId
1060  && old_address.objectId == address.objectId
1061  && old_address.objectSubId == address.objectSubId)
1062  break;
1063  if (old_address.classId != RelationRelationId)
1064  {
1065  if (IsSharedRelation(old_address.classId))
1066  UnlockSharedObject(old_address.classId,
1067  old_address.objectId,
1068  0, lockmode);
1069  else
1070  UnlockDatabaseObject(old_address.classId,
1071  old_address.objectId,
1072  0, lockmode);
1073  }
1074  }
1075 
1076  /*
1077  * If we're dealing with a relation or attribute, then the relation is
1078  * already locked. Otherwise, we lock it now.
1079  */
1080  if (address.classId != RelationRelationId)
1081  {
1082  if (IsSharedRelation(address.classId))
1083  LockSharedObject(address.classId, address.objectId, 0,
1084  lockmode);
1085  else
1086  LockDatabaseObject(address.classId, address.objectId, 0,
1087  lockmode);
1088  }
1089 
1090  /*
1091  * At this point, we've resolved the name to an OID and locked the
1092  * corresponding database object. However, it's possible that by the
1093  * time we acquire the lock on the object, concurrent DDL has modified
1094  * the database in such a way that the name we originally looked up no
1095  * longer resolves to that OID.
1096  *
1097  * We can be certain that this isn't an issue if (a) no shared
1098  * invalidation messages have been processed or (b) we've locked a
1099  * relation somewhere along the line. All the relation name lookups
1100  * in this module ultimately use RangeVarGetRelid() to acquire a
1101  * relation lock, and that function protects against the same kinds of
1102  * races we're worried about here. Even when operating on a
1103  * constraint, rule, or trigger, we still acquire AccessShareLock on
1104  * the relation, which is enough to freeze out any concurrent DDL.
1105  *
1106  * In all other cases, however, it's possible that the name we looked
1107  * up no longer refers to the object we locked, so we retry the lookup
1108  * and see whether we get the same answer.
1109  */
1110  if (inval_count == SharedInvalidMessageCounter || relation != NULL)
1111  break;
1112  old_address = address;
1113  }
1114 
1115  /* Return the object address and the relation. */
1116  *relp = relation;
1117  return address;
1118 }
Oid LookupOperWithArgs(ObjectWithArgs *oper, bool noError)
Definition: parse_oper.c:140
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:594
Oid get_language_oid(const char *langname, bool missing_ok)
Definition: proclang.c:559
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:608
Oid get_ts_config_oid(List *names, bool missing_ok)
Definition: namespace.c:2671
unsigned int Oid
Definition: postgres_ext.h:31
#define linitial_node(type, l)
Definition: pg_list.h:198
static ObjectAddress get_object_address_unqualified(ObjectType objtype, Value *strval, bool missing_ok)
#define OidIsValid(objectId)
Definition: c.h:639
#define lsecond(l)
Definition: pg_list.h:200
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:2418
Oid get_transform_oid(Oid type_id, Oid lang_id, bool missing_ok)
#define ERROR
Definition: elog.h:43
void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1023
Oid get_statistics_object_oid(List *names, bool missing_ok)
Definition: namespace.c:2170
Oid get_ts_template_oid(List *names, bool missing_ok)
Definition: namespace.c:2545
#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:961
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)
#define ereport(elevel, rest)
Definition: elog.h:141
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:982
#define lsecond_node(type, l)
Definition: pg_list.h:203
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:239
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1002
uint64 SharedInvalidMessageCounter
Definition: sinval.c:26
#define InvalidOid
Definition: postgres_ext.h:36
Oid get_ts_parser_oid(List *names, bool missing_ok)
Definition: namespace.c:2292
#define Assert(condition)
Definition: c.h:733
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:3618
bool LargeObjectExists(Oid loid)
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define elog(elevel,...)
Definition: elog.h:228
Oid LookupFuncWithArgs(ObjectType objtype, ObjectWithArgs *func, bool missing_ok)
Definition: parse_func.c:2161
Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok)
Oid get_collation_oid(List *name, bool missing_ok)
Definition: namespace.c:3564
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 1128 of file objectaddress.c.

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

Referenced by ExecAlterObjectDependsStmt().

1131 {
1132  if (rel)
1133  {
1134  object = lcons(makeString(rel->relname), object);
1135  if (rel->schemaname)
1136  object = lcons(makeString(rel->schemaname), object);
1137  if (rel->catalogname)
1138  object = lcons(makeString(rel->catalogname), object);
1139  }
1140 
1141  return get_object_address(objtype, (Node *) object,
1142  relp, lockmode, missing_ok);
1143 }
Value * makeString(char *str)
Definition: value.c:53
Definition: nodes.h:525
char * schemaname
Definition: primnodes.h:67
char * relname
Definition: primnodes.h:68
List * lcons(void *datum, List *list)
Definition: list.c:454
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 2608 of file objectaddress.c.

References ObjectPropertyType::attnum_acl, and get_object_property_data().

Referenced by AlterObjectOwner_internal().

2609 {
2610  const ObjectPropertyType *prop = get_object_property_data(class_id);
2611 
2612  return prop->attnum_acl;
2613 }
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 2584 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().

2585 {
2586  const ObjectPropertyType *prop = get_object_property_data(class_id);
2587 
2588  return prop->attnum_name;
2589 }
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 2592 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().

2593 {
2594  const ObjectPropertyType *prop = get_object_property_data(class_id);
2595 
2596  return prop->attnum_namespace;
2597 }
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 2576 of file objectaddress.c.

References ObjectPropertyType::attnum_oid, and get_object_property_data().

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

2577 {
2578  const ObjectPropertyType *prop = get_object_property_data(class_id);
2579 
2580  return prop->attnum_oid;
2581 }
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 2600 of file objectaddress.c.

References ObjectPropertyType::attnum_owner, and get_object_property_data().

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

2601 {
2602  const ObjectPropertyType *prop = get_object_property_data(class_id);
2603 
2604  return prop->attnum_owner;
2605 }
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 2568 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

2569 {
2570  const ObjectPropertyType *prop = get_object_property_data(class_id);
2571 
2572  return prop->name_catcache_id;
2573 }
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 2560 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_catcache_id.

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

2561 {
2562  const ObjectPropertyType *prop = get_object_property_data(class_id);
2563 
2564  return prop->oid_catcache_id;
2565 }
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 2641 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::is_nsp_name_unique.

Referenced by EventTriggerSQLDropAddObject(), and pg_identify_object().

2642 {
2643  const ObjectPropertyType *prop = get_object_property_data(class_id);
2644 
2645  return prop->is_nsp_name_unique;
2646 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_namespace()

Oid get_object_namespace ( const ObjectAddress address)

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

2494 {
2495  int cache;
2496  HeapTuple tuple;
2497  bool isnull;
2498  Oid oid;
2499  const ObjectPropertyType *property;
2500 
2501  /* If not owned by a namespace, just return InvalidOid. */
2502  property = get_object_property_data(address->classId);
2503  if (property->attnum_namespace == InvalidAttrNumber)
2504  return InvalidOid;
2505 
2506  /* Currently, we can only handle object types with system caches. */
2507  cache = property->oid_catcache_id;
2508  Assert(cache != -1);
2509 
2510  /* Fetch tuple from syscache and extract namespace attribute. */
2511  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2512  if (!HeapTupleIsValid(tuple))
2513  elog(ERROR, "cache lookup failed for cache %d oid %u",
2514  cache, address->objectId);
2515  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2516  tuple,
2517  property->attnum_namespace,
2518  &isnull));
2519  Assert(!isnull);
2520  ReleaseSysCache(tuple);
2521 
2522  return oid;
2523 }
#define DatumGetObjectId(X)
Definition: postgres.h:500
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
static const ObjectPropertyType * get_object_property_data(Oid class_id)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1377
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:733
AttrNumber attnum_namespace
#define InvalidAttrNumber
Definition: attnum.h:23
#define elog(elevel,...)
Definition: elog.h:228

◆ get_object_oid_index()

Oid get_object_oid_index ( Oid  class_id)

Definition at line 2552 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by get_catalog_object_by_oid().

2553 {
2554  const ObjectPropertyType *prop = get_object_property_data(class_id);
2555 
2556  return prop->oid_index_oid;
2557 }
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 2623 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().

2624 {
2625  const ObjectPropertyType *prop = get_object_property_data(class_id);
2626 
2627  if (prop->objtype == OBJECT_TABLE)
2628  {
2629  /*
2630  * If the property data says it's a table, dig a little deeper to get
2631  * the real relation kind, so that callers can produce more precise
2632  * error messages.
2633  */
2634  return get_relkind_objtype(get_rel_relkind(object_id));
2635  }
2636  else
2637  return prop->objtype;
2638 }
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1805
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 5354 of file objectaddress.c.

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

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

5355 {
5356  switch (relkind)
5357  {
5358  case RELKIND_RELATION:
5359  case RELKIND_PARTITIONED_TABLE:
5360  return OBJECT_TABLE;
5361  case RELKIND_INDEX:
5362  case RELKIND_PARTITIONED_INDEX:
5363  return OBJECT_INDEX;
5364  case RELKIND_SEQUENCE:
5365  return OBJECT_SEQUENCE;
5366  case RELKIND_VIEW:
5367  return OBJECT_VIEW;
5368  case RELKIND_MATVIEW:
5369  return OBJECT_MATVIEW;
5370  case RELKIND_FOREIGN_TABLE:
5371  return OBJECT_FOREIGN_TABLE;
5372  case RELKIND_TOASTVALUE:
5373  return OBJECT_TABLE;
5374  default:
5375  /* Per above, don't raise an error */
5376  return OBJECT_TABLE;
5377  }
5378 }
char relkind
Definition: pg_class.h:81

◆ getObjectDescription()

char* getObjectDescription ( const ObjectAddress object)

Definition at line 2752 of file objectaddress.c.

References _, AccessMethodOperatorOidIndexId, AccessMethodProcedureOidIndexId, AccessShareLock, AMOID, appendStringInfo(), Assert, AttrDefaultOidIndexId, BTEqualStrategyNumber, CastOidIndexId, CLAOID, ObjectAddress::classId, CollationIsVisible(), COLLOID, CONSTROID, ConversionIsVisible(), CONVOID, StringInfoData::data, datname, DefaultAclOidIndexId, elog, ERROR, EVENTTRIGGEROID, ForeignDataWrapper::fdwname, format_operator(), format_procedure(), format_type_be(), get_attname(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name(), get_publication_name(), get_subscription_name(), get_tablespace_name(), GetForeignDataWrapper(), GetForeignServer(), getObjectClass(), getObjectDescription(), getOpFamilyDescription(), getRelationDescription(), GETSTRUCT, GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), NameStr, ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, OCLASS_AM, OCLASS_AMOP, OCLASS_AMPROC, OCLASS_CAST, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONSTRAINT, OCLASS_CONVERSION, OCLASS_DATABASE, OCLASS_DEFACL, OCLASS_DEFAULT, OCLASS_EVENT_TRIGGER, OCLASS_EXTENSION, OCLASS_FDW, OCLASS_FOREIGN_SERVER, OCLASS_LANGUAGE, OCLASS_LARGEOBJECT, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, OCLASS_SCHEMA, OCLASS_STATISTIC_EXT, OCLASS_SUBSCRIPTION, OCLASS_TBLSPACE, OCLASS_TRANSFORM, OCLASS_TRIGGER, OCLASS_TSCONFIG, OCLASS_TSDICT, OCLASS_TSPARSER, OCLASS_TSTEMPLATE, OCLASS_TYPE, OCLASS_USER_MAPPING, OidIsValid, OpclassIsVisible(), pfree(), PolicyOidIndexId, PUBLICATIONREL, quote_qualified_identifier(), ReleaseSysCache(), RewriteOidIndexId, ScanKeyInit(), SearchSysCache1(), ForeignServer::servername, STATEXTOID, StatisticsObjIsVisible(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TRFOID, TriggerOidIndexId, TSConfigIsVisible(), TSCONFIGOID, TSDictionaryIsVisible(), TSDICTOID, TSParserIsVisible(), TSPARSEROID, TSTemplateIsVisible(), TSTEMPLATEOID, and USERMAPPINGOID.

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

2753 {
2754  StringInfoData buffer;
2755 
2756  initStringInfo(&buffer);
2757 
2758  switch (getObjectClass(object))
2759  {
2760  case OCLASS_CLASS:
2761  if (object->objectSubId == 0)
2762  getRelationDescription(&buffer, object->objectId);
2763  else
2764  {
2765  /* column, not whole relation */
2766  StringInfoData rel;
2767 
2768  initStringInfo(&rel);
2769  getRelationDescription(&rel, object->objectId);
2770  /* translator: second %s is, e.g., "table %s" */
2771  appendStringInfo(&buffer, _("column %s of %s"),
2772  get_attname(object->objectId,
2773  object->objectSubId,
2774  false),
2775  rel.data);
2776  pfree(rel.data);
2777  }
2778  break;
2779 
2780  case OCLASS_PROC:
2781  appendStringInfo(&buffer, _("function %s"),
2782  format_procedure(object->objectId));
2783  break;
2784 
2785  case OCLASS_TYPE:
2786  appendStringInfo(&buffer, _("type %s"),
2787  format_type_be(object->objectId));
2788  break;
2789 
2790  case OCLASS_CAST:
2791  {
2792  Relation castDesc;
2793  ScanKeyData skey[1];
2794  SysScanDesc rcscan;
2795  HeapTuple tup;
2796  Form_pg_cast castForm;
2797 
2798  castDesc = table_open(CastRelationId, AccessShareLock);
2799 
2800  ScanKeyInit(&skey[0],
2801  Anum_pg_cast_oid,
2802  BTEqualStrategyNumber, F_OIDEQ,
2803  ObjectIdGetDatum(object->objectId));
2804 
2805  rcscan = systable_beginscan(castDesc, CastOidIndexId, true,
2806  NULL, 1, skey);
2807 
2808  tup = systable_getnext(rcscan);
2809 
2810  if (!HeapTupleIsValid(tup))
2811  elog(ERROR, "could not find tuple for cast %u",
2812  object->objectId);
2813 
2814  castForm = (Form_pg_cast) GETSTRUCT(tup);
2815 
2816  appendStringInfo(&buffer, _("cast from %s to %s"),
2817  format_type_be(castForm->castsource),
2818  format_type_be(castForm->casttarget));
2819 
2820  systable_endscan(rcscan);
2821  table_close(castDesc, AccessShareLock);
2822  break;
2823  }
2824 
2825  case OCLASS_COLLATION:
2826  {
2827  HeapTuple collTup;
2828  Form_pg_collation coll;
2829  char *nspname;
2830 
2831  collTup = SearchSysCache1(COLLOID,
2832  ObjectIdGetDatum(object->objectId));
2833  if (!HeapTupleIsValid(collTup))
2834  elog(ERROR, "cache lookup failed for collation %u",
2835  object->objectId);
2836  coll = (Form_pg_collation) GETSTRUCT(collTup);
2837 
2838  /* Qualify the name if not visible in search path */
2839  if (CollationIsVisible(object->objectId))
2840  nspname = NULL;
2841  else
2842  nspname = get_namespace_name(coll->collnamespace);
2843 
2844  appendStringInfo(&buffer, _("collation %s"),
2846  NameStr(coll->collname)));
2847  ReleaseSysCache(collTup);
2848  break;
2849  }
2850 
2851  case OCLASS_CONSTRAINT:
2852  {
2853  HeapTuple conTup;
2854  Form_pg_constraint con;
2855 
2856  conTup = SearchSysCache1(CONSTROID,
2857  ObjectIdGetDatum(object->objectId));
2858  if (!HeapTupleIsValid(conTup))
2859  elog(ERROR, "cache lookup failed for constraint %u",
2860  object->objectId);
2861  con = (Form_pg_constraint) GETSTRUCT(conTup);
2862 
2863  if (OidIsValid(con->conrelid))
2864  {
2865  StringInfoData rel;
2866 
2867  initStringInfo(&rel);
2868  getRelationDescription(&rel, con->conrelid);
2869  /* translator: second %s is, e.g., "table %s" */
2870  appendStringInfo(&buffer, _("constraint %s on %s"),
2871  NameStr(con->conname), rel.data);
2872  pfree(rel.data);
2873  }
2874  else
2875  {
2876  appendStringInfo(&buffer, _("constraint %s"),
2877  NameStr(con->conname));
2878  }
2879 
2880  ReleaseSysCache(conTup);
2881  break;
2882  }
2883 
2884  case OCLASS_CONVERSION:
2885  {
2886  HeapTuple conTup;
2887  Form_pg_conversion conv;
2888  char *nspname;
2889 
2890  conTup = SearchSysCache1(CONVOID,
2891  ObjectIdGetDatum(object->objectId));
2892  if (!HeapTupleIsValid(conTup))
2893  elog(ERROR, "cache lookup failed for conversion %u",
2894  object->objectId);
2895  conv = (Form_pg_conversion) GETSTRUCT(conTup);
2896 
2897  /* Qualify the name if not visible in search path */
2898  if (ConversionIsVisible(object->objectId))
2899  nspname = NULL;
2900  else
2901  nspname = get_namespace_name(conv->connamespace);
2902 
2903  appendStringInfo(&buffer, _("conversion %s"),
2905  NameStr(conv->conname)));
2906  ReleaseSysCache(conTup);
2907  break;
2908  }
2909 
2910  case OCLASS_DEFAULT:
2911  {
2912  Relation attrdefDesc;
2913  ScanKeyData skey[1];
2914  SysScanDesc adscan;
2915  HeapTuple tup;
2916  Form_pg_attrdef attrdef;
2917  ObjectAddress colobject;
2918 
2919  attrdefDesc = table_open(AttrDefaultRelationId, AccessShareLock);
2920 
2921  ScanKeyInit(&skey[0],
2922  Anum_pg_attrdef_oid,
2923  BTEqualStrategyNumber, F_OIDEQ,
2924  ObjectIdGetDatum(object->objectId));
2925 
2926  adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndexId,
2927  true, NULL, 1, skey);
2928 
2929  tup = systable_getnext(adscan);
2930 
2931  if (!HeapTupleIsValid(tup))
2932  elog(ERROR, "could not find tuple for attrdef %u",
2933  object->objectId);
2934 
2935  attrdef = (Form_pg_attrdef) GETSTRUCT(tup);
2936 
2937  colobject.classId = RelationRelationId;
2938  colobject.objectId = attrdef->adrelid;
2939  colobject.objectSubId = attrdef->adnum;
2940 
2941  /* translator: %s is typically "column %s of table %s" */
2942  appendStringInfo(&buffer, _("default value for %s"),
2943  getObjectDescription(&colobject));
2944 
2945  systable_endscan(adscan);
2946  table_close(attrdefDesc, AccessShareLock);
2947  break;
2948  }
2949 
2950  case OCLASS_LANGUAGE:
2951  appendStringInfo(&buffer, _("language %s"),
2952  get_language_name(object->objectId, false));
2953  break;
2954 
2955  case OCLASS_LARGEOBJECT:
2956  appendStringInfo(&buffer, _("large object %u"),
2957  object->objectId);
2958  break;
2959 
2960  case OCLASS_OPERATOR:
2961  appendStringInfo(&buffer, _("operator %s"),
2962  format_operator(object->objectId));
2963  break;
2964 
2965  case OCLASS_OPCLASS:
2966  {
2967  HeapTuple opcTup;
2968  Form_pg_opclass opcForm;
2969  HeapTuple amTup;
2970  Form_pg_am amForm;
2971  char *nspname;
2972 
2973  opcTup = SearchSysCache1(CLAOID,
2974  ObjectIdGetDatum(object->objectId));
2975  if (!HeapTupleIsValid(opcTup))
2976  elog(ERROR, "cache lookup failed for opclass %u",
2977  object->objectId);
2978  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
2979 
2980  amTup = SearchSysCache1(AMOID,
2981  ObjectIdGetDatum(opcForm->opcmethod));
2982  if (!HeapTupleIsValid(amTup))
2983  elog(ERROR, "cache lookup failed for access method %u",
2984  opcForm->opcmethod);
2985  amForm = (Form_pg_am) GETSTRUCT(amTup);
2986 
2987  /* Qualify the name if not visible in search path */
2988  if (OpclassIsVisible(object->objectId))
2989  nspname = NULL;
2990  else
2991  nspname = get_namespace_name(opcForm->opcnamespace);
2992 
2993  appendStringInfo(&buffer, _("operator class %s for access method %s"),
2995  NameStr(opcForm->opcname)),
2996  NameStr(amForm->amname));
2997 
2998  ReleaseSysCache(amTup);
2999  ReleaseSysCache(opcTup);
3000  break;
3001  }
3002 
3003  case OCLASS_OPFAMILY:
3004  getOpFamilyDescription(&buffer, object->objectId);
3005  break;
3006 
3007  case OCLASS_AM:
3008  {
3009  HeapTuple tup;
3010 
3011  tup = SearchSysCache1(AMOID,
3012  ObjectIdGetDatum(object->objectId));
3013  if (!HeapTupleIsValid(tup))
3014  elog(ERROR, "cache lookup failed for access method %u",
3015  object->objectId);
3016  appendStringInfo(&buffer, _("access method %s"),
3017  NameStr(((Form_pg_am) GETSTRUCT(tup))->amname));
3018  ReleaseSysCache(tup);
3019  break;
3020  }
3021 
3022  case OCLASS_AMOP:
3023  {
3024  Relation amopDesc;
3025  HeapTuple tup;
3026  ScanKeyData skey[1];
3027  SysScanDesc amscan;
3028  Form_pg_amop amopForm;
3029  StringInfoData opfam;
3030 
3031  amopDesc = table_open(AccessMethodOperatorRelationId,
3032  AccessShareLock);
3033 
3034  ScanKeyInit(&skey[0],
3035  Anum_pg_amop_oid,
3036  BTEqualStrategyNumber, F_OIDEQ,
3037  ObjectIdGetDatum(object->objectId));
3038 
3039  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
3040  NULL, 1, skey);
3041 
3042  tup = systable_getnext(amscan);
3043 
3044  if (!HeapTupleIsValid(tup))
3045  elog(ERROR, "could not find tuple for amop entry %u",
3046  object->objectId);
3047 
3048  amopForm = (Form_pg_amop) GETSTRUCT(tup);
3049 
3050  initStringInfo(&opfam);
3051  getOpFamilyDescription(&opfam, amopForm->amopfamily);
3052 
3053  /*------
3054  translator: %d is the operator strategy (a number), the
3055  first two %s's are data type names, the third %s is the
3056  description of the operator family, and the last %s is the
3057  textual form of the operator with arguments. */
3058  appendStringInfo(&buffer, _("operator %d (%s, %s) of %s: %s"),
3059  amopForm->amopstrategy,
3060  format_type_be(amopForm->amoplefttype),
3061  format_type_be(amopForm->amoprighttype),
3062  opfam.data,
3063  format_operator(amopForm->amopopr));
3064 
3065  pfree(opfam.data);
3066 
3067  systable_endscan(amscan);
3068  table_close(amopDesc, AccessShareLock);
3069  break;
3070  }
3071 
3072  case OCLASS_AMPROC:
3073  {
3074  Relation amprocDesc;
3075  ScanKeyData skey[1];
3076  SysScanDesc amscan;
3077  HeapTuple tup;
3078  Form_pg_amproc amprocForm;
3079  StringInfoData opfam;
3080 
3081  amprocDesc = table_open(AccessMethodProcedureRelationId,
3082  AccessShareLock);
3083 
3084  ScanKeyInit(&skey[0],
3085  Anum_pg_amproc_oid,
3086  BTEqualStrategyNumber, F_OIDEQ,
3087  ObjectIdGetDatum(object->objectId));
3088 
3089  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
3090  NULL, 1, skey);
3091 
3092  tup = systable_getnext(amscan);
3093 
3094  if (!HeapTupleIsValid(tup))
3095  elog(ERROR, "could not find tuple for amproc entry %u",
3096  object->objectId);
3097 
3098  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
3099 
3100  initStringInfo(&opfam);
3101  getOpFamilyDescription(&opfam, amprocForm->amprocfamily);
3102 
3103  /*------
3104  translator: %d is the function number, the first two %s's
3105  are data type names, the third %s is the description of the
3106  operator family, and the last %s is the textual form of the
3107  function with arguments. */
3108  appendStringInfo(&buffer, _("function %d (%s, %s) of %s: %s"),
3109  amprocForm->amprocnum,
3110  format_type_be(amprocForm->amproclefttype),
3111  format_type_be(amprocForm->amprocrighttype),
3112  opfam.data,
3113  format_procedure(amprocForm->amproc));
3114 
3115  pfree(opfam.data);
3116 
3117  systable_endscan(amscan);
3118  table_close(amprocDesc, AccessShareLock);
3119  break;
3120  }
3121 
3122  case OCLASS_REWRITE:
3123  {
3124  Relation ruleDesc;
3125  ScanKeyData skey[1];
3126  SysScanDesc rcscan;
3127  HeapTuple tup;
3129  StringInfoData rel;
3130 
3131  ruleDesc = table_open(RewriteRelationId, AccessShareLock);
3132 
3133  ScanKeyInit(&skey[0],
3134  Anum_pg_rewrite_oid,
3135  BTEqualStrategyNumber, F_OIDEQ,
3136  ObjectIdGetDatum(object->objectId));
3137 
3138  rcscan = systable_beginscan(ruleDesc, RewriteOidIndexId, true,
3139  NULL, 1, skey);
3140 
3141  tup = systable_getnext(rcscan);
3142 
3143  if (!HeapTupleIsValid(tup))
3144  elog(ERROR, "could not find tuple for rule %u",
3145  object->objectId);
3146  rule = (Form_pg_rewrite) GETSTRUCT(tup);
3147 
3148  initStringInfo(&rel);
3149  getRelationDescription(&rel, rule->ev_class);
3150 
3151  /* translator: second %s is, e.g., "table %s" */
3152  appendStringInfo(&buffer, _("rule %s on %s"),
3153  NameStr(rule->rulename), rel.data);
3154  pfree(rel.data);
3155  systable_endscan(rcscan);
3156  table_close(ruleDesc, AccessShareLock);
3157  break;
3158  }
3159 
3160  case OCLASS_TRIGGER:
3161  {
3162  Relation trigDesc;
3163  ScanKeyData skey[1];
3164  SysScanDesc tgscan;
3165  HeapTuple tup;
3166  Form_pg_trigger trig;
3167  StringInfoData rel;
3168 
3169  trigDesc = table_open(TriggerRelationId, AccessShareLock);
3170 
3171  ScanKeyInit(&skey[0],
3172  Anum_pg_trigger_oid,
3173  BTEqualStrategyNumber, F_OIDEQ,
3174  ObjectIdGetDatum(object->objectId));
3175 
3176  tgscan = systable_beginscan(trigDesc, TriggerOidIndexId, true,
3177  NULL, 1, skey);
3178 
3179  tup = systable_getnext(tgscan);
3180 
3181  if (!HeapTupleIsValid(tup))
3182  elog(ERROR, "could not find tuple for trigger %u",
3183  object->objectId);
3184  trig = (Form_pg_trigger) GETSTRUCT(tup);
3185 
3186  initStringInfo(&rel);
3187  getRelationDescription(&rel, trig->tgrelid);
3188 
3189  /* translator: second %s is, e.g., "table %s" */
3190  appendStringInfo(&buffer, _("trigger %s on %s"),
3191  NameStr(trig->tgname), rel.data);
3192  pfree(rel.data);
3193  systable_endscan(tgscan);
3194  table_close(trigDesc, AccessShareLock);
3195  break;
3196  }
3197 
3198  case OCLASS_SCHEMA:
3199  {
3200  char *nspname;
3201 
3202  nspname = get_namespace_name(object->objectId);
3203  if (!nspname)
3204  elog(ERROR, "cache lookup failed for namespace %u",
3205  object->objectId);
3206  appendStringInfo(&buffer, _("schema %s"), nspname);
3207  break;
3208  }
3209 
3210  case OCLASS_STATISTIC_EXT:
3211  {
3212  HeapTuple stxTup;
3213  Form_pg_statistic_ext stxForm;
3214  char *nspname;
3215 
3216  stxTup = SearchSysCache1(STATEXTOID,
3217  ObjectIdGetDatum(object->objectId));
3218  if (!HeapTupleIsValid(stxTup))
3219  elog(ERROR, "could not find tuple for statistics object %u",
3220  object->objectId);
3221  stxForm = (Form_pg_statistic_ext) GETSTRUCT(stxTup);
3222 
3223  /* Qualify the name if not visible in search path */
3224  if (StatisticsObjIsVisible(object->objectId))
3225  nspname = NULL;
3226  else
3227  nspname = get_namespace_name(stxForm->stxnamespace);
3228 
3229  appendStringInfo(&buffer, _("statistics object %s"),
3231  NameStr(stxForm->stxname)));
3232 
3233  ReleaseSysCache(stxTup);
3234  break;
3235  }
3236 
3237  case OCLASS_TSPARSER:
3238  {
3239  HeapTuple tup;
3240  Form_pg_ts_parser prsForm;
3241  char *nspname;
3242 
3244  ObjectIdGetDatum(object->objectId));
3245  if (!HeapTupleIsValid(tup))
3246  elog(ERROR, "cache lookup failed for text search parser %u",
3247  object->objectId);
3248  prsForm = (Form_pg_ts_parser) GETSTRUCT(tup);
3249 
3250  /* Qualify the name if not visible in search path */
3251  if (TSParserIsVisible(object->objectId))
3252  nspname = NULL;
3253  else
3254  nspname = get_namespace_name(prsForm->prsnamespace);
3255 
3256  appendStringInfo(&buffer, _("text search parser %s"),
3258  NameStr(prsForm->prsname)));
3259  ReleaseSysCache(tup);
3260  break;
3261  }
3262 
3263  case OCLASS_TSDICT:
3264  {
3265  HeapTuple tup;
3266  Form_pg_ts_dict dictForm;
3267  char *nspname;
3268 
3269  tup = SearchSysCache1(TSDICTOID,
3270  ObjectIdGetDatum(object->objectId));
3271  if (!HeapTupleIsValid(tup))
3272  elog(ERROR, "cache lookup failed for text search dictionary %u",
3273  object->objectId);
3274  dictForm = (Form_pg_ts_dict) GETSTRUCT(tup);
3275 
3276  /* Qualify the name if not visible in search path */
3277  if (TSDictionaryIsVisible(object->objectId))
3278  nspname = NULL;
3279  else
3280  nspname = get_namespace_name(dictForm->dictnamespace);
3281 
3282  appendStringInfo(&buffer, _("text search dictionary %s"),
3284  NameStr(dictForm->dictname)));
3285  ReleaseSysCache(tup);
3286  break;
3287  }
3288 
3289  case OCLASS_TSTEMPLATE:
3290  {
3291  HeapTuple tup;
3292  Form_pg_ts_template tmplForm;
3293  char *nspname;
3294 
3296  ObjectIdGetDatum(object->objectId));
3297  if (!HeapTupleIsValid(tup))
3298  elog(ERROR, "cache lookup failed for text search template %u",
3299  object->objectId);
3300  tmplForm = (Form_pg_ts_template) GETSTRUCT(tup);
3301 
3302  /* Qualify the name if not visible in search path */
3303  if (TSTemplateIsVisible(object->objectId))
3304  nspname = NULL;
3305  else
3306  nspname = get_namespace_name(tmplForm->tmplnamespace);
3307 
3308  appendStringInfo(&buffer, _("text search template %s"),
3310  NameStr(tmplForm->tmplname)));
3311  ReleaseSysCache(tup);
3312  break;
3313  }
3314 
3315  case OCLASS_TSCONFIG:
3316  {
3317  HeapTuple tup;
3318  Form_pg_ts_config cfgForm;
3319  char *nspname;
3320 
3322  ObjectIdGetDatum(object->objectId));
3323  if (!HeapTupleIsValid(tup))
3324  elog(ERROR, "cache lookup failed for text search configuration %u",
3325  object->objectId);
3326  cfgForm = (Form_pg_ts_config) GETSTRUCT(tup);
3327 
3328  /* Qualify the name if not visible in search path */
3329  if (TSConfigIsVisible(object->objectId))
3330  nspname = NULL;
3331  else
3332  nspname = get_namespace_name(cfgForm->cfgnamespace);
3333 
3334  appendStringInfo(&buffer, _("text search configuration %s"),
3336  NameStr(cfgForm->cfgname)));
3337  ReleaseSysCache(tup);
3338  break;
3339  }
3340 
3341  case OCLASS_ROLE:
3342  {
3343  appendStringInfo(&buffer, _("role %s"),
3344  GetUserNameFromId(object->objectId, false));
3345  break;
3346  }
3347 
3348  case OCLASS_DATABASE:
3349  {
3350  char *datname;
3351 
3352  datname = get_database_name(object->objectId);
3353  if (!datname)
3354  elog(ERROR, "cache lookup failed for database %u",
3355  object->objectId);
3356  appendStringInfo(&buffer, _("database %s"), datname);
3357  break;
3358  }
3359 
3360  case OCLASS_TBLSPACE:
3361  {
3362  char *tblspace;
3363 
3364  tblspace = get_tablespace_name(object->objectId);
3365  if (!tblspace)
3366  elog(ERROR, "cache lookup failed for tablespace %u",
3367  object->objectId);
3368  appendStringInfo(&buffer, _("tablespace %s"), tblspace);
3369  break;
3370  }
3371 
3372  case OCLASS_FDW:
3373  {
3374  ForeignDataWrapper *fdw;
3375 
3376  fdw = GetForeignDataWrapper(object->objectId);
3377  appendStringInfo(&buffer, _("foreign-data wrapper %s"), fdw->fdwname);
3378  break;
3379  }
3380 
3381  case OCLASS_FOREIGN_SERVER:
3382  {
3383  ForeignServer *srv;
3384 
3385  srv = GetForeignServer(object->objectId);
3386  appendStringInfo(&buffer, _("server %s"), srv->servername);
3387  break;
3388  }
3389 
3390  case OCLASS_USER_MAPPING:
3391  {
3392  HeapTuple tup;
3393  Oid useid;
3394  char *usename;
3395  Form_pg_user_mapping umform;
3396  ForeignServer *srv;
3397 
3399  ObjectIdGetDatum(object->objectId));
3400  if (!HeapTupleIsValid(tup))
3401  elog(ERROR, "cache lookup failed for user mapping %u",
3402  object->objectId);
3403  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
3404  useid = umform->umuser;
3405  srv = GetForeignServer(umform->umserver);
3406 
3407  ReleaseSysCache(tup);
3408 
3409  if (OidIsValid(useid))
3410  usename = GetUserNameFromId(useid, false);
3411  else
3412  usename = "public";
3413 
3414  appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
3415  srv->servername);
3416  break;
3417  }
3418 
3419  case OCLASS_DEFACL:
3420  {
3421  Relation defaclrel;
3422  ScanKeyData skey[1];
3423  SysScanDesc rcscan;
3424  HeapTuple tup;
3425  Form_pg_default_acl defacl;
3426  char *rolename;
3427  char *nspname;
3428 
3429  defaclrel = table_open(DefaultAclRelationId, AccessShareLock);
3430 
3431  ScanKeyInit(&skey[0],
3432  Anum_pg_default_acl_oid,
3433  BTEqualStrategyNumber, F_OIDEQ,
3434  ObjectIdGetDatum(object->objectId));
3435 
3436  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
3437  true, NULL, 1, skey);
3438 
3439  tup = systable_getnext(rcscan);
3440 
3441  if (!HeapTupleIsValid(tup))
3442  elog(ERROR, "could not find tuple for default ACL %u",
3443  object->objectId);
3444 
3445  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
3446 
3447  rolename = GetUserNameFromId(defacl->defaclrole, false);
3448 
3449  if (OidIsValid(defacl->defaclnamespace))
3450  nspname = get_namespace_name(defacl->defaclnamespace);
3451  else
3452  nspname = NULL;
3453 
3454  switch (defacl->defaclobjtype)
3455  {
3456  case DEFACLOBJ_RELATION:
3457  if (nspname)
3458  appendStringInfo(&buffer,
3459  _("default privileges on new relations belonging to role %s in schema %s"),
3460  rolename, nspname);
3461  else
3462  appendStringInfo(&buffer,
3463  _("default privileges on new relations belonging to role %s"),
3464  rolename);
3465  break;
3466  case DEFACLOBJ_SEQUENCE:
3467  if (nspname)
3468  appendStringInfo(&buffer,
3469  _("default privileges on new sequences belonging to role %s in schema %s"),
3470  rolename, nspname);
3471  else
3472  appendStringInfo(&buffer,
3473  _("default privileges on new sequences belonging to role %s"),
3474  rolename);
3475  break;
3476  case DEFACLOBJ_FUNCTION:
3477  if (nspname)
3478  appendStringInfo(&buffer,
3479  _("default privileges on new functions belonging to role %s in schema %s"),
3480  rolename, nspname);
3481  else
3482  appendStringInfo(&buffer,
3483  _("default privileges on new functions belonging to role %s"),
3484  rolename);
3485  break;
3486  case DEFACLOBJ_TYPE:
3487  if (nspname)
3488  appendStringInfo(&buffer,
3489  _("default privileges on new types belonging to role %s in schema %s"),
3490  rolename, nspname);
3491  else
3492  appendStringInfo(&buffer,
3493  _("default privileges on new types belonging to role %s"),
3494  rolename);
3495  break;
3496  case DEFACLOBJ_NAMESPACE:
3497  Assert(!nspname);
3498  appendStringInfo(&buffer,
3499  _("default privileges on new schemas belonging to role %s"),
3500  rolename);
3501  break;
3502  default:
3503  /* shouldn't get here */
3504  if (nspname)
3505  appendStringInfo(&buffer,
3506  _("default privileges belonging to role %s in schema %s"),
3507  rolename, nspname);
3508  else
3509  appendStringInfo(&buffer,
3510  _("default privileges belonging to role %s"),
3511  rolename);
3512  break;
3513  }
3514 
3515  systable_endscan(rcscan);
3516  table_close(defaclrel, AccessShareLock);
3517  break;
3518  }
3519 
3520  case OCLASS_EXTENSION:
3521  {
3522  char *extname;
3523 
3524  extname = get_extension_name(object->objectId);
3525  if (!extname)
3526  elog(ERROR, "cache lookup failed for extension %u",
3527  object->objectId);
3528  appendStringInfo(&buffer, _("extension %s"), extname);
3529  break;
3530  }
3531 
3532  case OCLASS_EVENT_TRIGGER:
3533  {
3534  HeapTuple tup;
3535 
3537  ObjectIdGetDatum(object->objectId));
3538  if (!HeapTupleIsValid(tup))
3539  elog(ERROR, "cache lookup failed for event trigger %u",
3540  object->objectId);
3541  appendStringInfo(&buffer, _("event trigger %s"),
3542  NameStr(((Form_pg_event_trigger) GETSTRUCT(tup))->evtname));
3543  ReleaseSysCache(tup);
3544  break;
3545  }
3546 
3547  case OCLASS_POLICY:
3548  {
3549  Relation policy_rel;
3550  ScanKeyData skey[1];
3551  SysScanDesc sscan;
3552  HeapTuple tuple;
3553  Form_pg_policy form_policy;
3554  StringInfoData rel;
3555 
3556  policy_rel = table_open(PolicyRelationId, AccessShareLock);
3557 
3558  ScanKeyInit(&skey[0],
3559  Anum_pg_policy_oid,
3560  BTEqualStrategyNumber, F_OIDEQ,
3561  ObjectIdGetDatum(object->objectId));
3562 
3563  sscan = systable_beginscan(policy_rel, PolicyOidIndexId,
3564  true, NULL, 1, skey);
3565 
3566  tuple = systable_getnext(sscan);
3567 
3568  if (!HeapTupleIsValid(tuple))
3569  elog(ERROR, "could not find tuple for policy %u",
3570  object->objectId);
3571  form_policy = (Form_pg_policy) GETSTRUCT(tuple);
3572 
3573  initStringInfo(&rel);
3574  getRelationDescription(&rel, form_policy->polrelid);
3575 
3576  /* translator: second %s is, e.g., "table %s" */
3577  appendStringInfo(&buffer, _("policy %s on %s"),
3578  NameStr(form_policy->polname), rel.data);
3579  pfree(rel.data);
3580  systable_endscan(sscan);
3581  table_close(policy_rel, AccessShareLock);
3582  break;
3583  }
3584 
3585  case OCLASS_PUBLICATION:
3586  {
3587  appendStringInfo(&buffer, _("publication %s"),
3589  false));
3590  break;
3591  }
3592 
3594  {
3595  HeapTuple tup;
3596  char *pubname;
3597  Form_pg_publication_rel prform;
3598  StringInfoData rel;
3599 
3601  ObjectIdGetDatum(object->objectId));
3602  if (!HeapTupleIsValid(tup))
3603  elog(ERROR, "cache lookup failed for publication table %u",
3604  object->objectId);
3605 
3606  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
3607  pubname = get_publication_name(prform->prpubid, false);
3608 
3609  initStringInfo(&rel);
3610  getRelationDescription(&rel, prform->prrelid);
3611 
3612  /* translator: first %s is, e.g., "table %s" */
3613  appendStringInfo(&buffer, _("publication of %s in publication %s"),
3614  rel.data, pubname);
3615  pfree(rel.data);
3616  ReleaseSysCache(tup);
3617  break;
3618  }
3619 
3620  case OCLASS_SUBSCRIPTION:
3621  {
3622  appendStringInfo(&buffer, _("subscription %s"),
3624  false));
3625  break;
3626  }
3627 
3628  case OCLASS_TRANSFORM:
3629  {
3630  HeapTuple trfTup;
3631  Form_pg_transform trfForm;
3632 
3633  trfTup = SearchSysCache1(TRFOID,
3634  ObjectIdGetDatum(object->objectId));
3635  if (!HeapTupleIsValid(trfTup))
3636  elog(ERROR, "could not find tuple for transform %u",
3637  object->objectId);
3638 
3639  trfForm = (Form_pg_transform) GETSTRUCT(trfTup);
3640 
3641  appendStringInfo(&buffer, _("transform for %s language %s"),
3642  format_type_be(trfForm->trftype),
3643  get_language_name(trfForm->trflang, false));
3644 
3645  ReleaseSysCache(trfTup);
3646  break;
3647  }
3648 
3649  /*
3650  * There's intentionally no default: case here; we want the
3651  * compiler to warn if a new OCLASS hasn't been handled above.
3652  */
3653  }
3654 
3655  return buffer.data;
3656 }
#define RewriteOidIndexId
Definition: indexing.h:218
#define TriggerOidIndexId
Definition: indexing.h:258
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:525
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
Definition: syscache.h:36
char * get_language_name(Oid langoid, bool missing_ok)
Definition: lsyscache.c:990
FormData_pg_ts_config * Form_pg_ts_config
Definition: pg_ts_config.h:48
char * fdwname
Definition: foreign.h:28
#define PolicyOidIndexId
Definition: indexing.h:334
FormData_pg_amproc * Form_pg_amproc
Definition: pg_amproc.h:68
char * get_extension_name(Oid ext_oid)
Definition: extension.c:183
#define DefaultAclOidIndexId
Definition: indexing.h:314
#define AccessShareLock
Definition: lockdefs.h:36
bool StatisticsObjIsVisible(Oid relid)
Definition: namespace.c:2227
static void getOpFamilyDescription(StringInfo buffer, Oid opfid)
#define AttrDefaultOidIndexId
Definition: indexing.h:91
#define AccessMethodOperatorOidIndexId
Definition: indexing.h:81
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
NameData datname
Definition: pg_database.h:35
char * format_operator(Oid operator_oid)
Definition: regproc.c:820
unsigned int Oid
Definition: postgres_ext.h:31
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2712
#define OidIsValid(objectId)
Definition: c.h:639
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:352
char * get_publication_name(Oid pubid, bool missing_ok)
char * getObjectDescription(const ObjectAddress *object)
Definition: localtime.c:79
char * get_subscription_name(Oid subid, bool missing_ok)
#define AccessMethodProcedureOidIndexId
Definition: indexing.h:86
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:444
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
Definition: foreign.c:35
void pfree(void *pointer)
Definition: mcxt.c:1056
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
FormData_pg_transform * Form_pg_transform
Definition: pg_transform.h:43
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
bool TSConfigIsVisible(Oid cfgid)
Definition: namespace.c:2729
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2155
FormData_pg_user_mapping * Form_pg_user_mapping
FormData_pg_ts_dict * Form_pg_ts_dict
Definition: pg_ts_dict.h:52
FormData_pg_default_acl * Form_pg_default_acl
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3094
#define CastOidIndexId
Definition: indexing.h:109
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2040
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:56
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
FormData_pg_attrdef * Form_pg_attrdef
Definition: pg_attrdef.h:47
bool TSDictionaryIsVisible(Oid dictId)
Definition: namespace.c:2476
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10724
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
ForeignServer * GetForeignServer(Oid serverid)
Definition: foreign.c:109
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
FormData_pg_ts_parser * Form_pg_ts_parser
Definition: pg_ts_parser.h:55
FormData_pg_conversion * Form_pg_conversion
Definition: pg_conversion.h:62
bool OpclassIsVisible(Oid opcid)
Definition: namespace.c:1825
FormData_pg_policy * Form_pg_policy
Definition: pg_policy.h:50
char * format_procedure(Oid procedure_oid)
Definition: regproc.c:323
static void getRelationDescription(StringInfo buffer, Oid relid)
bool ConversionIsVisible(Oid conid)
Definition: namespace.c:2123
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:795
#define Assert(condition)
Definition: c.h:733
FormData_pg_trigger * Form_pg_trigger
Definition: pg_trigger.h:71
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:51
FormData_pg_rewrite * Form_pg_rewrite
Definition: pg_rewrite.h:52
bool TSTemplateIsVisible(Oid tmplId)
Definition: namespace.c:2603
FormData_pg_am * Form_pg_am
Definition: pg_am.h:48
bool TSParserIsVisible(Oid prsId)
Definition: namespace.c:2350
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:88
char * get_tablespace_name(Oid spc_oid)
Definition: tablespace.c:1462
char * servername
Definition: foreign.h:39
FormData_pg_ts_template * Form_pg_ts_template
#define elog(elevel,...)
Definition: elog.h:228
FormData_pg_publication_rel * Form_pg_publication_rel
#define NameStr(name)
Definition: c.h:610
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:775
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:87
#define BTEqualStrategyNumber
Definition: stratnum.h:31
FormData_pg_statistic_ext * Form_pg_statistic_ext

◆ getObjectDescriptionOids()

char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 3662 of file objectaddress.c.

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

3663 {
3664  ObjectAddress address;
3665 
3666  address.classId = classid;
3667  address.objectId = objid;
3668  address.objectSubId = 0;
3669 
3670  return getObjectDescription(&address);
3671 }
char * getObjectDescription(const ObjectAddress *object)

◆ getObjectIdentity()

◆ getObjectIdentityParts()

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

Definition at line 4295 of file objectaddress.c.

References AccessMethodOperatorOidIndexId, AccessMethodProcedureOidIndexId, AccessShareLock, AMOID, appendStringInfo(), appendStringInfoString(), Assert, AttrDefaultOidIndexId, BTEqualStrategyNumber, CLAOID, ObjectAddress::classId, COLLOID, CONSTROID, CONVOID, StringInfoData::data, datname, DefaultAclOidIndexId, elog, ERROR, EVENTTRIGGEROID, ForeignDataWrapper::fdwname, format_operator_parts(), format_operator_qualified(), format_procedure_parts(), format_procedure_qualified(), format_type_be_qualified(), 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(), GetForeignDataWrapper(), GetForeignServer(), getObjectClass(), getObjectIdentityParts(), getOpFamilyIdentity(), getRelationIdentity(), GETSTRUCT, GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), LANGOID, lappend(), 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, 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().

4297 {
4298  StringInfoData buffer;
4299 
4300  initStringInfo(&buffer);
4301 
4302  /*
4303  * Make sure that both objname and objargs were passed, or none was; and
4304  * initialize them to empty lists. For objname this is useless because it
4305  * will be initialized in all cases inside the switch; but we do it anyway
4306  * so that we can test below that no branch leaves it unset.
4307  */
4308  Assert(PointerIsValid(objname) == PointerIsValid(objargs));
4309  if (objname)
4310  {
4311  *objname = NIL;
4312  *objargs = NIL;
4313  }
4314 
4315  switch (getObjectClass(object))
4316  {
4317  case OCLASS_CLASS:
4318  getRelationIdentity(&buffer, object->objectId, objname);
4319  if (object->objectSubId != 0)
4320  {
4321  char *attr;
4322 
4323  attr = get_attname(object->objectId, object->objectSubId,
4324  false);
4325  appendStringInfo(&buffer, ".%s", quote_identifier(attr));
4326  if (objname)
4327  *objname = lappend(*objname, attr);
4328  }
4329  break;
4330 
4331  case OCLASS_PROC:
4332  appendStringInfoString(&buffer,
4333  format_procedure_qualified(object->objectId));
4334  if (objname)
4335  format_procedure_parts(object->objectId, objname, objargs);
4336  break;
4337 
4338  case OCLASS_TYPE:
4339  {
4340  char *typeout;
4341 
4342  typeout = format_type_be_qualified(object->objectId);
4343  appendStringInfoString(&buffer, typeout);
4344  if (objname)
4345  *objname = list_make1(typeout);
4346  }
4347  break;
4348 
4349  case OCLASS_CAST:
4350  {
4351  Relation castRel;
4352  HeapTuple tup;
4353  Form_pg_cast castForm;
4354 
4355  castRel = table_open(CastRelationId, AccessShareLock);
4356 
4357  tup = get_catalog_object_by_oid(castRel, Anum_pg_cast_oid,
4358  object->objectId);
4359 
4360  if (!HeapTupleIsValid(tup))
4361  elog(ERROR, "could not find tuple for cast %u",
4362  object->objectId);
4363 
4364  castForm = (Form_pg_cast) GETSTRUCT(tup);
4365 
4366  appendStringInfo(&buffer, "(%s AS %s)",
4367  format_type_be_qualified(castForm->castsource),
4368  format_type_be_qualified(castForm->casttarget));
4369 
4370  if (objname)
4371  {
4372  *objname = list_make1(format_type_be_qualified(castForm->castsource));
4373  *objargs = list_make1(format_type_be_qualified(castForm->casttarget));
4374  }
4375 
4376  table_close(castRel, AccessShareLock);
4377  break;
4378  }
4379 
4380  case OCLASS_COLLATION:
4381  {
4382  HeapTuple collTup;
4383  Form_pg_collation coll;
4384  char *schema;
4385 
4386  collTup = SearchSysCache1(COLLOID,
4387  ObjectIdGetDatum(object->objectId));
4388  if (!HeapTupleIsValid(collTup))
4389  elog(ERROR, "cache lookup failed for collation %u",
4390  object->objectId);
4391  coll = (Form_pg_collation) GETSTRUCT(collTup);
4392  schema = get_namespace_name_or_temp(coll->collnamespace);
4393  appendStringInfoString(&buffer,
4395  NameStr(coll->collname)));
4396  if (objname)
4397  *objname = list_make2(schema,
4398  pstrdup(NameStr(coll->collname)));
4399  ReleaseSysCache(collTup);
4400  break;
4401  }
4402 
4403  case OCLASS_CONSTRAINT:
4404  {
4405  HeapTuple conTup;
4406  Form_pg_constraint con;
4407 
4408  conTup = SearchSysCache1(CONSTROID,
4409  ObjectIdGetDatum(object->objectId));
4410  if (!HeapTupleIsValid(conTup))
4411  elog(ERROR, "cache lookup failed for constraint %u",
4412  object->objectId);
4413  con = (Form_pg_constraint) GETSTRUCT(conTup);
4414 
4415  if (OidIsValid(con->conrelid))
4416  {
4417  appendStringInfo(&buffer, "%s on ",
4418  quote_identifier(NameStr(con->conname)));
4419  getRelationIdentity(&buffer, con->conrelid, objname);
4420  if (objname)
4421  *objname = lappend(*objname, pstrdup(NameStr(con->conname)));
4422  }
4423  else
4424  {
4425  ObjectAddress domain;
4426 
4427  Assert(OidIsValid(con->contypid));
4428  domain.classId = TypeRelationId;
4429  domain.objectId = con->contypid;
4430  domain.objectSubId = 0;
4431 
4432  appendStringInfo(&buffer, "%s on %s",
4433  quote_identifier(NameStr(con->conname)),
4434  getObjectIdentityParts(&domain, objname, objargs));
4435 
4436  if (objname)
4437  *objargs = lappend(*objargs, pstrdup(NameStr(con->conname)));
4438  }
4439 
4440  ReleaseSysCache(conTup);
4441  break;
4442  }
4443 
4444  case OCLASS_CONVERSION:
4445  {
4446  HeapTuple conTup;
4447  Form_pg_conversion conForm;
4448  char *schema;
4449 
4450  conTup = SearchSysCache1(CONVOID,
4451  ObjectIdGetDatum(object->objectId));
4452  if (!HeapTupleIsValid(conTup))
4453  elog(ERROR, "cache lookup failed for conversion %u",
4454  object->objectId);
4455  conForm = (Form_pg_conversion) GETSTRUCT(conTup);
4456  schema = get_namespace_name_or_temp(conForm->connamespace);
4457  appendStringInfoString(&buffer,
4459  NameStr(conForm->conname)));
4460  if (objname)
4461  *objname = list_make2(schema,
4462  pstrdup(NameStr(conForm->conname)));
4463  ReleaseSysCache(conTup);
4464  break;
4465  }
4466 
4467  case OCLASS_DEFAULT:
4468  {
4469  Relation attrdefDesc;
4470  ScanKeyData skey[1];
4471  SysScanDesc adscan;
4472 
4473  HeapTuple tup;
4474  Form_pg_attrdef attrdef;
4475  ObjectAddress colobject;
4476 
4477  attrdefDesc = table_open(AttrDefaultRelationId, AccessShareLock);
4478 
4479  ScanKeyInit(&skey[0],
4480  Anum_pg_attrdef_oid,
4481  BTEqualStrategyNumber, F_OIDEQ,
4482  ObjectIdGetDatum(object->objectId));
4483 
4484  adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndexId,
4485  true, NULL, 1, skey);
4486 
4487  tup = systable_getnext(adscan);
4488 
4489  if (!HeapTupleIsValid(tup))
4490  elog(ERROR, "could not find tuple for attrdef %u",
4491  object->objectId);
4492 
4493  attrdef = (Form_pg_attrdef) GETSTRUCT(tup);
4494 
4495  colobject.classId = RelationRelationId;
4496  colobject.objectId = attrdef->adrelid;
4497  colobject.objectSubId = attrdef->adnum;
4498 
4499  appendStringInfo(&buffer, "for %s",
4500  getObjectIdentityParts(&colobject,
4501  objname, objargs));
4502 
4503  systable_endscan(adscan);
4504  table_close(attrdefDesc, AccessShareLock);
4505  break;
4506  }
4507 
4508  case OCLASS_LANGUAGE:
4509  {
4510  HeapTuple langTup;
4511  Form_pg_language langForm;
4512 
4513  langTup = SearchSysCache1(LANGOID,
4514  ObjectIdGetDatum(object->objectId));
4515  if (!HeapTupleIsValid(langTup))
4516  elog(ERROR, "cache lookup failed for language %u",
4517  object->objectId);
4518  langForm = (Form_pg_language) GETSTRUCT(langTup);
4519  appendStringInfoString(&buffer,
4520  quote_identifier(NameStr(langForm->lanname)));
4521  if (objname)
4522  *objname = list_make1(pstrdup(NameStr(langForm->lanname)));
4523  ReleaseSysCache(langTup);
4524  break;
4525  }
4526  case OCLASS_LARGEOBJECT:
4527  appendStringInfo(&buffer, "%u",
4528  object->objectId);
4529  if (objname)
4530  *objname = list_make1(psprintf("%u", object->objectId));
4531  break;
4532 
4533  case OCLASS_OPERATOR:
4534  appendStringInfoString(&buffer,
4535  format_operator_qualified(object->objectId));
4536  if (objname)
4537  format_operator_parts(object->objectId, objname, objargs);
4538  break;
4539 
4540  case OCLASS_OPCLASS:
4541  {
4542  HeapTuple opcTup;
4543  Form_pg_opclass opcForm;
4544  HeapTuple amTup;
4545  Form_pg_am amForm;
4546  char *schema;
4547 
4548  opcTup = SearchSysCache1(CLAOID,
4549  ObjectIdGetDatum(object->objectId));
4550  if (!HeapTupleIsValid(opcTup))
4551  elog(ERROR, "cache lookup failed for opclass %u",
4552  object->objectId);
4553  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
4554  schema = get_namespace_name_or_temp(opcForm->opcnamespace);
4555 
4556  amTup = SearchSysCache1(AMOID,
4557  ObjectIdGetDatum(opcForm->opcmethod));
4558  if (!HeapTupleIsValid(amTup))
4559  elog(ERROR, "cache lookup failed for access method %u",
4560  opcForm->opcmethod);
4561  amForm = (Form_pg_am) GETSTRUCT(amTup);
4562 
4563  appendStringInfo(&buffer, "%s USING %s",
4565  NameStr(opcForm->opcname)),
4566  quote_identifier(NameStr(amForm->amname)));
4567  if (objname)
4568  *objname = list_make3(pstrdup(NameStr(amForm->amname)),
4569  schema,
4570  pstrdup(NameStr(opcForm->opcname)));
4571 
4572  ReleaseSysCache(amTup);
4573  ReleaseSysCache(opcTup);
4574  break;
4575  }
4576 
4577  case OCLASS_OPFAMILY:
4578  getOpFamilyIdentity(&buffer, object->objectId, objname);
4579  break;
4580 
4581  case OCLASS_AM:
4582  {
4583  char *amname;
4584 
4585  amname = get_am_name(object->objectId);
4586  if (!amname)
4587  elog(ERROR, "cache lookup failed for access method %u",
4588  object->objectId);
4589  appendStringInfoString(&buffer, quote_identifier(amname));
4590  if (objname)
4591  *objname = list_make1(amname);
4592  }
4593  break;
4594 
4595  case OCLASS_AMOP:
4596  {
4597  Relation amopDesc;
4598  HeapTuple tup;
4599  ScanKeyData skey[1];
4600  SysScanDesc amscan;
4601  Form_pg_amop amopForm;
4602  StringInfoData opfam;
4603  char *ltype;
4604  char *rtype;
4605 
4606  amopDesc = table_open(AccessMethodOperatorRelationId,
4607  AccessShareLock);
4608 
4609  ScanKeyInit(&skey[0],
4610  Anum_pg_amop_oid,
4611  BTEqualStrategyNumber, F_OIDEQ,
4612  ObjectIdGetDatum(object->objectId));
4613 
4614  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
4615  NULL, 1, skey);
4616 
4617  tup = systable_getnext(amscan);
4618 
4619  if (!HeapTupleIsValid(tup))
4620  elog(ERROR, "could not find tuple for amop entry %u",
4621  object->objectId);
4622 
4623  amopForm = (Form_pg_amop) GETSTRUCT(tup);
4624 
4625  initStringInfo(&opfam);
4626  getOpFamilyIdentity(&opfam, amopForm->amopfamily, objname);
4627 
4628  ltype = format_type_be_qualified(amopForm->amoplefttype);
4629  rtype = format_type_be_qualified(amopForm->amoprighttype);
4630 
4631  if (objname)
4632  {
4633  *objname = lappend(*objname,
4634  psprintf("%d", amopForm->amopstrategy));
4635  *objargs = list_make2(ltype, rtype);
4636  }
4637 
4638  appendStringInfo(&buffer, "operator %d (%s, %s) of %s",
4639  amopForm->amopstrategy,
4640  ltype, rtype, opfam.data);
4641 
4642  pfree(opfam.data);
4643 
4644  systable_endscan(amscan);
4645  table_close(amopDesc, AccessShareLock);
4646  break;
4647  }
4648 
4649  case OCLASS_AMPROC:
4650  {
4651  Relation amprocDesc;
4652  ScanKeyData skey[1];
4653  SysScanDesc amscan;
4654  HeapTuple tup;
4655  Form_pg_amproc amprocForm;
4656  StringInfoData opfam;
4657  char *ltype;
4658  char *rtype;
4659 
4660  amprocDesc = table_open(AccessMethodProcedureRelationId,
4661  AccessShareLock);
4662 
4663  ScanKeyInit(&skey[0],
4664  Anum_pg_amproc_oid,
4665  BTEqualStrategyNumber, F_OIDEQ,
4666  ObjectIdGetDatum(object->objectId));
4667 
4668  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
4669  NULL, 1, skey);
4670 
4671  tup = systable_getnext(amscan);
4672 
4673  if (!HeapTupleIsValid(tup))
4674  elog(ERROR, "could not find tuple for amproc entry %u",
4675  object->objectId);
4676 
4677  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
4678 
4679  initStringInfo(&opfam);
4680  getOpFamilyIdentity(&opfam, amprocForm->amprocfamily, objname);
4681 
4682  ltype = format_type_be_qualified(amprocForm->amproclefttype);
4683  rtype = format_type_be_qualified(amprocForm->amprocrighttype);
4684 
4685  if (objname)
4686  {
4687  *objname = lappend(*objname,
4688  psprintf("%d", amprocForm->amprocnum));
4689  *objargs = list_make2(ltype, rtype);
4690  }
4691 
4692  appendStringInfo(&buffer, "function %d (%s, %s) of %s",
4693  amprocForm->amprocnum,
4694  ltype, rtype, opfam.data);
4695 
4696  pfree(opfam.data);
4697 
4698  systable_endscan(amscan);
4699  table_close(amprocDesc, AccessShareLock);
4700  break;
4701  }
4702 
4703  case OCLASS_REWRITE:
4704  {
4705  Relation ruleDesc;
4706  HeapTuple tup;
4708 
4709  ruleDesc = table_open(RewriteRelationId, AccessShareLock);
4710 
4711  tup = get_catalog_object_by_oid(ruleDesc, Anum_pg_rewrite_oid,
4712  object->objectId);
4713 
4714  if (!HeapTupleIsValid(tup))
4715  elog(ERROR, "could not find tuple for rule %u",
4716  object->objectId);
4717 
4718  rule = (Form_pg_rewrite) GETSTRUCT(tup);
4719 
4720  appendStringInfo(&buffer, "%s on ",
4721  quote_identifier(NameStr(rule->rulename)));
4722  getRelationIdentity(&buffer, rule->ev_class, objname);
4723  if (objname)
4724  *objname = lappend(*objname, pstrdup(NameStr(rule->rulename)));
4725 
4726  table_close(ruleDesc, AccessShareLock);
4727  break;
4728  }
4729 
4730  case OCLASS_TRIGGER:
4731  {
4732  Relation trigDesc;
4733  HeapTuple tup;
4734  Form_pg_trigger trig;
4735 
4736  trigDesc = table_open(TriggerRelationId, AccessShareLock);
4737 
4738  tup = get_catalog_object_by_oid(trigDesc, Anum_pg_trigger_oid,
4739  object->objectId);
4740 
4741  if (!HeapTupleIsValid(tup))
4742  elog(ERROR, "could not find tuple for trigger %u",
4743  object->objectId);
4744 
4745  trig = (Form_pg_trigger) GETSTRUCT(tup);
4746 
4747  appendStringInfo(&buffer, "%s on ",
4748  quote_identifier(NameStr(trig->tgname)));
4749  getRelationIdentity(&buffer, trig->tgrelid, objname);
4750  if (objname)
4751  *objname = lappend(*objname, pstrdup(NameStr(trig->tgname)));
4752 
4753  table_close(trigDesc, AccessShareLock);
4754  break;
4755  }
4756 
4757  case OCLASS_SCHEMA:
4758  {
4759  char *nspname;
4760 
4761  nspname = get_namespace_name_or_temp(object->objectId);
4762  if (!nspname)
4763  elog(ERROR, "cache lookup failed for namespace %u",
4764  object->objectId);
4765  appendStringInfoString(&buffer,
4766  quote_identifier(nspname));
4767  if (objname)
4768  *objname = list_make1(nspname);
4769  break;
4770  }
4771 
4772  case OCLASS_STATISTIC_EXT:
4773  {
4774  HeapTuple tup;
4775  Form_pg_statistic_ext formStatistic;
4776  char *schema;
4777 
4779  ObjectIdGetDatum(object->objectId));
4780  if (!HeapTupleIsValid(tup))
4781  elog(ERROR, "cache lookup failed for statistics object %u",
4782  object->objectId);
4783  formStatistic = (Form_pg_statistic_ext) GETSTRUCT(tup);
4784  schema = get_namespace_name_or_temp(formStatistic->stxnamespace);
4785  appendStringInfoString(&buffer,
4787  NameStr(formStatistic->stxname)));
4788  if (objname)
4789  *objname = list_make2(schema,
4790  pstrdup(NameStr(formStatistic->stxname)));
4791  ReleaseSysCache(tup);
4792  }
4793  break;
4794 
4795  case OCLASS_TSPARSER:
4796  {
4797  HeapTuple tup;
4798  Form_pg_ts_parser formParser;
4799  char *schema;
4800 
4802  ObjectIdGetDatum(object->objectId));
4803  if (!HeapTupleIsValid(tup))
4804  elog(ERROR, "cache lookup failed for text search parser %u",
4805  object->objectId);
4806  formParser = (Form_pg_ts_parser) GETSTRUCT(tup);
4807  schema = get_namespace_name_or_temp(formParser->prsnamespace);
4808  appendStringInfoString(&buffer,
4810  NameStr(formParser->prsname)));
4811  if (objname)
4812  *objname = list_make2(schema,
4813  pstrdup(NameStr(formParser->prsname)));
4814  ReleaseSysCache(tup);
4815  break;
4816  }
4817 
4818  case OCLASS_TSDICT:
4819  {
4820  HeapTuple tup;
4821  Form_pg_ts_dict formDict;
4822  char *schema;
4823 
4824  tup = SearchSysCache1(TSDICTOID,
4825  ObjectIdGetDatum(object->objectId));
4826  if (!HeapTupleIsValid(tup))
4827  elog(ERROR, "cache lookup failed for text search dictionary %u",
4828  object->objectId);
4829  formDict = (Form_pg_ts_dict) GETSTRUCT(tup);
4830  schema = get_namespace_name_or_temp(formDict->dictnamespace);
4831  appendStringInfoString(&buffer,
4833  NameStr(formDict->dictname)));
4834  if (objname)
4835  *objname = list_make2(schema,
4836  pstrdup(NameStr(formDict->dictname)));
4837  ReleaseSysCache(tup);
4838  break;
4839  }
4840 
4841  case OCLASS_TSTEMPLATE:
4842  {
4843  HeapTuple tup;
4844  Form_pg_ts_template formTmpl;
4845  char *schema;
4846 
4848  ObjectIdGetDatum(object->objectId));
4849  if (!HeapTupleIsValid(tup))
4850  elog(ERROR, "cache lookup failed for text search template %u",
4851  object->objectId);
4852  formTmpl = (Form_pg_ts_template) GETSTRUCT(tup);
4853  schema = get_namespace_name_or_temp(formTmpl->tmplnamespace);
4854  appendStringInfoString(&buffer,
4856  NameStr(formTmpl->tmplname)));
4857  if (objname)
4858  *objname = list_make2(schema,
4859  pstrdup(NameStr(formTmpl->tmplname)));
4860  ReleaseSysCache(tup);
4861  break;
4862  }
4863 
4864  case OCLASS_TSCONFIG:
4865  {
4866  HeapTuple tup;
4867  Form_pg_ts_config formCfg;
4868  char *schema;
4869 
4871  ObjectIdGetDatum(object->objectId));
4872  if (!HeapTupleIsValid(tup))
4873  elog(ERROR, "cache lookup failed for text search configuration %u",
4874  object->objectId);
4875  formCfg = (Form_pg_ts_config) GETSTRUCT(tup);
4876  schema = get_namespace_name_or_temp(formCfg->cfgnamespace);
4877  appendStringInfoString(&buffer,
4879  NameStr(formCfg->cfgname)));
4880  if (objname)
4881  *objname = list_make2(schema,
4882  pstrdup(NameStr(formCfg->cfgname)));
4883  ReleaseSysCache(tup);
4884  break;
4885  }
4886 
4887  case OCLASS_ROLE:
4888  {
4889  char *username;
4890 
4891  username = GetUserNameFromId(object->objectId, false);
4892  if (objname)
4893  *objname = list_make1(username);
4894  appendStringInfoString(&buffer,
4895  quote_identifier(username));
4896  break;
4897  }
4898 
4899  case OCLASS_DATABASE:
4900  {
4901  char *datname;
4902 
4903  datname = get_database_name(object->objectId);
4904  if (!datname)
4905  elog(ERROR, "cache lookup failed for database %u",
4906  object->objectId);
4907  if (objname)
4908  *objname = list_make1(datname);
4909  appendStringInfoString(&buffer,
4910  quote_identifier(datname));
4911  break;
4912  }
4913 
4914  case OCLASS_TBLSPACE:
4915  {
4916  char *tblspace;
4917 
4918  tblspace = get_tablespace_name(object->objectId);
4919  if (!tblspace)
4920  elog(ERROR, "cache lookup failed for tablespace %u",
4921  object->objectId);
4922  if (objname)
4923  *objname = list_make1(tblspace);
4924  appendStringInfoString(&buffer,
4925  quote_identifier(tblspace));
4926  break;
4927  }
4928 
4929  case OCLASS_FDW:
4930  {
4931  ForeignDataWrapper *fdw;
4932 
4933  fdw = GetForeignDataWrapper(object->objectId);
4935  if (objname)
4936  *objname = list_make1(pstrdup(fdw->fdwname));
4937  break;
4938  }
4939 
4940  case OCLASS_FOREIGN_SERVER:
4941  {
4942  ForeignServer *srv;
4943 
4944  srv = GetForeignServer(object->objectId);
4945  appendStringInfoString(&buffer,
4947  if (objname)
4948  *objname = list_make1(pstrdup(srv->servername));
4949  break;
4950  }
4951 
4952  case OCLASS_USER_MAPPING:
4953  {
4954  HeapTuple tup;
4955  Oid useid;
4956  Form_pg_user_mapping umform;
4957  ForeignServer *srv;
4958  const char *usename;
4959 
4961  ObjectIdGetDatum(object->objectId));
4962  if (!HeapTupleIsValid(tup))
4963  elog(ERROR, "cache lookup failed for user mapping %u",
4964  object->objectId);
4965  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
4966  useid = umform->umuser;
4967  srv = GetForeignServer(umform->umserver);
4968 
4969  ReleaseSysCache(tup);
4970 
4971  if (OidIsValid(useid))
4972  usename = GetUserNameFromId(useid, false);
4973  else
4974  usename = "public";
4975 
4976  if (objname)
4977  {
4978  *objname = list_make1(pstrdup(usename));
4979  *objargs = list_make1(pstrdup(srv->servername));
4980  }
4981 
4982  appendStringInfo(&buffer, "%s on server %s",
4983  quote_identifier(usename),
4984  srv->servername);
4985  break;
4986  }
4987 
4988  case OCLASS_DEFACL:
4989  {
4990  Relation defaclrel;
4991  ScanKeyData skey[1];
4992  SysScanDesc rcscan;
4993  HeapTuple tup;
4994  Form_pg_default_acl defacl;
4995  char *schema;
4996  char *username;
4997 
4998  defaclrel = table_open(DefaultAclRelationId, AccessShareLock);
4999 
5000  ScanKeyInit(&skey[0],
5001  Anum_pg_default_acl_oid,
5002  BTEqualStrategyNumber, F_OIDEQ,
5003  ObjectIdGetDatum(object->objectId));
5004 
5005  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
5006  true, NULL, 1, skey);
5007 
5008  tup = systable_getnext(rcscan);
5009 
5010  if (!HeapTupleIsValid(tup))
5011  elog(ERROR, "could not find tuple for default ACL %u",
5012  object->objectId);
5013 
5014  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
5015 
5016  username = GetUserNameFromId(defacl->defaclrole, false);
5017  appendStringInfo(&buffer,
5018  "for role %s",
5019  quote_identifier(username));
5020 
5021  if (OidIsValid(defacl->defaclnamespace))
5022  {
5023  schema = get_namespace_name_or_temp(defacl->defaclnamespace);
5024  appendStringInfo(&buffer,
5025  " in schema %s",
5026  quote_identifier(schema));
5027  }
5028  else
5029  schema = NULL;
5030 
5031  switch (defacl->defaclobjtype)
5032  {
5033  case DEFACLOBJ_RELATION:
5034  appendStringInfoString(&buffer,
5035  " on tables");
5036  break;
5037  case DEFACLOBJ_SEQUENCE:
5038  appendStringInfoString(&buffer,
5039  " on sequences");
5040  break;
5041  case DEFACLOBJ_FUNCTION:
5042  appendStringInfoString(&buffer,
5043  " on functions");
5044  break;
5045  case DEFACLOBJ_TYPE:
5046  appendStringInfoString(&buffer,
5047  " on types");
5048  break;
5049  case DEFACLOBJ_NAMESPACE:
5050  appendStringInfoString(&buffer,
5051  " on schemas");
5052  break;
5053  }
5054 
5055  if (objname)
5056  {
5057  *objname = list_make1(username);
5058  if (schema)
5059  *objname = lappend(*objname, schema);
5060  *objargs = list_make1(psprintf("%c", defacl->defaclobjtype));
5061  }
5062 
5063  systable_endscan(rcscan);
5064  table_close(defaclrel, AccessShareLock);
5065  break;
5066  }
5067 
5068  case OCLASS_EXTENSION:
5069  {
5070  char *extname;
5071 
5072  extname = get_extension_name(object->objectId);
5073  if (!extname)
5074  elog(ERROR, "cache lookup failed for extension %u",
5075  object->objectId);
5076  appendStringInfoString(&buffer, quote_identifier(extname));
5077  if (objname)
5078  *objname = list_make1(extname);
5079  break;
5080  }
5081 
5082  case OCLASS_EVENT_TRIGGER:
5083  {
5084  HeapTuple tup;
5085  Form_pg_event_trigger trigForm;
5086 
5087  /* no objname support here */
5088  if (objname)
5089  *objname = NIL;
5090 
5092  ObjectIdGetDatum(object->objectId));
5093  if (!HeapTupleIsValid(tup))
5094  elog(ERROR, "cache lookup failed for event trigger %u",
5095  object->objectId);
5096  trigForm = (Form_pg_event_trigger) GETSTRUCT(tup);
5097  appendStringInfoString(&buffer,
5098  quote_identifier(NameStr(trigForm->evtname)));
5099  ReleaseSysCache(tup);
5100  break;
5101  }
5102 
5103  case OCLASS_POLICY:
5104  {
5105  Relation polDesc;
5106  HeapTuple tup;
5107  Form_pg_policy policy;
5108 
5109  polDesc = table_open(PolicyRelationId, AccessShareLock);
5110 
5111  tup = get_catalog_object_by_oid(polDesc, Anum_pg_policy_oid,
5112  object->objectId);
5113 
5114  if (!HeapTupleIsValid(tup))
5115  elog(ERROR, "could not find tuple for policy %u",
5116  object->objectId);
5117 
5118  policy = (Form_pg_policy) GETSTRUCT(tup);
5119 
5120  appendStringInfo(&buffer, "%s on ",
5121  quote_identifier(NameStr(policy->polname)));
5122  getRelationIdentity(&buffer, policy->polrelid, objname);
5123  if (objname)
5124  *objname = lappend(*objname, pstrdup(NameStr(policy->polname)));
5125 
5126  table_close(polDesc, AccessShareLock);
5127  break;
5128  }
5129 
5130  case OCLASS_PUBLICATION:
5131  {
5132  char *pubname;
5133 
5134  pubname = get_publication_name(object->objectId, false);
5135  appendStringInfoString(&buffer,
5136  quote_identifier(pubname));
5137  if (objname)
5138  *objname = list_make1(pubname);
5139  break;
5140  }
5141 
5143  {
5144  HeapTuple tup;
5145  char *pubname;
5146  Form_pg_publication_rel prform;
5147 
5149  ObjectIdGetDatum(object->objectId));
5150  if (!HeapTupleIsValid(tup))
5151  elog(ERROR, "cache lookup failed for publication table %u",
5152  object->objectId);
5153 
5154  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
5155  pubname = get_publication_name(prform->prpubid, false);
5156 
5157  getRelationIdentity(&buffer, prform->prrelid, objname);
5158  appendStringInfo(&buffer, " in publication %s", pubname);
5159 
5160  if (objargs)
5161  *objargs = list_make1(pubname);
5162 
5163  ReleaseSysCache(tup);
5164  break;
5165  }
5166 
5167  case OCLASS_SUBSCRIPTION:
5168  {
5169  char *subname;
5170 
5171  subname = get_subscription_name(object->objectId, false);
5172  appendStringInfoString(&buffer,
5173  quote_identifier(subname));
5174  if (objname)
5175  *objname = list_make1(subname);
5176  break;
5177  }
5178 
5179  case OCLASS_TRANSFORM:
5180  {
5181  Relation transformDesc;
5182  HeapTuple tup;
5183  Form_pg_transform transform;
5184  char *transformLang;
5185  char *transformType;
5186 
5187  transformDesc = table_open(TransformRelationId, AccessShareLock);
5188 
5189  tup = get_catalog_object_by_oid(transformDesc,
5190  Anum_pg_transform_oid,
5191  object->objectId);
5192 
5193  if (!HeapTupleIsValid(tup))
5194  elog(ERROR, "could not find tuple for transform %u",
5195  object->objectId);
5196 
5197  transform = (Form_pg_transform) GETSTRUCT(tup);
5198 
5199  transformType = format_type_be_qualified(transform->trftype);
5200  transformLang = get_language_name(transform->trflang, false);
5201 
5202  appendStringInfo(&buffer, "for %s on language %s",
5203  transformType,
5204  transformLang);
5205  if (objname)
5206  {
5207  *objname = list_make1(transformType);
5208  *objargs = list_make1(pstrdup(transformLang));
5209  }
5210 
5211  table_close(transformDesc, AccessShareLock);
5212  }
5213  break;
5214 
5215  /*
5216  * There's intentionally no default: case here; we want the
5217  * compiler to warn if a new OCLASS hasn't been handled above.
5218  */
5219  }
5220 
5221  /*
5222  * If a get_object_address representation was requested, make sure we are
5223  * providing one. We don't check objargs, because many of the cases above
5224  * leave it as NIL.
5225  */
5226  if (objname && *objname == NIL)
5227  elog(ERROR, "requested object address for unsupported object class %d: text result \"%s\"",
5228  (int) getObjectClass(object), buffer.data);
5229 
5230  return buffer.data;
5231 }
#define list_make2(x1, x2)
Definition: pg_list.h:229
#define list_make3(x1, x2, x3)
Definition: pg_list.h:231
#define NIL
Definition: pg_list.h:65
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:525
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
Definition: syscache.h:36
const char * quote_identifier(const char *ident)
Definition: ruleutils.c:10640
char * get_language_name(Oid langoid, bool missing_ok)
Definition: lsyscache.c:990
FormData_pg_ts_config * Form_pg_ts_config
Definition: pg_ts_config.h:48
char * fdwname
Definition: foreign.h:28
FormData_pg_amproc * Form_pg_amproc
Definition: pg_amproc.h:68
char * pstrdup(const char *in)
Definition: mcxt.c:1186
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
char * get_extension_name(Oid ext_oid)
Definition: extension.c:183
static void getOpFamilyIdentity(StringInfo buffer, Oid opfid, List **object)
char * getObjectIdentityParts(const ObjectAddress *object, List **objname, List **objargs)
#define DefaultAclOidIndexId
Definition: indexing.h:314
#define AccessShareLock
Definition: lockdefs.h:36
#define AttrDefaultOidIndexId
Definition: indexing.h:91
#define AccessMethodOperatorOidIndexId
Definition: indexing.h:81
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:2712
#define OidIsValid(objectId)
Definition: c.h:639
static void getRelationIdentity(StringInfo buffer, Oid relid, List **object)
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:352
char * get_publication_name(Oid pubid, bool missing_ok)
Definition: localtime.c:79
char * get_subscription_name(Oid subid, bool missing_ok)
#define AccessMethodProcedureOidIndexId
Definition: indexing.h:86
#define list_make1(x1)
Definition: pg_list.h:227
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:444
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
Definition: foreign.c:35
void pfree(void *pointer)
Definition: mcxt.c:1056
void format_operator_parts(Oid operator_oid, List **objnames, List **objargs)
Definition: regproc.c:832
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
FormData_pg_transform * Form_pg_transform
Definition: pg_transform.h:43
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
char * format_operator_qualified(Oid operator_oid)
Definition: regproc.c:826
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2155
FormData_pg_user_mapping * Form_pg_user_mapping
FormData_pg_ts_dict * Form_pg_ts_dict
Definition: pg_ts_dict.h:52
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
FormData_pg_default_acl * Form_pg_default_acl
char * get_am_name(Oid amOid)
Definition: amcmds.c:216
void format_procedure_parts(Oid procedure_oid, List **objnames, List **objargs)
Definition: regproc.c:408
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:56
char * format_procedure_qualified(Oid procedure_oid)
Definition: regproc.c:329
List * lappend(List *list, void *datum)
Definition: list.c:322
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
FormData_pg_attrdef * Form_pg_attrdef
Definition: pg_attrdef.h:47
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10724
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
ForeignServer * GetForeignServer(Oid serverid)
Definition: foreign.c:109
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
FormData_pg_ts_parser * Form_pg_ts_parser
Definition: pg_ts_parser.h:55
FormData_pg_conversion * Form_pg_conversion
Definition: pg_conversion.h:62
static char * username
Definition: initdb.c:133
FormData_pg_policy * Form_pg_policy
Definition: pg_policy.h:50
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:795
#define Assert(condition)
Definition: c.h:733
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:336
FormData_pg_trigger * Form_pg_trigger
Definition: pg_trigger.h:71
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:51
FormData_pg_rewrite * Form_pg_rewrite
Definition: pg_rewrite.h:52
FormData_pg_am * Form_pg_am
Definition: pg_am.h:48
FormData_pg_language * Form_pg_language
Definition: pg_language.h:65
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3118
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:88
char * get_tablespace_name(Oid spc_oid)
Definition: tablespace.c:1462
char * servername
Definition: foreign.h:39
FormData_pg_ts_template * Form_pg_ts_template
#define elog(elevel,...)
Definition: elog.h:228
FormData_pg_publication_rel * Form_pg_publication_rel
#define NameStr(name)
Definition: c.h:610
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:775
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:627
#define BTEqualStrategyNumber
Definition: stratnum.h:31
FormData_pg_statistic_ext * Form_pg_statistic_ext

◆ getObjectTypeDescription()

char* getObjectTypeDescription ( const ObjectAddress object)

Definition at line 3996 of file objectaddress.c.

References appendStringInfoString(), StringInfoData::data, getConstraintTypeDescription(), getObjectClass(), getProcedureTypeDescription(), getRelationTypeDescription(), initStringInfo(), 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().

3997 {
3998  StringInfoData buffer;
3999 
4000  initStringInfo(&buffer);
4001 
4002  switch (getObjectClass(object))
4003  {
4004  case OCLASS_CLASS:
4005  getRelationTypeDescription(&buffer, object->objectId,
4006  object->objectSubId);
4007  break;
4008 
4009  case OCLASS_PROC:
4010  getProcedureTypeDescription(&buffer, object->objectId);
4011  break;
4012 
4013  case OCLASS_TYPE:
4014  appendStringInfoString(&buffer, "type");
4015  break;
4016 
4017  case OCLASS_CAST:
4018  appendStringInfoString(&buffer, "cast");
4019  break;
4020 
4021  case OCLASS_COLLATION:
4022  appendStringInfoString(&buffer, "collation");
4023  break;
4024 
4025  case OCLASS_CONSTRAINT:
4026  getConstraintTypeDescription(&buffer, object->objectId);
4027  break;
4028 
4029  case OCLASS_CONVERSION:
4030  appendStringInfoString(&buffer, "conversion");
4031  break;
4032 
4033  case OCLASS_DEFAULT:
4034  appendStringInfoString(&buffer, "default value");
4035  break;
4036 
4037  case OCLASS_LANGUAGE:
4038  appendStringInfoString(&buffer, "language");
4039  break;
4040 
4041  case OCLASS_LARGEOBJECT:
4042  appendStringInfoString(&buffer, "large object");
4043  break;
4044 
4045  case OCLASS_OPERATOR:
4046  appendStringInfoString(&buffer, "operator");
4047  break;
4048 
4049  case OCLASS_OPCLASS:
4050  appendStringInfoString(&buffer, "operator class");
4051  break;
4052 
4053  case OCLASS_OPFAMILY:
4054  appendStringInfoString(&buffer, "operator family");
4055  break;
4056 
4057  case OCLASS_AM:
4058  appendStringInfoString(&buffer, "access method");
4059  break;
4060 
4061  case OCLASS_AMOP:
4062  appendStringInfoString(&buffer, "operator of access method");
4063  break;
4064 
4065  case OCLASS_AMPROC:
4066  appendStringInfoString(&buffer, "function of access method");
4067  break;
4068 
4069  case OCLASS_REWRITE:
4070  appendStringInfoString(&buffer, "rule");
4071  break;
4072 
4073  case OCLASS_TRIGGER:
4074  appendStringInfoString(&buffer, "trigger");
4075  break;
4076 
4077  case OCLASS_SCHEMA:
4078  appendStringInfoString(&buffer, "schema");
4079  break;
4080 
4081  case OCLASS_STATISTIC_EXT:
4082  appendStringInfoString(&buffer, "statistics object");
4083  break;
4084 
4085  case OCLASS_TSPARSER:
4086  appendStringInfoString(&buffer, "text search parser");
4087  break;
4088 
4089  case OCLASS_TSDICT:
4090  appendStringInfoString(&buffer, "text search dictionary");
4091  break;
4092 
4093  case OCLASS_TSTEMPLATE:
4094  appendStringInfoString(&buffer, "text search template");
4095  break;
4096 
4097  case OCLASS_TSCONFIG:
4098  appendStringInfoString(&buffer, "text search configuration");
4099  break;
4100 
4101  case OCLASS_ROLE:
4102  appendStringInfoString(&buffer, "role");
4103  break;
4104 
4105  case OCLASS_DATABASE:
4106  appendStringInfoString(&buffer, "database");
4107  break;
4108 
4109  case OCLASS_TBLSPACE:
4110  appendStringInfoString(&buffer, "tablespace");
4111  break;
4112 
4113  case OCLASS_FDW:
4114  appendStringInfoString(&buffer, "foreign-data wrapper");
4115  break;
4116 
4117  case OCLASS_FOREIGN_SERVER:
4118  appendStringInfoString(&buffer, "server");
4119  break;
4120 
4121  case OCLASS_USER_MAPPING:
4122  appendStringInfoString(&buffer, "user mapping");
4123  break;
4124 
4125  case OCLASS_DEFACL:
4126  appendStringInfoString(&buffer, "default acl");
4127  break;
4128 
4129  case OCLASS_EXTENSION:
4130  appendStringInfoString(&buffer, "extension");
4131  break;
4132 
4133  case OCLASS_EVENT_TRIGGER:
4134  appendStringInfoString(&buffer, "event trigger");
4135  break;
4136 
4137  case OCLASS_POLICY:
4138  appendStringInfoString(&buffer, "policy");
4139  break;
4140 
4141  case OCLASS_PUBLICATION:
4142  appendStringInfoString(&buffer, "publication");
4143  break;
4144 
4146  appendStringInfoString(&buffer, "publication relation");
4147  break;
4148 
4149  case OCLASS_SUBSCRIPTION:
4150  appendStringInfoString(&buffer, "subscription");
4151  break;
4152 
4153  case OCLASS_TRANSFORM:
4154  appendStringInfoString(&buffer, "transform");
4155  break;
4156 
4157  /*
4158  * There's intentionally no default: case here; we want the
4159  * compiler to warn if a new OCLASS hasn't been handled above.
4160  */
4161  }
4162 
4163  return buffer.data;
4164 }
static void getConstraintTypeDescription(StringInfo buffer, Oid constroid)
static void getRelationTypeDescription(StringInfo buffer, Oid relid, int32 objectSubId)
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2712
static void getProcedureTypeDescription(StringInfo buffer, Oid procid)
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59

◆ is_objectclass_supported()

bool is_objectclass_supported ( Oid  class_id)

Definition at line 2653 of file objectaddress.c.

References lengthof.

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

2654 {
2655  int index;
2656 
2657  for (index = 0; index < lengthof(ObjectProperty); index++)
2658  {
2659  if (ObjectProperty[index].class_oid == class_id)
2660  return true;
2661  }
2662 
2663  return false;
2664 }
#define lengthof(array)
Definition: c.h:663
Definition: type.h:89
static const ObjectPropertyType ObjectProperty[]

◆ read_objtype_from_string()

int read_objtype_from_string ( const char *  objtype)

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

2533 {
2534  int i;
2535 
2536  for (i = 0; i < lengthof(ObjectTypeMap); i++)
2537  {
2538  if (strcmp(ObjectTypeMap[i].tm_name, objtype) == 0)
2539  return ObjectTypeMap[i].tm_type;
2540  }
2541  ereport(ERROR,
2542  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2543  errmsg("unrecognized object type \"%s\"", objtype)));
2544 
2545  return -1; /* keep compiler quiet */
2546 }
int errcode(int sqlerrcode)
Definition: elog.c:608
#define lengthof(array)
Definition: c.h:663
#define ERROR
Definition: elog.h:43
static const struct object_type_map ObjectTypeMap[]
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:822
int i

◆ strlist_to_textarray()

struct ArrayType* strlist_to_textarray ( List list)

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

5300 {
5301  ArrayType *arr;
5302  Datum *datums;
5303  bool *nulls;
5304  int j = 0;
5305  ListCell *cell;
5306  MemoryContext memcxt;
5307  MemoryContext oldcxt;
5308  int lb[1];
5309 
5310  /* Work in a temp context; easier than individually pfree'ing the Datums */
5312  "strlist to array",
5314  oldcxt = MemoryContextSwitchTo(memcxt);
5315 
5316  datums = (Datum *) palloc(sizeof(Datum) * list_length(list));
5317  nulls = palloc(sizeof(bool) * list_length(list));
5318 
5319  foreach(cell, list)
5320  {
5321  char *name = lfirst(cell);
5322 
5323  if (name)
5324  {
5325  nulls[j] = false;
5326  datums[j++] = CStringGetTextDatum(name);
5327  }
5328  else
5329  nulls[j] = true;
5330  }
5331 
5332  MemoryContextSwitchTo(oldcxt);
5333 
5334  lb[0] = 1;
5335  arr = construct_md_array(datums, nulls, 1, &j,
5336  lb, TEXTOID, -1, false, 'i');
5337 
5338  MemoryContextDelete(memcxt);
5339 
5340  return arr;
5341 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:211
#define AllocSetContextCreate
Definition: memutils.h:170
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
uintptr_t Datum
Definition: postgres.h:367
#define lfirst(lc)
Definition: pg_list.h:190
static int list_length(const List *l)
Definition: pg_list.h:169
const char * name
Definition: encode.c:521
void * palloc(Size size)
Definition: mcxt.c:949
#define CStringGetTextDatum(s)
Definition: builtins.h:83
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:3326

Variable Documentation

◆ InvalidObjectAddress