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:5380
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:5199
#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:4888
bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid)
Definition: aclchk.c:5038
bool pg_language_ownercheck(Oid lan_oid, Oid roleid)
Definition: aclchk.c:4859
#define castNode(_type_, nodeptr)
Definition: nodes.h:594
bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid)
Definition: aclchk.c:5065
bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5119
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5293
#define strVal(v)
Definition: value.h:54
bool pg_oper_ownercheck(Oid oper_oid, Oid roleid)
Definition: aclchk.c:4807
int errcode(int sqlerrcode)
Definition: elog.c:570
char * format_type_be(Oid type_oid)
Definition: format_type.c:326
bool pg_namespace_ownercheck(Oid nsp_oid, Oid roleid)
Definition: aclchk.c:4931
unsigned int Oid
Definition: postgres_ext.h:31
bool pg_type_ownercheck(Oid type_oid, Oid roleid)
Definition: aclchk.c:4781
#define linitial_node(type, l)
Definition: pg_list.h:198
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3666
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3353
#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:5146
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5251
#define RelationGetRelationName(relation)
Definition: rel.h:450
bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid)
Definition: aclchk.c:4957
bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
Definition: aclchk.c:5011
#define ereport(elevel, rest)
Definition: elog.h:141
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
Definition: aclchk.c:5173
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1124
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:1172
bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid)
Definition: aclchk.c:4984
bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid)
Definition: aclchk.c:5225
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:4755
bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5092
int errmsg(const char *fmt,...)
Definition: elog.c:784
#define elog(elevel,...)
Definition: elog.h:226
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:416
bool pg_proc_ownercheck(Oid proc_oid, Oid roleid)
Definition: aclchk.c:4833
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:292
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5319
bool pg_statistics_object_ownercheck(Oid stat_oid, Oid roleid)
Definition: aclchk.c:5345

◆ get_catalog_object_by_oid()

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

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

2699 {
2700  HeapTuple tuple;
2701  Oid classId = RelationGetRelid(catalog);
2702  int oidCacheId = get_object_catcache_oid(classId);
2703 
2704  if (oidCacheId > 0)
2705  {
2706  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2707  if (!HeapTupleIsValid(tuple)) /* should not happen */
2708  return NULL;
2709  }
2710  else
2711  {
2712  Oid oidIndexId = get_object_oid_index(classId);
2713  SysScanDesc scan;
2714  ScanKeyData skey;
2715 
2716  Assert(OidIsValid(oidIndexId));
2717 
2718  ScanKeyInit(&skey,
2719  oidcol,
2720  BTEqualStrategyNumber, F_OIDEQ,
2721  ObjectIdGetDatum(objectId));
2722 
2723  scan = systable_beginscan(catalog, oidIndexId, true,
2724  NULL, 1, &skey);
2725  tuple = systable_getnext(scan);
2726  if (!HeapTupleIsValid(tuple))
2727  {
2728  systable_endscan(scan);
2729  return NULL;
2730  }
2731  tuple = heap_copytuple(tuple);
2732 
2733  systable_endscan(scan);
2734  }
2735 
2736  return tuple;
2737 }
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:638
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:732
#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:416
#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:570
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:638
#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:1025
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:963
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:984
#define lsecond_node(type, l)
Definition: pg_list.h:203
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:240
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1004
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:732
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:784
#define elog(elevel,...)
Definition: elog.h:226
Oid LookupFuncWithArgs(ObjectType objtype, ObjectWithArgs *func, bool missing_ok)
Definition: parse_func.c:2160
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:233

◆ 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:453
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
char * catalogname
Definition: primnodes.h:66

◆ get_object_attnum_acl()

AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 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 2634 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::is_nsp_name_unique.

Referenced by EventTriggerSQLDropAddObject(), and pg_identify_object().

2635 {
2636  const ObjectPropertyType *prop = get_object_property_data(class_id);
2637 
2638  return prop->is_nsp_name_unique;
2639 }
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:1124
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1172
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1385
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:732
AttrNumber attnum_namespace
#define InvalidAttrNumber
Definition: attnum.h:23
#define elog(elevel,...)
Definition: elog.h:226

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

2617 {
2618  const ObjectPropertyType *prop = get_object_property_data(class_id);
2619 
2620  if (prop->objtype == OBJECT_TABLE)
2621  {
2622  /*
2623  * If the property data says it's a table, dig a little deeper to get
2624  * the real relation kind, so that callers can produce more precise
2625  * error messages.
2626  */
2627  return get_relkind_objtype(get_rel_relkind(object_id));
2628  }
2629  else
2630  return prop->objtype;
2631 }
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 5337 of file objectaddress.c.

References elog, ERROR, 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().

5338 {
5339  switch (relkind)
5340  {
5341  case RELKIND_RELATION:
5342  case RELKIND_PARTITIONED_TABLE:
5343  return OBJECT_TABLE;
5344  case RELKIND_INDEX:
5345  case RELKIND_PARTITIONED_INDEX:
5346  return OBJECT_INDEX;
5347  case RELKIND_SEQUENCE:
5348  return OBJECT_SEQUENCE;
5349  case RELKIND_VIEW:
5350  return OBJECT_VIEW;
5351  case RELKIND_MATVIEW:
5352  return OBJECT_MATVIEW;
5353  case RELKIND_FOREIGN_TABLE:
5354  return OBJECT_FOREIGN_TABLE;
5355 
5356  /*
5357  * other relkinds are not supported here because they don't map to
5358  * OBJECT_* values
5359  */
5360  default:
5361  elog(ERROR, "unexpected relkind: %d", relkind);
5362  return 0;
5363  }
5364 }
char relkind
Definition: pg_class.h:81
#define ERROR
Definition: elog.h:43
#define elog(elevel,...)
Definition: elog.h:226

◆ getObjectDescription()

char* getObjectDescription ( const ObjectAddress object)

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

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

◆ getObjectDescriptionOids()

char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 3655 of file objectaddress.c.

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

3656 {
3657  ObjectAddress address;
3658 
3659  address.classId = classid;
3660  address.objectId = objid;
3661  address.objectSubId = 0;
3662 
3663  return getObjectDescription(&address);
3664 }
char * getObjectDescription(const ObjectAddress *object)

◆ getObjectIdentity()

◆ getObjectIdentityParts()

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

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

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

◆ getObjectTypeDescription()

char* getObjectTypeDescription ( const ObjectAddress object)

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

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

◆ is_objectclass_supported()

bool is_objectclass_supported ( Oid  class_id)

Definition at line 2646 of file objectaddress.c.

References lengthof.

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

2647 {
2648  int index;
2649 
2650  for (index = 0; index < lengthof(ObjectProperty); index++)
2651  {
2652  if (ObjectProperty[index].class_oid == class_id)
2653  return true;
2654  }
2655 
2656  return false;
2657 }
#define lengthof(array)
Definition: c.h:662
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:570
#define lengthof(array)
Definition: c.h:662
#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:784
int i

◆ strlist_to_textarray()

struct ArrayType* strlist_to_textarray ( List list)

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

5293 {
5294  ArrayType *arr;
5295  Datum *datums;
5296  bool *nulls;
5297  int j = 0;
5298  ListCell *cell;
5299  MemoryContext memcxt;
5300  MemoryContext oldcxt;
5301  int lb[1];
5302 
5303  /* Work in a temp context; easier than individually pfree'ing the Datums */
5305  "strlist to array",
5307  oldcxt = MemoryContextSwitchTo(memcxt);
5308 
5309  datums = (Datum *) palloc(sizeof(Datum) * list_length(list));
5310  nulls = palloc(sizeof(bool) * list_length(list));
5311 
5312  foreach(cell, list)
5313  {
5314  char *name = lfirst(cell);
5315 
5316  if (name)
5317  {
5318  nulls[j] = false;
5319  datums[j++] = CStringGetTextDatum(name);
5320  }
5321  else
5322  nulls[j] = true;
5323  }
5324 
5325  MemoryContextSwitchTo(oldcxt);
5326 
5327  lb[0] = 1;
5328  arr = construct_md_array(datums, nulls, 1, &j,
5329  lb, TEXTOID, -1, false, 'i');
5330 
5331  MemoryContextDelete(memcxt);
5332 
5333  return arr;
5334 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:211
#define AllocSetContextCreate
Definition: memutils.h:169
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:191
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:924
#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