PostgreSQL Source Code  git master
objectaddress.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
#include "catalog/catalog.h"
#include "catalog/indexing.h"
#include "catalog/objectaddress.h"
#include "catalog/pg_am.h"
#include "catalog/pg_amop.h"
#include "catalog/pg_amproc.h"
#include "catalog/pg_attrdef.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_cast.h"
#include "catalog/pg_default_acl.h"
#include "catalog/pg_event_trigger.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_constraint.h"
#include "catalog/pg_conversion.h"
#include "catalog/pg_database.h"
#include "catalog/pg_extension.h"
#include "catalog/pg_foreign_data_wrapper.h"
#include "catalog/pg_foreign_server.h"
#include "catalog/pg_language.h"
#include "catalog/pg_largeobject.h"
#include "catalog/pg_largeobject_metadata.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_opclass.h"
#include "catalog/pg_opfamily.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_policy.h"
#include "catalog/pg_publication.h"
#include "catalog/pg_publication_rel.h"
#include "catalog/pg_rewrite.h"
#include "catalog/pg_statistic_ext.h"
#include "catalog/pg_subscription.h"
#include "catalog/pg_tablespace.h"
#include "catalog/pg_transform.h"
#include "catalog/pg_trigger.h"
#include "catalog/pg_ts_config.h"
#include "catalog/pg_ts_dict.h"
#include "catalog/pg_ts_parser.h"
#include "catalog/pg_ts_template.h"
#include "catalog/pg_type.h"
#include "catalog/pg_user_mapping.h"
#include "commands/dbcommands.h"
#include "commands/defrem.h"
#include "commands/event_trigger.h"
#include "commands/extension.h"
#include "commands/policy.h"
#include "commands/proclang.h"
#include "commands/tablespace.h"
#include "commands/trigger.h"
#include "foreign/foreign.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "parser/parse_func.h"
#include "parser/parse_oper.h"
#include "parser/parse_type.h"
#include "rewrite/rewriteSupport.h"
#include "storage/large_object.h"
#include "storage/lmgr.h"
#include "storage/sinval.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/regproc.h"
#include "utils/syscache.h"
#include "utils/tqual.h"
Include dependency graph for objectaddress.c:

Go to the source code of this file.

Data Structures

struct  ObjectPropertyType
 
struct  object_type_map
 

Functions

static ObjectAddress get_object_address_unqualified (ObjectType objtype, Value *strval, bool missing_ok)
 
static ObjectAddress get_relation_by_qualified_name (ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static ObjectAddress get_object_address_relobject (ObjectType objtype, List *object, Relation *relp, bool missing_ok)
 
static ObjectAddress get_object_address_attribute (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)
 
static ObjectAddress get_object_address_type (ObjectType objtype, TypeName *typename, bool missing_ok)
 
static ObjectAddress get_object_address_opcf (ObjectType objtype, List *object, bool missing_ok)
 
static ObjectAddress get_object_address_opf_member (ObjectType objtype, List *object, bool missing_ok)
 
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)
 
static ObjectAddress get_object_address_defacl (List *object, bool missing_ok)
 
static const ObjectPropertyTypeget_object_property_data (Oid class_id)
 
static void getRelationDescription (StringInfo buffer, Oid relid)
 
static void getOpFamilyDescription (StringInfo buffer, Oid opfid)
 
static void getRelationTypeDescription (StringInfo buffer, Oid relid, int32 objectSubId)
 
static void getProcedureTypeDescription (StringInfo buffer, Oid procid)
 
static void getConstraintTypeDescription (StringInfo buffer, Oid constroid)
 
static void getOpFamilyIdentity (StringInfo buffer, Oid opfid, List **object)
 
static void getRelationIdentity (StringInfo buffer, Oid relid, List **object)
 
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)
 
static Listtextarray_to_strvaluelist (ArrayType *arr)
 
Datum pg_get_object_address (PG_FUNCTION_ARGS)
 
void check_object_ownership (Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
 
Oid get_object_namespace (const ObjectAddress *address)
 
int read_objtype_from_string (const char *objtype)
 
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_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)
 
bool is_objectclass_supported (Oid class_id)
 
HeapTuple get_catalog_object_by_oid (Relation catalog, Oid objectId)
 
char * getObjectDescription (const ObjectAddress *object)
 
char * getObjectDescriptionOids (Oid classid, Oid objid)
 
Datum pg_describe_object (PG_FUNCTION_ARGS)
 
Datum pg_identify_object (PG_FUNCTION_ARGS)
 
Datum pg_identify_object_as_address (PG_FUNCTION_ARGS)
 
char * getObjectTypeDescription (const ObjectAddress *object)
 
char * getObjectIdentity (const ObjectAddress *object)
 
char * getObjectIdentityParts (const ObjectAddress *object, List **objname, List **objargs)
 
ArrayTypestrlist_to_textarray (List *list)
 
ObjectType get_relkind_objtype (char relkind)
 

Variables

static const ObjectPropertyType ObjectProperty []
 
static const struct object_type_map ObjectTypeMap []
 
const ObjectAddress InvalidObjectAddress
 

Function Documentation

◆ check_object_ownership()

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

Definition at line 2230 of file objectaddress.c.

References aclcheck_error(), aclcheck_error_type(), ACLCHECK_NOT_OWNER, castNode, elog, ereport, errcode(), errmsg(), ERROR, format_type_be(), has_createrole_privilege(), 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, 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, strVal, superuser_arg(), and typenameTypeId().

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

2232 {
2233  switch (objtype)
2234  {
2235  case OBJECT_INDEX:
2236  case OBJECT_SEQUENCE:
2237  case OBJECT_TABLE:
2238  case OBJECT_VIEW:
2239  case OBJECT_MATVIEW:
2240  case OBJECT_FOREIGN_TABLE:
2241  case OBJECT_COLUMN:
2242  case OBJECT_RULE:
2243  case OBJECT_TRIGGER:
2244  case OBJECT_POLICY:
2245  case OBJECT_TABCONSTRAINT:
2246  if (!pg_class_ownercheck(RelationGetRelid(relation), roleid))
2248  RelationGetRelationName(relation));
2249  break;
2250  case OBJECT_DATABASE:
2251  if (!pg_database_ownercheck(address.objectId, roleid))
2253  strVal((Value *) object));
2254  break;
2255  case OBJECT_TYPE:
2256  case OBJECT_DOMAIN:
2257  case OBJECT_ATTRIBUTE:
2258  case OBJECT_DOMCONSTRAINT:
2259  if (!pg_type_ownercheck(address.objectId, roleid))
2261  break;
2262  case OBJECT_AGGREGATE:
2263  case OBJECT_FUNCTION:
2264  case OBJECT_PROCEDURE:
2265  case OBJECT_ROUTINE:
2266  if (!pg_proc_ownercheck(address.objectId, roleid))
2268  NameListToString((castNode(ObjectWithArgs, object))->objname));
2269  break;
2270  case OBJECT_OPERATOR:
2271  if (!pg_oper_ownercheck(address.objectId, roleid))
2273  NameListToString((castNode(ObjectWithArgs, object))->objname));
2274  break;
2275  case OBJECT_SCHEMA:
2276  if (!pg_namespace_ownercheck(address.objectId, roleid))
2278  strVal((Value *) object));
2279  break;
2280  case OBJECT_COLLATION:
2281  if (!pg_collation_ownercheck(address.objectId, roleid))
2283  NameListToString(castNode(List, object)));
2284  break;
2285  case OBJECT_CONVERSION:
2286  if (!pg_conversion_ownercheck(address.objectId, roleid))
2288  NameListToString(castNode(List, object)));
2289  break;
2290  case OBJECT_EXTENSION:
2291  if (!pg_extension_ownercheck(address.objectId, roleid))
2293  strVal((Value *) object));
2294  break;
2295  case OBJECT_FDW:
2296  if (!pg_foreign_data_wrapper_ownercheck(address.objectId, roleid))
2298  strVal((Value *) object));
2299  break;
2300  case OBJECT_FOREIGN_SERVER:
2301  if (!pg_foreign_server_ownercheck(address.objectId, roleid))
2303  strVal((Value *) object));
2304  break;
2305  case OBJECT_EVENT_TRIGGER:
2306  if (!pg_event_trigger_ownercheck(address.objectId, roleid))
2308  strVal((Value *) object));
2309  break;
2310  case OBJECT_LANGUAGE:
2311  if (!pg_language_ownercheck(address.objectId, roleid))
2313  strVal((Value *) object));
2314  break;
2315  case OBJECT_OPCLASS:
2316  if (!pg_opclass_ownercheck(address.objectId, roleid))
2318  NameListToString(castNode(List, object)));
2319  break;
2320  case OBJECT_OPFAMILY:
2321  if (!pg_opfamily_ownercheck(address.objectId, roleid))
2323  NameListToString(castNode(List, object)));
2324  break;
2325  case OBJECT_LARGEOBJECT:
2326  if (!lo_compat_privileges &&
2327  !pg_largeobject_ownercheck(address.objectId, roleid))
2328  ereport(ERROR,
2329  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2330  errmsg("must be owner of large object %u",
2331  address.objectId)));
2332  break;
2333  case OBJECT_CAST:
2334  {
2335  /* We can only check permissions on the source/target types */
2336  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2337  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2338  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2339  Oid targettypeid = typenameTypeId(NULL, targettype);
2340 
2341  if (!pg_type_ownercheck(sourcetypeid, roleid)
2342  && !pg_type_ownercheck(targettypeid, roleid))
2343  ereport(ERROR,
2344  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2345  errmsg("must be owner of type %s or type %s",
2346  format_type_be(sourcetypeid),
2347  format_type_be(targettypeid))));
2348  }
2349  break;
2350  case OBJECT_PUBLICATION:
2351  if (!pg_publication_ownercheck(address.objectId, roleid))
2353  strVal((Value *) object));
2354  break;
2355  case OBJECT_SUBSCRIPTION:
2356  if (!pg_subscription_ownercheck(address.objectId, roleid))
2358  strVal((Value *) object));
2359  break;
2360  case OBJECT_TRANSFORM:
2361  {
2362  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2363  Oid typeid = typenameTypeId(NULL, typename);
2364 
2365  if (!pg_type_ownercheck(typeid, roleid))
2367  }
2368  break;
2369  case OBJECT_TABLESPACE:
2370  if (!pg_tablespace_ownercheck(address.objectId, roleid))
2372  strVal((Value *) object));
2373  break;
2374  case OBJECT_TSDICTIONARY:
2375  if (!pg_ts_dict_ownercheck(address.objectId, roleid))
2377  NameListToString(castNode(List, object)));
2378  break;
2380  if (!pg_ts_config_ownercheck(address.objectId, roleid))
2382  NameListToString(castNode(List, object)));
2383  break;
2384  case OBJECT_ROLE:
2385 
2386  /*
2387  * We treat roles as being "owned" by those with CREATEROLE priv,
2388  * except that superusers are only owned by superusers.
2389  */
2390  if (superuser_arg(address.objectId))
2391  {
2392  if (!superuser_arg(roleid))
2393  ereport(ERROR,
2394  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2395  errmsg("must be superuser")));
2396  }
2397  else
2398  {
2399  if (!has_createrole_privilege(roleid))
2400  ereport(ERROR,
2401  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2402  errmsg("must have CREATEROLE privilege")));
2403  }
2404  break;
2405  case OBJECT_TSPARSER:
2406  case OBJECT_TSTEMPLATE:
2407  case OBJECT_ACCESS_METHOD:
2408  /* We treat these object types as being owned by superusers */
2409  if (!superuser_arg(roleid))
2410  ereport(ERROR,
2411  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2412  errmsg("must be superuser")));
2413  break;
2414  case OBJECT_STATISTIC_EXT:
2415  if (!pg_statistics_object_ownercheck(address.objectId, roleid))
2417  break;
2418  default:
2419  elog(ERROR, "unrecognized object type: %d",
2420  (int) objtype);
2421  }
2422 }
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:5376
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:5195
bool lo_compat_privileges
Definition: inv_api.c:57
bool pg_largeobject_ownercheck(Oid lobj_oid, Oid roleid)
Definition: aclchk.c:4884
bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid)
Definition: aclchk.c:5034
bool pg_language_ownercheck(Oid lan_oid, Oid roleid)
Definition: aclchk.c:4855
#define castNode(_type_, nodeptr)
Definition: nodes.h:586
bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid)
Definition: aclchk.c:5061
bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5115
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5289
#define strVal(v)
Definition: value.h:54
bool pg_oper_ownercheck(Oid oper_oid, Oid roleid)
Definition: aclchk.c:4803
int errcode(int sqlerrcode)
Definition: elog.c:575
char * format_type_be(Oid type_oid)
Definition: format_type.c:328
bool pg_namespace_ownercheck(Oid nsp_oid, Oid roleid)
Definition: aclchk.c:4927
unsigned int Oid
Definition: postgres_ext.h:31
bool pg_type_ownercheck(Oid type_oid, Oid roleid)
Definition: aclchk.c:4777
#define linitial_node(type, l)
Definition: pg_list.h:114
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3662
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3349
#define ERROR
Definition: elog.h:43
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:5142
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5247
#define RelationGetRelationName(relation)
Definition: rel.h:441
bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid)
Definition: aclchk.c:4953
bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
Definition: aclchk.c:5007
#define ereport(elevel, rest)
Definition: elog.h:122
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
Definition: aclchk.c:5169
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
char * NameListToString(List *names)
Definition: namespace.c:3082
#define lsecond_node(type, l)
Definition: pg_list.h:119
bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid)
Definition: aclchk.c:4980
bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid)
Definition: aclchk.c:5221
Definition: value.h:42
bool pg_class_ownercheck(Oid class_oid, Oid roleid)
Definition: aclchk.c:4751
bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5088
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
Definition: pg_list.h:45
#define RelationGetRelid(relation)
Definition: rel.h:407
bool pg_proc_ownercheck(Oid proc_oid, Oid roleid)
Definition: aclchk.c:4829
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:274
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5315
bool pg_statistics_object_ownercheck(Oid stat_oid, Oid roleid)
Definition: aclchk.c:5341

◆ get_catalog_object_by_oid()

HeapTuple get_catalog_object_by_oid ( Relation  catalog,
Oid  objectId 
)

Definition at line 2628 of file objectaddress.c.

References Assert, BTEqualStrategyNumber, get_object_catcache_oid(), get_object_oid_index(), heap_copytuple(), HeapTupleIsValid, ObjectIdAttributeNumber, 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().

2629 {
2630  HeapTuple tuple;
2631  Oid classId = RelationGetRelid(catalog);
2632  int oidCacheId = get_object_catcache_oid(classId);
2633 
2634  if (oidCacheId > 0)
2635  {
2636  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2637  if (!HeapTupleIsValid(tuple)) /* should not happen */
2638  return NULL;
2639  }
2640  else
2641  {
2642  Oid oidIndexId = get_object_oid_index(classId);
2643  SysScanDesc scan;
2644  ScanKeyData skey;
2645 
2646  Assert(OidIsValid(oidIndexId));
2647 
2648  ScanKeyInit(&skey,
2650  BTEqualStrategyNumber, F_OIDEQ,
2651  ObjectIdGetDatum(objectId));
2652 
2653  scan = systable_beginscan(catalog, oidIndexId, true,
2654  NULL, 1, &skey);
2655  tuple = systable_getnext(scan);
2656  if (!HeapTupleIsValid(tuple))
2657  {
2658  systable_endscan(scan);
2659  return NULL;
2660  }
2661  tuple = heap_copytuple(tuple);
2662 
2663  systable_endscan(scan);
2664  }
2665 
2666  return tuple;
2667 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:722
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:502
#define ObjectIdAttributeNumber
Definition: sysattr.h:22
Oid get_object_oid_index(Oid class_id)
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:605
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:331
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:419
#define ObjectIdGetDatum(X)
Definition: postgres.h:492
int get_object_catcache_oid(Oid class_id)
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:699
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:173
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define RelationGetRelid(relation)
Definition: rel.h:407
#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 797 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().

799 {
800  ObjectAddress address;
801  ObjectAddress old_address = {InvalidOid, InvalidOid, 0};
802  Relation relation = NULL;
803  uint64 inval_count;
804 
805  /* Some kind of lock must be taken. */
806  Assert(lockmode != NoLock);
807 
808  for (;;)
809  {
810  /*
811  * Remember this value, so that, after looking up the object name and
812  * locking it, we can check whether any invalidation messages have
813  * been processed that might require a do-over.
814  */
815  inval_count = SharedInvalidMessageCounter;
816 
817  /* Look up object address. */
818  switch (objtype)
819  {
820  case OBJECT_INDEX:
821  case OBJECT_SEQUENCE:
822  case OBJECT_TABLE:
823  case OBJECT_VIEW:
824  case OBJECT_MATVIEW:
826  address =
827  get_relation_by_qualified_name(objtype, castNode(List, object),
828  &relation, lockmode,
829  missing_ok);
830  break;
831  case OBJECT_COLUMN:
832  address =
833  get_object_address_attribute(objtype, castNode(List, object),
834  &relation, lockmode,
835  missing_ok);
836  break;
837  case OBJECT_DEFAULT:
838  address =
839  get_object_address_attrdef(objtype, castNode(List, object),
840  &relation, lockmode,
841  missing_ok);
842  break;
843  case OBJECT_RULE:
844  case OBJECT_TRIGGER:
846  case OBJECT_POLICY:
847  address = get_object_address_relobject(objtype, castNode(List, object),
848  &relation, missing_ok);
849  break;
851  {
852  List *objlist;
853  ObjectAddress domaddr;
854  char *constrname;
855 
856  objlist = castNode(List, object);
858  linitial_node(TypeName, objlist),
859  missing_ok);
860  constrname = strVal(lsecond(objlist));
861 
862  address.classId = ConstraintRelationId;
863  address.objectId = get_domain_constraint_oid(domaddr.objectId,
864  constrname, missing_ok);
865  address.objectSubId = 0;
866 
867  }
868  break;
869  case OBJECT_DATABASE:
870  case OBJECT_EXTENSION:
871  case OBJECT_TABLESPACE:
872  case OBJECT_ROLE:
873  case OBJECT_SCHEMA:
874  case OBJECT_LANGUAGE:
875  case OBJECT_FDW:
879  case OBJECT_PUBLICATION:
880  case OBJECT_SUBSCRIPTION:
881  address = get_object_address_unqualified(objtype,
882  (Value *) object, missing_ok);
883  break;
884  case OBJECT_TYPE:
885  case OBJECT_DOMAIN:
886  address = get_object_address_type(objtype, castNode(TypeName, object), missing_ok);
887  break;
888  case OBJECT_AGGREGATE:
889  case OBJECT_FUNCTION:
890  case OBJECT_PROCEDURE:
891  case OBJECT_ROUTINE:
892  address.classId = ProcedureRelationId;
893  address.objectId = LookupFuncWithArgs(objtype, castNode(ObjectWithArgs, object), missing_ok);
894  address.objectSubId = 0;
895  break;
896  case OBJECT_OPERATOR:
897  address.classId = OperatorRelationId;
898  address.objectId = LookupOperWithArgs(castNode(ObjectWithArgs, object), missing_ok);
899  address.objectSubId = 0;
900  break;
901  case OBJECT_COLLATION:
902  address.classId = CollationRelationId;
903  address.objectId = get_collation_oid(castNode(List, object), missing_ok);
904  address.objectSubId = 0;
905  break;
906  case OBJECT_CONVERSION:
907  address.classId = ConversionRelationId;
908  address.objectId = get_conversion_oid(castNode(List, object), missing_ok);
909  address.objectSubId = 0;
910  break;
911  case OBJECT_OPCLASS:
912  case OBJECT_OPFAMILY:
913  address = get_object_address_opcf(objtype, castNode(List, object), missing_ok);
914  break;
915  case OBJECT_AMOP:
916  case OBJECT_AMPROC:
917  address = get_object_address_opf_member(objtype, castNode(List, object), missing_ok);
918  break;
919  case OBJECT_LARGEOBJECT:
920  address.classId = LargeObjectRelationId;
921  address.objectId = oidparse(object);
922  address.objectSubId = 0;
923  if (!LargeObjectExists(address.objectId))
924  {
925  if (!missing_ok)
926  ereport(ERROR,
927  (errcode(ERRCODE_UNDEFINED_OBJECT),
928  errmsg("large object %u does not exist",
929  address.objectId)));
930  }
931  break;
932  case OBJECT_CAST:
933  {
934  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
935  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
936  Oid sourcetypeid;
937  Oid targettypeid;
938 
939  sourcetypeid = LookupTypeNameOid(NULL, sourcetype, missing_ok);
940  targettypeid = LookupTypeNameOid(NULL, targettype, missing_ok);
941  address.classId = CastRelationId;
942  address.objectId =
943  get_cast_oid(sourcetypeid, targettypeid, missing_ok);
944  address.objectSubId = 0;
945  }
946  break;
947  case OBJECT_TRANSFORM:
948  {
949  TypeName *typename = linitial_node(TypeName, castNode(List, object));
950  char *langname = strVal(lsecond(castNode(List, object)));
951  Oid type_id = LookupTypeNameOid(NULL, typename, missing_ok);
952  Oid lang_id = get_language_oid(langname, missing_ok);
953 
954  address.classId = TransformRelationId;
955  address.objectId =
956  get_transform_oid(type_id, lang_id, missing_ok);
957  address.objectSubId = 0;
958  }
959  break;
960  case OBJECT_TSPARSER:
961  address.classId = TSParserRelationId;
962  address.objectId = get_ts_parser_oid(castNode(List, object), missing_ok);
963  address.objectSubId = 0;
964  break;
965  case OBJECT_TSDICTIONARY:
966  address.classId = TSDictionaryRelationId;
967  address.objectId = get_ts_dict_oid(castNode(List, object), missing_ok);
968  address.objectSubId = 0;
969  break;
970  case OBJECT_TSTEMPLATE:
971  address.classId = TSTemplateRelationId;
972  address.objectId = get_ts_template_oid(castNode(List, object), missing_ok);
973  address.objectSubId = 0;
974  break;
976  address.classId = TSConfigRelationId;
977  address.objectId = get_ts_config_oid(castNode(List, object), missing_ok);
978  address.objectSubId = 0;
979  break;
980  case OBJECT_USER_MAPPING:
981  address = get_object_address_usermapping(castNode(List, object),
982  missing_ok);
983  break;
986  &relation,
987  missing_ok);
988  break;
989  case OBJECT_DEFACL:
990  address = get_object_address_defacl(castNode(List, object),
991  missing_ok);
992  break;
994  address.classId = StatisticExtRelationId;
995  address.objectId = get_statistics_object_oid(castNode(List, object),
996  missing_ok);
997  address.objectSubId = 0;
998  break;
999  default:
1000  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1001  /* placate compiler, in case it thinks elog might return */
1002  address.classId = InvalidOid;
1003  address.objectId = InvalidOid;
1004  address.objectSubId = 0;
1005  }
1006 
1007  /*
1008  * If we could not find the supplied object, return without locking.
1009  */
1010  if (!OidIsValid(address.objectId))
1011  {
1012  Assert(missing_ok);
1013  return address;
1014  }
1015 
1016  /*
1017  * If we're retrying, see if we got the same answer as last time. If
1018  * so, we're done; if not, we locked the wrong thing, so give up our
1019  * lock.
1020  */
1021  if (OidIsValid(old_address.classId))
1022  {
1023  if (old_address.classId == address.classId
1024  && old_address.objectId == address.objectId
1025  && old_address.objectSubId == address.objectSubId)
1026  break;
1027  if (old_address.classId != RelationRelationId)
1028  {
1029  if (IsSharedRelation(old_address.classId))
1030  UnlockSharedObject(old_address.classId,
1031  old_address.objectId,
1032  0, lockmode);
1033  else
1034  UnlockDatabaseObject(old_address.classId,
1035  old_address.objectId,
1036  0, lockmode);
1037  }
1038  }
1039 
1040  /*
1041  * If we're dealing with a relation or attribute, then the relation is
1042  * already locked. Otherwise, we lock it now.
1043  */
1044  if (address.classId != RelationRelationId)
1045  {
1046  if (IsSharedRelation(address.classId))
1047  LockSharedObject(address.classId, address.objectId, 0,
1048  lockmode);
1049  else
1050  LockDatabaseObject(address.classId, address.objectId, 0,
1051  lockmode);
1052  }
1053 
1054  /*
1055  * At this point, we've resolved the name to an OID and locked the
1056  * corresponding database object. However, it's possible that by the
1057  * time we acquire the lock on the object, concurrent DDL has modified
1058  * the database in such a way that the name we originally looked up no
1059  * longer resolves to that OID.
1060  *
1061  * We can be certain that this isn't an issue if (a) no shared
1062  * invalidation messages have been processed or (b) we've locked a
1063  * relation somewhere along the line. All the relation name lookups
1064  * in this module ultimately use RangeVarGetRelid() to acquire a
1065  * relation lock, and that function protects against the same kinds of
1066  * races we're worried about here. Even when operating on a
1067  * constraint, rule, or trigger, we still acquire AccessShareLock on
1068  * the relation, which is enough to freeze out any concurrent DDL.
1069  *
1070  * In all other cases, however, it's possible that the name we looked
1071  * up no longer refers to the object we locked, so we retry the lookup
1072  * and see whether we get the same answer.
1073  */
1074  if (inval_count == SharedInvalidMessageCounter || relation != NULL)
1075  break;
1076  old_address = address;
1077  }
1078 
1079  /* Return the object address and the relation. */
1080  *relp = relation;
1081  return address;
1082 }
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:586
Oid get_language_oid(const char *langname, bool missing_ok)
Definition: proclang.c:549
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
Oid get_ts_config_oid(List *names, bool missing_ok)
Definition: namespace.c:2658
unsigned int Oid
Definition: postgres_ext.h:31
#define linitial_node(type, l)
Definition: pg_list.h:114
static ObjectAddress get_object_address_unqualified(ObjectType objtype, Value *strval, bool missing_ok)
#define OidIsValid(objectId)
Definition: c.h:605
#define lsecond(l)
Definition: pg_list.h:116
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:2405
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:918
Oid get_statistics_object_oid(List *names, bool missing_ok)
Definition: namespace.c:2157
Oid get_ts_template_oid(List *names, bool missing_ok)
Definition: namespace.c:2532
#define NoLock
Definition: lockdefs.h:34
Oid LookupFuncWithArgs(ObjectType objtype, ObjectWithArgs *func, bool noError)
Definition: parse_func.c:2041
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:856
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:122
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:877
#define lsecond_node(type, l)
Definition: pg_list.h:119
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:220
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:897
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:2279
#define Assert(condition)
Definition: c.h:699
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:3566
bool LargeObjectExists(Oid loid)
int errmsg(const char *fmt,...)
Definition: elog.c:797
Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok)
#define elog
Definition: elog.h:219
Oid get_collation_oid(List *name, bool missing_ok)
Definition: namespace.c:3512
Definition: pg_list.h:45
Oid LookupTypeNameOid(ParseState *pstate, const TypeName *typeName, bool missing_ok)
Definition: parse_type.c:215

◆ get_object_address_attrdef()

static ObjectAddress get_object_address_attrdef ( ObjectType  objtype,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
static

Definition at line 1412 of file objectaddress.c.

References AccessShareLock, attname, attnum, AttrDefaultIndexId, BTEqualStrategyNumber, ObjectAddress::classId, tupleDesc::constr, ereport, errcode(), errmsg(), ERROR, get_attnum(), HeapTupleGetOid, HeapTupleIsValid, Int16GetDatum, InvalidAttrNumber, InvalidOid, list_copy(), list_length(), list_truncate(), llast, makeRangeVarFromNameList(), NameListToString(), ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, OidIsValid, relation_close(), relation_open(), relation_openrv(), RelationGetDescr, RelationGetRelid, ScanKeyInit(), strVal, systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by get_object_address().

1415 {
1416  ObjectAddress address;
1417  List *relname;
1418  Oid reloid;
1419  Relation relation;
1420  const char *attname;
1422  TupleDesc tupdesc;
1423  Oid defoid;
1424 
1425  /* Extract relation name and open relation. */
1426  if (list_length(object) < 2)
1427  ereport(ERROR,
1428  (errcode(ERRCODE_SYNTAX_ERROR),
1429  errmsg("column name must be qualified")));
1430  attname = strVal(llast(object));
1431  relname = list_truncate(list_copy(object), list_length(object) - 1);
1432  /* XXX no missing_ok support here */
1433  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1434  reloid = RelationGetRelid(relation);
1435 
1436  tupdesc = RelationGetDescr(relation);
1437 
1438  /* Look up attribute number and scan pg_attrdef to find its tuple */
1439  attnum = get_attnum(reloid, attname);
1440  defoid = InvalidOid;
1441  if (attnum != InvalidAttrNumber && tupdesc->constr != NULL)
1442  {
1443  Relation attrdef;
1444  ScanKeyData keys[2];
1445  SysScanDesc scan;
1446  HeapTuple tup;
1447 
1448  attrdef = relation_open(AttrDefaultRelationId, AccessShareLock);
1449  ScanKeyInit(&keys[0],
1450  Anum_pg_attrdef_adrelid,
1452  F_OIDEQ,
1453  ObjectIdGetDatum(reloid));
1454  ScanKeyInit(&keys[1],
1455  Anum_pg_attrdef_adnum,
1457  F_INT2EQ,
1458  Int16GetDatum(attnum));
1459  scan = systable_beginscan(attrdef, AttrDefaultIndexId, true,
1460  NULL, 2, keys);
1461  if (HeapTupleIsValid(tup = systable_getnext(scan)))
1462  defoid = HeapTupleGetOid(tup);
1463 
1464  systable_endscan(scan);
1465  relation_close(attrdef, AccessShareLock);
1466  }
1467  if (!OidIsValid(defoid))
1468  {
1469  if (!missing_ok)
1470  ereport(ERROR,
1471  (errcode(ERRCODE_UNDEFINED_COLUMN),
1472  errmsg("default value for column \"%s\" of relation \"%s\" does not exist",
1473  attname, NameListToString(relname))));
1474 
1475  address.classId = AttrDefaultRelationId;
1476  address.objectId = InvalidOid;
1477  address.objectSubId = InvalidAttrNumber;
1478  relation_close(relation, lockmode);
1479  return address;
1480  }
1481 
1482  address.classId = AttrDefaultRelationId;
1483  address.objectId = defoid;
1484  address.objectSubId = 0;
1485 
1486  *relp = relation;
1487  return address;
1488 }
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: heapam.c:1202
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:502
#define RelationGetDescr(relation)
Definition: rel.h:433
#define llast(l)
Definition: pg_list.h:131
#define Int16GetDatum(X)
Definition: postgres.h:436
List * list_truncate(List *list, int new_size)
Definition: list.c:350
#define AccessShareLock
Definition: lockdefs.h:36
List * list_copy(const List *oldlist)
Definition: list.c:1160
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: heapam.c:1270
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3042
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:605
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:331
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:419
#define ObjectIdGetDatum(X)
Definition: postgres.h:492
#define ERROR
Definition: elog.h:43
NameData attname
Definition: pg_attribute.h:40
#define AttrDefaultIndexId
Definition: indexing.h:86
AttrNumber get_attnum(Oid relid, const char *attname)
Definition: lsyscache.c:806
#define ereport(elevel, rest)
Definition: elog.h:122
char * NameListToString(List *names)
Definition: namespace.c:3082
#define InvalidOid
Definition: postgres_ext.h:36
int16 attnum
Definition: pg_attribute.h:79
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
TupleConstr * constr
Definition: tupdesc.h:87
static int list_length(const List *l)
Definition: pg_list.h:89
#define InvalidAttrNumber
Definition: attnum.h:23
int errmsg(const char *fmt,...)
Definition: elog.c:797
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1124
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:707
Definition: pg_list.h:45
int16 AttrNumber
Definition: attnum.h:21
#define RelationGetRelid(relation)
Definition: rel.h:407
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ get_object_address_attribute()

static ObjectAddress get_object_address_attribute ( ObjectType  objtype,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
static

Definition at line 1361 of file objectaddress.c.

References attname, attnum, ObjectAddress::classId, ereport, errcode(), errmsg(), ERROR, get_attnum(), InvalidAttrNumber, InvalidOid, lfirst, list_copy(), list_length(), list_tail(), list_truncate(), makeRangeVarFromNameList(), NameListToString(), ObjectAddress::objectId, ObjectAddress::objectSubId, relation_close(), relation_openrv(), RelationGetRelid, and strVal.

Referenced by get_object_address().

1364 {
1365  ObjectAddress address;
1366  List *relname;
1367  Oid reloid;
1368  Relation relation;
1369  const char *attname;
1371 
1372  /* Extract relation name and open relation. */
1373  if (list_length(object) < 2)
1374  ereport(ERROR,
1375  (errcode(ERRCODE_SYNTAX_ERROR),
1376  errmsg("column name must be qualified")));
1377  attname = strVal(lfirst(list_tail(object)));
1378  relname = list_truncate(list_copy(object), list_length(object) - 1);
1379  /* XXX no missing_ok support here */
1380  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1381  reloid = RelationGetRelid(relation);
1382 
1383  /* Look up attribute and construct return value. */
1384  attnum = get_attnum(reloid, attname);
1385  if (attnum == InvalidAttrNumber)
1386  {
1387  if (!missing_ok)
1388  ereport(ERROR,
1389  (errcode(ERRCODE_UNDEFINED_COLUMN),
1390  errmsg("column \"%s\" of relation \"%s\" does not exist",
1391  attname, NameListToString(relname))));
1392 
1393  address.classId = RelationRelationId;
1394  address.objectId = InvalidOid;
1395  address.objectSubId = InvalidAttrNumber;
1396  relation_close(relation, lockmode);
1397  return address;
1398  }
1399 
1400  address.classId = RelationRelationId;
1401  address.objectId = reloid;
1402  address.objectSubId = attnum;
1403 
1404  *relp = relation;
1405  return address;
1406 }
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: heapam.c:1202
List * list_truncate(List *list, int new_size)
Definition: list.c:350
List * list_copy(const List *oldlist)
Definition: list.c:1160
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: heapam.c:1270
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3042
unsigned int Oid
Definition: postgres_ext.h:31
static ListCell * list_tail(List *l)
Definition: pg_list.h:83
#define ERROR
Definition: elog.h:43
NameData attname
Definition: pg_attribute.h:40
AttrNumber get_attnum(Oid relid, const char *attname)
Definition: lsyscache.c:806
#define ereport(elevel, rest)
Definition: elog.h:122
char * NameListToString(List *names)
Definition: namespace.c:3082
#define InvalidOid
Definition: postgres_ext.h:36
int16 attnum
Definition: pg_attribute.h:79
#define lfirst(lc)
Definition: pg_list.h:106
static int list_length(const List *l)
Definition: pg_list.h:89
#define InvalidAttrNumber
Definition: attnum.h:23
int errmsg(const char *fmt,...)
Definition: elog.c:797
Definition: pg_list.h:45
int16 AttrNumber
Definition: attnum.h:21
#define RelationGetRelid(relation)
Definition: rel.h:407

◆ get_object_address_defacl()

static ObjectAddress get_object_address_defacl ( List object,
bool  missing_ok 
)
static

Definition at line 1806 of file objectaddress.c.

References AUTHNAME, CharGetDatum, CStringGetDatum, DEFACLROLENSPOBJ, ereport, errcode(), errhint(), errmsg(), ERROR, get_namespace_oid(), HeapTupleGetOid, HeapTupleIsValid, InvalidOid, linitial, list_length(), lsecond, lthird, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache1(), SearchSysCache3(), strVal, and username.

Referenced by get_object_address().

1807 {
1808  HeapTuple tp;
1809  Oid userid;
1810  Oid schemaid;
1811  char *username;
1812  char *schema;
1813  char objtype;
1814  char *objtype_str;
1815  ObjectAddress address;
1816 
1817  ObjectAddressSet(address, DefaultAclRelationId, InvalidOid);
1818 
1819  /*
1820  * First figure out the textual attributes so that they can be used for
1821  * error reporting.
1822  */
1823  username = strVal(lsecond(object));
1824  if (list_length(object) >= 3)
1825  schema = (char *) strVal(lthird(object));
1826  else
1827  schema = NULL;
1828 
1829  /*
1830  * Decode defaclobjtype. Only first char is considered; the rest of the
1831  * string, if any, is blissfully ignored.
1832  */
1833  objtype = ((char *) strVal(linitial(object)))[0];
1834  switch (objtype)
1835  {
1836  case DEFACLOBJ_RELATION:
1837  objtype_str = "tables";
1838  break;
1839  case DEFACLOBJ_SEQUENCE:
1840  objtype_str = "sequences";
1841  break;
1842  case DEFACLOBJ_FUNCTION:
1843  objtype_str = "functions";
1844  break;
1845  case DEFACLOBJ_TYPE:
1846  objtype_str = "types";
1847  break;
1848  case DEFACLOBJ_NAMESPACE:
1849  objtype_str = "schemas";
1850  break;
1851  default:
1852  ereport(ERROR,
1853  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1854  errmsg("unrecognized default ACL object type \"%c\"", objtype),
1855  errhint("Valid object types are \"%c\", \"%c\", \"%c\", \"%c\", \"%c\".",
1856  DEFACLOBJ_RELATION,
1857  DEFACLOBJ_SEQUENCE,
1858  DEFACLOBJ_FUNCTION,
1859  DEFACLOBJ_TYPE,
1860  DEFACLOBJ_NAMESPACE)));
1861  }
1862 
1863  /*
1864  * Look up user ID. Behave as "default ACL not found" if the user doesn't
1865  * exist.
1866  */
1868  CStringGetDatum(username));
1869  if (!HeapTupleIsValid(tp))
1870  goto not_found;
1871  userid = HeapTupleGetOid(tp);
1872  ReleaseSysCache(tp);
1873 
1874  /*
1875  * If a schema name was given, look up its OID. If it doesn't exist,
1876  * behave as "default ACL not found".
1877  */
1878  if (schema)
1879  {
1880  schemaid = get_namespace_oid(schema, true);
1881  if (schemaid == InvalidOid)
1882  goto not_found;
1883  }
1884  else
1885  schemaid = InvalidOid;
1886 
1887  /* Finally, look up the pg_default_acl object */
1889  ObjectIdGetDatum(userid),
1890  ObjectIdGetDatum(schemaid),
1891  CharGetDatum(objtype));
1892  if (!HeapTupleIsValid(tp))
1893  goto not_found;
1894 
1895  address.objectId = HeapTupleGetOid(tp);
1896  ReleaseSysCache(tp);
1897 
1898  return address;
1899 
1900 not_found:
1901  if (!missing_ok)
1902  {
1903  if (schema)
1904  ereport(ERROR,
1905  (errcode(ERRCODE_UNDEFINED_OBJECT),
1906  errmsg("default ACL for user \"%s\" in schema \"%s\" on %s does not exist",
1907  username, schema, objtype_str)));
1908  else
1909  ereport(ERROR,
1910  (errcode(ERRCODE_UNDEFINED_OBJECT),
1911  errmsg("default ACL for user \"%s\" on %s does not exist",
1912  username, objtype_str)));
1913  }
1914  return address;
1915 }
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3024
int errhint(const char *fmt,...)
Definition: elog.c:987
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define lsecond(l)
Definition: pg_list.h:116
#define linitial(l)
Definition: pg_list.h:111
#define ObjectIdGetDatum(X)
Definition: postgres.h:492
#define ERROR
Definition: elog.h:43
HeapTuple SearchSysCache3(int cacheId, Datum key1, Datum key2, Datum key3)
Definition: syscache.c:1134
#define CStringGetDatum(X)
Definition: postgres.h:563
#define ereport(elevel, rest)
Definition: elog.h:122
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
static char * username
Definition: initdb.c:132
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static int list_length(const List *l)
Definition: pg_list.h:89
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
#define CharGetDatum(X)
Definition: postgres.h:401
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define lthird(l)
Definition: pg_list.h:121
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:707

◆ get_object_address_opcf()

static ObjectAddress get_object_address_opcf ( ObjectType  objtype,
List object,
bool  missing_ok 
)
static

Definition at line 1533 of file objectaddress.c.

References ObjectAddress::classId, elog, ERROR, get_index_am_oid(), get_opclass_oid(), get_opfamily_oid(), InvalidOid, linitial, list_copy_tail(), OBJECT_OPCLASS, OBJECT_OPFAMILY, ObjectAddress::objectId, ObjectAddress::objectSubId, and strVal.

Referenced by get_object_address(), and get_object_address_opf_member().

1534 {
1535  Oid amoid;
1536  ObjectAddress address;
1537 
1538  /* XXX no missing_ok support here */
1539  amoid = get_index_am_oid(strVal(linitial(object)), false);
1540  object = list_copy_tail(object, 1);
1541 
1542  switch (objtype)
1543  {
1544  case OBJECT_OPCLASS:
1545  address.classId = OperatorClassRelationId;
1546  address.objectId = get_opclass_oid(amoid, object, missing_ok);
1547  address.objectSubId = 0;
1548  break;
1549  case OBJECT_OPFAMILY:
1550  address.classId = OperatorFamilyRelationId;
1551  address.objectId = get_opfamily_oid(amoid, object, missing_ok);
1552  address.objectSubId = 0;
1553  break;
1554  default:
1555  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1556  /* placate compiler, which doesn't know elog won't return */
1557  address.classId = InvalidOid;
1558  address.objectId = InvalidOid;
1559  address.objectSubId = 0;
1560  }
1561 
1562  return address;
1563 }
#define strVal(v)
Definition: value.h:54
Oid get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
Definition: opclasscmds.c:221
List * list_copy_tail(const List *oldlist, int nskip)
Definition: list.c:1203
unsigned int Oid
Definition: postgres_ext.h:31
#define linitial(l)
Definition: pg_list.h:111
#define ERROR
Definition: elog.h:43
Oid get_index_am_oid(const char *amname, bool missing_ok)
Definition: amcmds.c:183
#define InvalidOid
Definition: postgres_ext.h:36
Oid get_opfamily_oid(Oid amID, List *opfamilyname, bool missing_ok)
Definition: opclasscmds.c:142
#define elog
Definition: elog.h:219

◆ get_object_address_opf_member()

static ObjectAddress get_object_address_opf_member ( ObjectType  objtype,
List object,
bool  missing_ok 
)
static

Definition at line 1571 of file objectaddress.c.

References AMOPSTRATEGY, AMPROCNUM, elog, ereport, errcode(), errmsg(), ERROR, get_object_address_opcf(), get_object_address_type(), getObjectDescription(), HeapTupleGetOid, HeapTupleIsValid, i, Int16GetDatum, InvalidOid, lfirst_node, linitial, list_copy(), list_length(), list_truncate(), llast, lsecond, OBJECT_AMOP, OBJECT_AMPROC, OBJECT_OPFAMILY, OBJECT_TYPE, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache4(), strVal, and TypeNameToString().

Referenced by get_object_address().

1573 {
1574  ObjectAddress famaddr;
1575  ObjectAddress address;
1576  ListCell *cell;
1577  List *copy;
1578  TypeName *typenames[2];
1579  Oid typeoids[2];
1580  int membernum;
1581  int i;
1582 
1583  /*
1584  * The last element of the object list contains the strategy or procedure
1585  * number. We need to strip that out before getting the opclass/family
1586  * address. The rest can be used directly by get_object_address_opcf().
1587  */
1588  membernum = atoi(strVal(llast(linitial(object))));
1589  copy = list_truncate(list_copy(linitial(object)), list_length(linitial(object)) - 1);
1590 
1591  /* no missing_ok support here */
1592  famaddr = get_object_address_opcf(OBJECT_OPFAMILY, copy, false);
1593 
1594  /* find out left/right type names and OIDs */
1595  typenames[0] = typenames[1] = NULL;
1596  typeoids[0] = typeoids[1] = InvalidOid;
1597  i = 0;
1598  foreach(cell, lsecond(object))
1599  {
1600  ObjectAddress typaddr;
1601 
1602  typenames[i] = lfirst_node(TypeName, cell);
1603  typaddr = get_object_address_type(OBJECT_TYPE, typenames[i], missing_ok);
1604  typeoids[i] = typaddr.objectId;
1605  if (++i >= 2)
1606  break;
1607  }
1608 
1609  switch (objtype)
1610  {
1611  case OBJECT_AMOP:
1612  {
1613  HeapTuple tp;
1614 
1615  ObjectAddressSet(address, AccessMethodOperatorRelationId,
1616  InvalidOid);
1617 
1619  ObjectIdGetDatum(famaddr.objectId),
1620  ObjectIdGetDatum(typeoids[0]),
1621  ObjectIdGetDatum(typeoids[1]),
1622  Int16GetDatum(membernum));
1623  if (!HeapTupleIsValid(tp))
1624  {
1625  if (!missing_ok)
1626  ereport(ERROR,
1627  (errcode(ERRCODE_UNDEFINED_OBJECT),
1628  errmsg("operator %d (%s, %s) of %s does not exist",
1629  membernum,
1630  TypeNameToString(typenames[0]),
1631  TypeNameToString(typenames[1]),
1632  getObjectDescription(&famaddr))));
1633  }
1634  else
1635  {
1636  address.objectId = HeapTupleGetOid(tp);
1637  ReleaseSysCache(tp);
1638  }
1639  }
1640  break;
1641 
1642  case OBJECT_AMPROC:
1643  {
1644  HeapTuple tp;
1645 
1646  ObjectAddressSet(address, AccessMethodProcedureRelationId,
1647  InvalidOid);
1648 
1650  ObjectIdGetDatum(famaddr.objectId),
1651  ObjectIdGetDatum(typeoids[0]),
1652  ObjectIdGetDatum(typeoids[1]),
1653  Int16GetDatum(membernum));
1654  if (!HeapTupleIsValid(tp))
1655  {
1656  if (!missing_ok)
1657  ereport(ERROR,
1658  (errcode(ERRCODE_UNDEFINED_OBJECT),
1659  errmsg("function %d (%s, %s) of %s does not exist",
1660  membernum,
1661  TypeNameToString(typenames[0]),
1662  TypeNameToString(typenames[1]),
1663  getObjectDescription(&famaddr))));
1664  }
1665  else
1666  {
1667  address.objectId = HeapTupleGetOid(tp);
1668  ReleaseSysCache(tp);
1669  }
1670  }
1671  break;
1672  default:
1673  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1674  }
1675 
1676  return address;
1677 }
char * TypeNameToString(const TypeName *typeName)
Definition: parse_type.c:459
#define llast(l)
Definition: pg_list.h:131
#define Int16GetDatum(X)
Definition: postgres.h:436
List * list_truncate(List *list, int new_size)
Definition: list.c:350
List * list_copy(const List *oldlist)
Definition: list.c:1160
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define lsecond(l)
Definition: pg_list.h:116
char * getObjectDescription(const ObjectAddress *object)
#define linitial(l)
Definition: pg_list.h:111
#define ObjectIdGetDatum(X)
Definition: postgres.h:492
#define ERROR
Definition: elog.h:43
#define lfirst_node(type, lc)
Definition: pg_list.h:109
static ObjectAddress get_object_address_type(ObjectType objtype, TypeName *typename, bool missing_ok)
static ObjectAddress get_object_address_opcf(ObjectType objtype, List *object, bool missing_ok)
HeapTuple SearchSysCache4(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
Definition: syscache.c:1145
#define ereport(elevel, rest)
Definition: elog.h:122
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static int list_length(const List *l)
Definition: pg_list.h:89
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
int errmsg(const char *fmt,...)
Definition: elog.c:797
int i
#define elog
Definition: elog.h:219
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:707
Definition: pg_list.h:45

◆ get_object_address_publication_rel()

static ObjectAddress get_object_address_publication_rel ( List object,
Relation relp,
bool  missing_ok 
)
static

Definition at line 1754 of file objectaddress.c.

References AccessShareLock, ereport, errcode(), errmsg(), ERROR, GetPublicationByName(), GetSysCacheOid2, InvalidOid, linitial, lsecond, makeRangeVarFromNameList(), ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum, Publication::oid, OidIsValid, PUBLICATIONRELMAP, relation_close(), relation_openrv_extended(), RelationGetRelationName, RelationGetRelid, and strVal.

Referenced by get_object_address().

1756 {
1757  ObjectAddress address;
1758  Relation relation;
1759  List *relname;
1760  char *pubname;
1761  Publication *pub;
1762 
1763  ObjectAddressSet(address, PublicationRelRelationId, InvalidOid);
1764 
1765  relname = linitial(object);
1767  AccessShareLock, missing_ok);
1768  if (!relation)
1769  return address;
1770 
1771  /* fetch publication name from input list */
1772  pubname = strVal(lsecond(object));
1773 
1774  /* Now look up the pg_publication tuple */
1775  pub = GetPublicationByName(pubname, missing_ok);
1776  if (!pub)
1777  {
1778  relation_close(relation, AccessShareLock);
1779  return address;
1780  }
1781 
1782  /* Find the publication relation mapping in syscache. */
1783  address.objectId =
1786  ObjectIdGetDatum(pub->oid));
1787  if (!OidIsValid(address.objectId))
1788  {
1789  if (!missing_ok)
1790  ereport(ERROR,
1791  (errcode(ERRCODE_UNDEFINED_OBJECT),
1792  errmsg("publication relation \"%s\" in publication \"%s\" does not exist",
1793  RelationGetRelationName(relation), pubname)));
1794  relation_close(relation, AccessShareLock);
1795  return address;
1796  }
1797 
1798  *relp = relation;
1799  return address;
1800 }
#define AccessShareLock
Definition: lockdefs.h:36
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: heapam.c:1270
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3042
#define OidIsValid(objectId)
Definition: c.h:605
Publication * GetPublicationByName(const char *pubname, bool missing_ok)
#define lsecond(l)
Definition: pg_list.h:116
#define GetSysCacheOid2(cacheId, key1, key2)
Definition: syscache.h:193
#define linitial(l)
Definition: pg_list.h:111
#define ObjectIdGetDatum(X)
Definition: postgres.h:492
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:441
#define ereport(elevel, rest)
Definition: elog.h:122
#define InvalidOid
Definition: postgres_ext.h:36
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
int errmsg(const char *fmt,...)
Definition: elog.c:797
Definition: pg_list.h:45
#define RelationGetRelid(relation)
Definition: rel.h:407
Relation relation_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: heapam.c:1237

◆ get_object_address_relobject()

static ObjectAddress get_object_address_relobject ( ObjectType  objtype,
List object,
Relation relp,
bool  missing_ok 
)
static

Definition at line 1282 of file objectaddress.c.

References AccessShareLock, ObjectAddress::classId, elog, ereport, errcode(), errmsg(), ERROR, get_relation_constraint_oid(), get_relation_policy_oid(), get_rewrite_oid(), get_trigger_oid(), heap_close, heap_openrv_extended(), InvalidOid, list_copy(), list_length(), list_truncate(), llast, makeRangeVarFromNameList(), OBJECT_POLICY, OBJECT_RULE, OBJECT_TABCONSTRAINT, OBJECT_TRIGGER, ObjectAddress::objectId, ObjectAddress::objectSubId, OidIsValid, RelationGetRelid, and strVal.

Referenced by get_object_address().

1284 {
1285  ObjectAddress address;
1286  Relation relation = NULL;
1287  int nnames;
1288  const char *depname;
1289  List *relname;
1290  Oid reloid;
1291 
1292  /* Extract name of dependent object. */
1293  depname = strVal(llast(object));
1294 
1295  /* Separate relation name from dependent object name. */
1296  nnames = list_length(object);
1297  if (nnames < 2)
1298  ereport(ERROR,
1299  (errcode(ERRCODE_SYNTAX_ERROR),
1300  errmsg("must specify relation and object name")));
1301 
1302  /* Extract relation name and open relation. */
1303  relname = list_truncate(list_copy(object), nnames - 1);
1304  relation = heap_openrv_extended(makeRangeVarFromNameList(relname),
1306  missing_ok);
1307 
1308  reloid = relation ? RelationGetRelid(relation) : InvalidOid;
1309 
1310  switch (objtype)
1311  {
1312  case OBJECT_RULE:
1313  address.classId = RewriteRelationId;
1314  address.objectId = relation ?
1315  get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
1316  address.objectSubId = 0;
1317  break;
1318  case OBJECT_TRIGGER:
1319  address.classId = TriggerRelationId;
1320  address.objectId = relation ?
1321  get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
1322  address.objectSubId = 0;
1323  break;
1324  case OBJECT_TABCONSTRAINT:
1325  address.classId = ConstraintRelationId;
1326  address.objectId = relation ?
1327  get_relation_constraint_oid(reloid, depname, missing_ok) :
1328  InvalidOid;
1329  address.objectSubId = 0;
1330  break;
1331  case OBJECT_POLICY:
1332  address.classId = PolicyRelationId;
1333  address.objectId = relation ?
1334  get_relation_policy_oid(reloid, depname, missing_ok) :
1335  InvalidOid;
1336  address.objectSubId = 0;
1337  break;
1338  default:
1339  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1340  }
1341 
1342  /* Avoid relcache leak when object not found. */
1343  if (!OidIsValid(address.objectId))
1344  {
1345  if (relation != NULL)
1346  heap_close(relation, AccessShareLock);
1347 
1348  relation = NULL; /* department of accident prevention */
1349  return address;
1350  }
1351 
1352  /* Done. */
1353  *relp = relation;
1354  return address;
1355 }
Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok)
#define llast(l)
Definition: pg_list.h:131
List * list_truncate(List *list, int new_size)
Definition: list.c:350
#define AccessShareLock
Definition: lockdefs.h:36
List * list_copy(const List *oldlist)
Definition: list.c:1160
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3042
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:605
Relation heap_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: heapam.c:1353
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define InvalidOid
Definition: postgres_ext.h:36
Oid get_relation_policy_oid(Oid relid, const char *policy_name, bool missing_ok)
Definition: policy.c:1314
static int list_length(const List *l)
Definition: pg_list.h:89
Oid get_trigger_oid(Oid relid, const char *trigname, bool missing_ok)
Definition: trigger.c:1559
Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok)
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
Definition: pg_list.h:45
#define RelationGetRelid(relation)
Definition: rel.h:407

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

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

Referenced by ExecAlterObjectDependsStmt().

1095 {
1096  if (rel)
1097  {
1098  object = lcons(makeString(rel->relname), object);
1099  if (rel->schemaname)
1100  object = lcons(makeString(rel->schemaname), object);
1101  if (rel->catalogname)
1102  object = lcons(makeString(rel->catalogname), object);
1103  }
1104 
1105  return get_object_address(objtype, (Node *) object,
1106  relp, lockmode, missing_ok);
1107 }
Value * makeString(char *str)
Definition: value.c:53
Definition: nodes.h:517
char * schemaname
Definition: primnodes.h:68
char * relname
Definition: primnodes.h:69
List * lcons(void *datum, List *list)
Definition: list.c:259
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
char * catalogname
Definition: primnodes.h:67

◆ get_object_address_type()

static ObjectAddress get_object_address_type ( ObjectType  objtype,
TypeName typename,
bool  missing_ok 
)
static

Definition at line 1494 of file objectaddress.c.

References ObjectAddress::classId, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, HeapTupleIsValid, InvalidOid, LookupTypeName(), OBJECT_DOMAIN, ObjectAddress::objectId, ObjectAddress::objectSubId, ReleaseSysCache(), TypeNameToString(), and typeTypeId().

Referenced by get_object_address(), and get_object_address_opf_member().

1495 {
1496  ObjectAddress address;
1497  Type tup;
1498 
1499  address.classId = TypeRelationId;
1500  address.objectId = InvalidOid;
1501  address.objectSubId = 0;
1502 
1503  tup = LookupTypeName(NULL, typename, NULL, missing_ok);
1504  if (!HeapTupleIsValid(tup))
1505  {
1506  if (!missing_ok)
1507  ereport(ERROR,
1508  (errcode(ERRCODE_UNDEFINED_OBJECT),
1509  errmsg("type \"%s\" does not exist",
1510  TypeNameToString(typename))));
1511  return address;
1512  }
1513  address.objectId = typeTypeId(tup);
1514 
1515  if (objtype == OBJECT_DOMAIN)
1516  {
1517  if (((Form_pg_type) GETSTRUCT(tup))->typtype != TYPTYPE_DOMAIN)
1518  ereport(ERROR,
1519  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1520  errmsg("\"%s\" is not a domain",
1521  TypeNameToString(typename))));
1522  }
1523 
1524  ReleaseSysCache(tup);
1525 
1526  return address;
1527 }
Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:57
#define GETSTRUCT(TUP)
Definition: htup_details.h:668
char * TypeNameToString(const TypeName *typeName)
Definition: parse_type.c:459
int errcode(int sqlerrcode)
Definition: elog.c:575
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
FormData_pg_type * Form_pg_type
Definition: pg_type.h:247
int errmsg(const char *fmt,...)
Definition: elog.c:797
Oid typeTypeId(Type tp)
Definition: parse_type.c:571

◆ get_object_address_unqualified()

static ObjectAddress get_object_address_unqualified ( ObjectType  objtype,
Value strval,
bool  missing_ok 
)
static

Definition at line 1114 of file objectaddress.c.

References ObjectAddress::classId, elog, ERROR, get_am_oid(), get_database_oid(), get_event_trigger_oid(), get_extension_oid(), get_foreign_data_wrapper_oid(), get_foreign_server_oid(), get_language_oid(), get_namespace_oid(), get_publication_oid(), get_role_oid(), get_subscription_oid(), get_tablespace_oid(), InvalidOid, name, OBJECT_ACCESS_METHOD, OBJECT_DATABASE, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_LANGUAGE, OBJECT_PUBLICATION, OBJECT_ROLE, OBJECT_SCHEMA, OBJECT_SUBSCRIPTION, OBJECT_TABLESPACE, ObjectAddress::objectId, ObjectAddress::objectSubId, and strVal.

Referenced by get_object_address().

1116 {
1117  const char *name;
1118  ObjectAddress address;
1119 
1120  name = strVal(strval);
1121 
1122  /* Translate name to OID. */
1123  switch (objtype)
1124  {
1125  case OBJECT_ACCESS_METHOD:
1126  address.classId = AccessMethodRelationId;
1127  address.objectId = get_am_oid(name, missing_ok);
1128  address.objectSubId = 0;
1129  break;
1130  case OBJECT_DATABASE:
1131  address.classId = DatabaseRelationId;
1132  address.objectId = get_database_oid(name, missing_ok);
1133  address.objectSubId = 0;
1134  break;
1135  case OBJECT_EXTENSION:
1136  address.classId = ExtensionRelationId;
1137  address.objectId = get_extension_oid(name, missing_ok);
1138  address.objectSubId = 0;
1139  break;
1140  case OBJECT_TABLESPACE:
1141  address.classId = TableSpaceRelationId;
1142  address.objectId = get_tablespace_oid(name, missing_ok);
1143  address.objectSubId = 0;
1144  break;
1145  case OBJECT_ROLE:
1146  address.classId = AuthIdRelationId;
1147  address.objectId = get_role_oid(name, missing_ok);
1148  address.objectSubId = 0;
1149  break;
1150  case OBJECT_SCHEMA:
1151  address.classId = NamespaceRelationId;
1152  address.objectId = get_namespace_oid(name, missing_ok);
1153  address.objectSubId = 0;
1154  break;
1155  case OBJECT_LANGUAGE:
1156  address.classId = LanguageRelationId;
1157  address.objectId = get_language_oid(name, missing_ok);
1158  address.objectSubId = 0;
1159  break;
1160  case OBJECT_FDW:
1161  address.classId = ForeignDataWrapperRelationId;
1162  address.objectId = get_foreign_data_wrapper_oid(name, missing_ok);
1163  address.objectSubId = 0;
1164  break;
1165  case OBJECT_FOREIGN_SERVER:
1166  address.classId = ForeignServerRelationId;
1167  address.objectId = get_foreign_server_oid(name, missing_ok);
1168  address.objectSubId = 0;
1169  break;
1170  case OBJECT_EVENT_TRIGGER:
1171  address.classId = EventTriggerRelationId;
1172  address.objectId = get_event_trigger_oid(name, missing_ok);
1173  address.objectSubId = 0;
1174  break;
1175  case OBJECT_PUBLICATION:
1176  address.classId = PublicationRelationId;
1177  address.objectId = get_publication_oid(name, missing_ok);
1178  address.objectSubId = 0;
1179  break;
1180  case OBJECT_SUBSCRIPTION:
1181  address.classId = SubscriptionRelationId;
1182  address.objectId = get_subscription_oid(name, missing_ok);
1183  address.objectSubId = 0;
1184  break;
1185  default:
1186  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1187  /* placate compiler, which doesn't know elog won't return */
1188  address.classId = InvalidOid;
1189  address.objectId = InvalidOid;
1190  address.objectSubId = 0;
1191  }
1192 
1193  return address;
1194 }
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Definition: tablespace.c:1382
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3024
Oid get_am_oid(const char *amname, bool missing_ok)
Definition: amcmds.c:193
Oid get_language_oid(const char *langname, bool missing_ok)
Definition: proclang.c:549
#define strVal(v)
Definition: value.h:54
Oid get_event_trigger_oid(const char *trigname, bool missing_ok)
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5116
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition: foreign.c:659
#define ERROR
Definition: elog.h:43
#define InvalidOid
Definition: postgres_ext.h:36
Oid get_database_oid(const char *dbname, bool missing_ok)
Definition: dbcommands.c:2009
Oid get_subscription_oid(const char *subname, bool missing_ok)
const char * name
Definition: encode.c:521
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:135
Oid get_publication_oid(const char *pubname, bool missing_ok)
#define elog
Definition: elog.h:219
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition: foreign.c:680

◆ get_object_address_usermapping()

static ObjectAddress get_object_address_usermapping ( List object,
bool  missing_ok 
)
static

Definition at line 1683 of file objectaddress.c.

References AUTHNAME, CStringGetDatum, ereport, errcode(), errmsg(), ERROR, GetForeignServerByName(), HeapTupleGetOid, HeapTupleIsValid, InvalidOid, linitial, lsecond, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache1(), SearchSysCache2(), ForeignServer::serverid, strVal, and username.

Referenced by get_object_address().

1684 {
1685  ObjectAddress address;
1686  Oid userid;
1687  char *username;
1688  char *servername;
1689  ForeignServer *server;
1690  HeapTuple tp;
1691 
1692  ObjectAddressSet(address, UserMappingRelationId, InvalidOid);
1693 
1694  /* fetch string names from input lists, for error messages */
1695  username = strVal(linitial(object));
1696  servername = strVal(lsecond(object));
1697 
1698  /* look up pg_authid OID of mapped user; InvalidOid if PUBLIC */
1699  if (strcmp(username, "public") == 0)
1700  userid = InvalidOid;
1701  else
1702  {
1704  CStringGetDatum(username));
1705  if (!HeapTupleIsValid(tp))
1706  {
1707  if (!missing_ok)
1708  ereport(ERROR,
1709  (errcode(ERRCODE_UNDEFINED_OBJECT),
1710  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1711  username, servername)));
1712  return address;
1713  }
1714  userid = HeapTupleGetOid(tp);
1715  ReleaseSysCache(tp);
1716  }
1717 
1718  /* Now look up the pg_user_mapping tuple */
1719  server = GetForeignServerByName(servername, true);
1720  if (!server)
1721  {
1722  if (!missing_ok)
1723  ereport(ERROR,
1724  (errcode(ERRCODE_UNDEFINED_OBJECT),
1725  errmsg("server \"%s\" does not exist", servername)));
1726  return address;
1727  }
1728  tp = SearchSysCache2(USERMAPPINGUSERSERVER,
1729  ObjectIdGetDatum(userid),
1730  ObjectIdGetDatum(server->serverid));
1731  if (!HeapTupleIsValid(tp))
1732  {
1733  if (!missing_ok)
1734  ereport(ERROR,
1735  (errcode(ERRCODE_UNDEFINED_OBJECT),
1736  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1737  username, servername)));
1738  return address;
1739  }
1740 
1741  address.objectId = HeapTupleGetOid(tp);
1742 
1743  ReleaseSysCache(tp);
1744 
1745  return address;
1746 }
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define lsecond(l)
Definition: pg_list.h:116
#define linitial(l)
Definition: pg_list.h:111
#define ObjectIdGetDatum(X)
Definition: postgres.h:492
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:563
ForeignServer * GetForeignServerByName(const char *srvname, bool missing_ok)
Definition: foreign.c:148
#define ereport(elevel, rest)
Definition: elog.h:122
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
static char * username
Definition: initdb.c:132
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:1123
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:707
Oid serverid
Definition: foreign.h:47

◆ get_object_attnum_acl()

AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 2538 of file objectaddress.c.

References ObjectPropertyType::attnum_acl, and get_object_property_data().

Referenced by AlterObjectOwner_internal().

2539 {
2540  const ObjectPropertyType *prop = get_object_property_data(class_id);
2541 
2542  return prop->attnum_acl;
2543 }
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 2514 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().

2515 {
2516  const ObjectPropertyType *prop = get_object_property_data(class_id);
2517 
2518  return prop->attnum_name;
2519 }
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 2522 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().

2523 {
2524  const ObjectPropertyType *prop = get_object_property_data(class_id);
2525 
2526  return prop->attnum_namespace;
2527 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_namespace

◆ get_object_attnum_owner()

AttrNumber get_object_attnum_owner ( Oid  class_id)

Definition at line 2530 of file objectaddress.c.

References ObjectPropertyType::attnum_owner, and get_object_property_data().

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

2531 {
2532  const ObjectPropertyType *prop = get_object_property_data(class_id);
2533 
2534  return prop->attnum_owner;
2535 }
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 2506 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

2507 {
2508  const ObjectPropertyType *prop = get_object_property_data(class_id);
2509 
2510  return prop->name_catcache_id;
2511 }
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 2498 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().

2499 {
2500  const ObjectPropertyType *prop = get_object_property_data(class_id);
2501 
2502  return prop->oid_catcache_id;
2503 }
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 2564 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::is_nsp_name_unique.

Referenced by EventTriggerSQLDropAddObject(), and pg_identify_object().

2565 {
2566  const ObjectPropertyType *prop = get_object_property_data(class_id);
2567 
2568  return prop->is_nsp_name_unique;
2569 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_namespace()

Oid get_object_namespace ( const ObjectAddress address)

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

2432 {
2433  int cache;
2434  HeapTuple tuple;
2435  bool isnull;
2436  Oid oid;
2437  const ObjectPropertyType *property;
2438 
2439  /* If not owned by a namespace, just return InvalidOid. */
2440  property = get_object_property_data(address->classId);
2441  if (property->attnum_namespace == InvalidAttrNumber)
2442  return InvalidOid;
2443 
2444  /* Currently, we can only handle object types with system caches. */
2445  cache = property->oid_catcache_id;
2446  Assert(cache != -1);
2447 
2448  /* Fetch tuple from syscache and extract namespace attribute. */
2449  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2450  if (!HeapTupleIsValid(tuple))
2451  elog(ERROR, "cache lookup failed for cache %d oid %u",
2452  cache, address->objectId);
2453  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2454  tuple,
2455  property->attnum_namespace,
2456  &isnull));
2457  Assert(!isnull);
2458  ReleaseSysCache(tuple);
2459 
2460  return oid;
2461 }
#define DatumGetObjectId(X)
Definition: postgres.h:485
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:492
#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:1112
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1368
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:699
AttrNumber attnum_namespace
#define InvalidAttrNumber
Definition: attnum.h:23
#define elog
Definition: elog.h:219

◆ get_object_oid_index()

Oid get_object_oid_index ( Oid  class_id)

Definition at line 2490 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by get_catalog_object_by_oid().

2491 {
2492  const ObjectPropertyType *prop = get_object_property_data(class_id);
2493 
2494  return prop->oid_index_oid;
2495 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)

◆ get_object_property_data()

static const ObjectPropertyType * get_object_property_data ( Oid  class_id)
static

Definition at line 2593 of file objectaddress.c.

References ObjectPropertyType::class_oid, ereport, errmsg_internal(), ERROR, and lengthof.

Referenced by get_object_attnum_acl(), get_object_attnum_name(), get_object_attnum_namespace(), get_object_attnum_owner(), get_object_catcache_name(), get_object_catcache_oid(), get_object_namensp_unique(), get_object_namespace(), get_object_oid_index(), and get_object_type().

2594 {
2595  static const ObjectPropertyType *prop_last = NULL;
2596  int index;
2597 
2598  /*
2599  * A shortcut to speed up multiple consecutive lookups of a particular
2600  * object class.
2601  */
2602  if (prop_last && prop_last->class_oid == class_id)
2603  return prop_last;
2604 
2605  for (index = 0; index < lengthof(ObjectProperty); index++)
2606  {
2607  if (ObjectProperty[index].class_oid == class_id)
2608  {
2609  prop_last = &ObjectProperty[index];
2610  return &ObjectProperty[index];
2611  }
2612  }
2613 
2614  ereport(ERROR,
2615  (errmsg_internal("unrecognized class ID: %u", class_id)));
2616 
2617  return NULL; /* keep MSC compiler happy */
2618 }
#define lengthof(array)
Definition: c.h:629
Definition: type.h:89
#define ERROR
Definition: elog.h:43
static const ObjectPropertyType ObjectProperty[]
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg_internal(const char *fmt,...)
Definition: elog.c:827

◆ get_object_type()

ObjectType get_object_type ( Oid  class_id,
Oid  object_id 
)

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

2547 {
2548  const ObjectPropertyType *prop = get_object_property_data(class_id);
2549 
2550  if (prop->objtype == OBJECT_TABLE)
2551  {
2552  /*
2553  * If the property data says it's a table, dig a little deeper to get
2554  * the real relation kind, so that callers can produce more precise
2555  * error messages.
2556  */
2557  return get_relkind_objtype(get_rel_relkind(object_id));
2558  }
2559  else
2560  return prop->objtype;
2561 }
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_relation_by_qualified_name()

static ObjectAddress get_relation_by_qualified_name ( ObjectType  objtype,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
static

Definition at line 1200 of file objectaddress.c.

References ObjectAddress::classId, elog, ereport, errcode(), errmsg(), ERROR, InvalidOid, makeRangeVarFromNameList(), OBJECT_FOREIGN_TABLE, OBJECT_INDEX, OBJECT_MATVIEW, OBJECT_SEQUENCE, OBJECT_TABLE, OBJECT_VIEW, ObjectAddress::objectId, ObjectAddress::objectSubId, RelationData::rd_rel, relation_openrv_extended(), RelationGetRelationName, and RelationGetRelid.

Referenced by get_object_address().

1203 {
1204  Relation relation;
1205  ObjectAddress address;
1206 
1207  address.classId = RelationRelationId;
1208  address.objectId = InvalidOid;
1209  address.objectSubId = 0;
1210 
1212  lockmode, missing_ok);
1213  if (!relation)
1214  return address;
1215 
1216  switch (objtype)
1217  {
1218  case OBJECT_INDEX:
1219  if (relation->rd_rel->relkind != RELKIND_INDEX &&
1220  relation->rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
1221  ereport(ERROR,
1222  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1223  errmsg("\"%s\" is not an index",
1224  RelationGetRelationName(relation))));
1225  break;
1226  case OBJECT_SEQUENCE:
1227  if (relation->rd_rel->relkind != RELKIND_SEQUENCE)
1228  ereport(ERROR,
1229  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1230  errmsg("\"%s\" is not a sequence",
1231  RelationGetRelationName(relation))));
1232  break;
1233  case OBJECT_TABLE:
1234  if (relation->rd_rel->relkind != RELKIND_RELATION &&
1235  relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1236  ereport(ERROR,
1237  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1238  errmsg("\"%s\" is not a table",
1239  RelationGetRelationName(relation))));
1240  break;
1241  case OBJECT_VIEW:
1242  if (relation->rd_rel->relkind != RELKIND_VIEW)
1243  ereport(ERROR,
1244  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1245  errmsg("\"%s\" is not a view",
1246  RelationGetRelationName(relation))));
1247  break;
1248  case OBJECT_MATVIEW:
1249  if (relation->rd_rel->relkind != RELKIND_MATVIEW)
1250  ereport(ERROR,
1251  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1252  errmsg("\"%s\" is not a materialized view",
1253  RelationGetRelationName(relation))));
1254  break;
1255  case OBJECT_FOREIGN_TABLE:
1256  if (relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE)
1257  ereport(ERROR,
1258  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1259  errmsg("\"%s\" is not a foreign table",
1260  RelationGetRelationName(relation))));
1261  break;
1262  default:
1263  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1264  break;
1265  }
1266 
1267  /* Done. */
1268  address.objectId = RelationGetRelid(relation);
1269  *relp = relation;
1270 
1271  return address;
1272 }
int errcode(int sqlerrcode)
Definition: elog.c:575
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3042
Form_pg_class rd_rel
Definition: rel.h:84
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:441
#define ereport(elevel, rest)
Definition: elog.h:122
#define InvalidOid
Definition: postgres_ext.h:36
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
#define RelationGetRelid(relation)
Definition: rel.h:407
Relation relation_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: heapam.c:1237

◆ get_relkind_objtype()

ObjectType get_relkind_objtype ( char  relkind)

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

5118 {
5119  switch (relkind)
5120  {
5121  case RELKIND_RELATION:
5122  case RELKIND_PARTITIONED_TABLE:
5123  return OBJECT_TABLE;
5124  case RELKIND_INDEX:
5125  return OBJECT_INDEX;
5126  case RELKIND_SEQUENCE:
5127  return OBJECT_SEQUENCE;
5128  case RELKIND_VIEW:
5129  return OBJECT_VIEW;
5130  case RELKIND_MATVIEW:
5131  return OBJECT_MATVIEW;
5132  case RELKIND_FOREIGN_TABLE:
5133  return OBJECT_FOREIGN_TABLE;
5134 
5135  /*
5136  * other relkinds are not supported here because they don't map to
5137  * OBJECT_* values
5138  */
5139  default:
5140  elog(ERROR, "unexpected relkind: %d", relkind);
5141  return 0;
5142  }
5143 }
char relkind
Definition: pg_class.h:51
#define ERROR
Definition: elog.h:43
#define elog
Definition: elog.h:219

◆ getConstraintTypeDescription()

static void getConstraintTypeDescription ( StringInfo  buffer,
Oid  constroid 
)
static

Definition at line 4012 of file objectaddress.c.

References AccessShareLock, appendStringInfoString(), elog, ERROR, get_catalog_object_by_oid(), GETSTRUCT, heap_close, heap_open(), HeapTupleGetOid, HeapTupleIsValid, and OidIsValid.

Referenced by getObjectTypeDescription().

4013 {
4014  Relation constrRel;
4015  HeapTuple constrTup;
4016  Form_pg_constraint constrForm;
4017 
4018  constrRel = heap_open(ConstraintRelationId, AccessShareLock);
4019  constrTup = get_catalog_object_by_oid(constrRel, constroid);
4020  if (!HeapTupleIsValid(constrTup))
4021  elog(ERROR, "cache lookup failed for constraint %u", constroid);
4022 
4023  constrForm = (Form_pg_constraint) GETSTRUCT(constrTup);
4024 
4025  if (OidIsValid(constrForm->conrelid))
4026  appendStringInfoString(buffer, "table constraint");
4027  else if (OidIsValid(constrForm->contypid))
4028  appendStringInfoString(buffer, "domain constraint");
4029  else
4030  elog(ERROR, "invalid constraint %u", HeapTupleGetOid(constrTup));
4031 
4032  heap_close(constrRel, AccessShareLock);
4033 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:668
#define AccessShareLock
Definition: lockdefs.h:36
#define heap_close(r, l)
Definition: heapam.h:97
#define OidIsValid(objectId)
Definition: c.h:605
#define ERROR
Definition: elog.h:43
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:157
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1294
FormData_pg_constraint * Form_pg_constraint
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
HeapTuple get_catalog_object_by_oid(Relation catalog, Oid objectId)
#define elog
Definition: elog.h:219
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:707

◆ getObjectDescription()

char* getObjectDescription ( const ObjectAddress object)

Definition at line 2675 of file objectaddress.c.

References _, AccessMethodOperatorOidIndexId, AccessMethodProcedureOidIndexId, AccessShareLock, AMOID, appendStringInfo(), AttrDefaultOidIndexId, BTEqualStrategyNumber, buffer, CastOidIndexId, CLAOID, ObjectAddress::classId, COLLOID, CONSTROID, CONVOID, StringInfoData::data, 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_rel_name(), get_subscription_name(), get_tablespace_name(), GetForeignDataWrapper(), GetForeignServer(), getObjectClass(), getObjectDescription(), getOpFamilyDescription(), getRelationDescription(), GETSTRUCT, GetUserNameFromId(), heap_close, heap_open(), HeapTupleIsValid, initStringInfo(), NameStr, ObjectAddress::objectId, ObjectIdAttributeNumber, 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, systable_beginscan(), systable_endscan(), systable_getnext(), TRFOID, TriggerOidIndexId, TSCONFIGOID, TSDICTOID, TSPARSEROID, TSTEMPLATEOID, and USERMAPPINGOID.

Referenced by AlterExtensionNamespace(), ATExecAlterColumnType(), changeDependencyFor(), 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().

2676 {
2678 
2679  initStringInfo(&buffer);
2680 
2681  switch (getObjectClass(object))
2682  {
2683  case OCLASS_CLASS:
2684  getRelationDescription(&buffer, object->objectId);
2685  if (object->objectSubId != 0)
2686  appendStringInfo(&buffer, _(" column %s"),
2687  get_attname(object->objectId,
2688  object->objectSubId,
2689  false));
2690  break;
2691 
2692  case OCLASS_PROC:
2693  appendStringInfo(&buffer, _("function %s"),
2694  format_procedure(object->objectId));
2695  break;
2696 
2697  case OCLASS_TYPE:
2698  appendStringInfo(&buffer, _("type %s"),
2699  format_type_be(object->objectId));
2700  break;
2701 
2702  case OCLASS_CAST:
2703  {
2704  Relation castDesc;
2705  ScanKeyData skey[1];
2706  SysScanDesc rcscan;
2707  HeapTuple tup;
2708  Form_pg_cast castForm;
2709 
2710  castDesc = heap_open(CastRelationId, AccessShareLock);
2711 
2712  ScanKeyInit(&skey[0],
2714  BTEqualStrategyNumber, F_OIDEQ,
2715  ObjectIdGetDatum(object->objectId));
2716 
2717  rcscan = systable_beginscan(castDesc, CastOidIndexId, true,
2718  NULL, 1, skey);
2719 
2720  tup = systable_getnext(rcscan);
2721 
2722  if (!HeapTupleIsValid(tup))
2723  elog(ERROR, "could not find tuple for cast %u",
2724  object->objectId);
2725 
2726  castForm = (Form_pg_cast) GETSTRUCT(tup);
2727 
2728  appendStringInfo(&buffer, _("cast from %s to %s"),
2729  format_type_be(castForm->castsource),
2730  format_type_be(castForm->casttarget));
2731 
2732  systable_endscan(rcscan);
2733  heap_close(castDesc, AccessShareLock);
2734  break;
2735  }
2736 
2737  case OCLASS_COLLATION:
2738  {
2739  HeapTuple collTup;
2740  Form_pg_collation coll;
2741 
2742  collTup = SearchSysCache1(COLLOID,
2743  ObjectIdGetDatum(object->objectId));
2744  if (!HeapTupleIsValid(collTup))
2745  elog(ERROR, "cache lookup failed for collation %u",
2746  object->objectId);
2747  coll = (Form_pg_collation) GETSTRUCT(collTup);
2748  appendStringInfo(&buffer, _("collation %s"),
2749  NameStr(coll->collname));
2750  ReleaseSysCache(collTup);
2751  break;
2752  }
2753 
2754  case OCLASS_CONSTRAINT:
2755  {
2756  HeapTuple conTup;
2757  Form_pg_constraint con;
2758 
2759  conTup = SearchSysCache1(CONSTROID,
2760  ObjectIdGetDatum(object->objectId));
2761  if (!HeapTupleIsValid(conTup))
2762  elog(ERROR, "cache lookup failed for constraint %u",
2763  object->objectId);
2764  con = (Form_pg_constraint) GETSTRUCT(conTup);
2765 
2766  if (OidIsValid(con->conrelid))
2767  {
2768  StringInfoData rel;
2769 
2770  initStringInfo(&rel);
2771  getRelationDescription(&rel, con->conrelid);
2772  appendStringInfo(&buffer, _("constraint %s on %s"),
2773  NameStr(con->conname), rel.data);
2774  pfree(rel.data);
2775  }
2776  else
2777  {
2778  appendStringInfo(&buffer, _("constraint %s"),
2779  NameStr(con->conname));
2780  }
2781 
2782  ReleaseSysCache(conTup);
2783  break;
2784  }
2785 
2786  case OCLASS_CONVERSION:
2787  {
2788  HeapTuple conTup;
2789 
2790  conTup = SearchSysCache1(CONVOID,
2791  ObjectIdGetDatum(object->objectId));
2792  if (!HeapTupleIsValid(conTup))
2793  elog(ERROR, "cache lookup failed for conversion %u",
2794  object->objectId);
2795  appendStringInfo(&buffer, _("conversion %s"),
2796  NameStr(((Form_pg_conversion) GETSTRUCT(conTup))->conname));
2797  ReleaseSysCache(conTup);
2798  break;
2799  }
2800 
2801  case OCLASS_DEFAULT:
2802  {
2803  Relation attrdefDesc;
2804  ScanKeyData skey[1];
2805  SysScanDesc adscan;
2806  HeapTuple tup;
2807  Form_pg_attrdef attrdef;
2808  ObjectAddress colobject;
2809 
2810  attrdefDesc = heap_open(AttrDefaultRelationId, AccessShareLock);
2811 
2812  ScanKeyInit(&skey[0],
2814  BTEqualStrategyNumber, F_OIDEQ,
2815  ObjectIdGetDatum(object->objectId));
2816 
2817  adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndexId,
2818  true, NULL, 1, skey);
2819 
2820  tup = systable_getnext(adscan);
2821 
2822  if (!HeapTupleIsValid(tup))
2823  elog(ERROR, "could not find tuple for attrdef %u",
2824  object->objectId);
2825 
2826  attrdef = (Form_pg_attrdef) GETSTRUCT(tup);
2827 
2828  colobject.classId = RelationRelationId;
2829  colobject.objectId = attrdef->adrelid;
2830  colobject.objectSubId = attrdef->adnum;
2831 
2832  appendStringInfo(&buffer, _("default for %s"),
2833  getObjectDescription(&colobject));
2834 
2835  systable_endscan(adscan);
2836  heap_close(attrdefDesc, AccessShareLock);
2837  break;
2838  }
2839 
2840  case OCLASS_LANGUAGE:
2841  appendStringInfo(&buffer, _("language %s"),
2842  get_language_name(object->objectId, false));
2843  break;
2844 
2845  case OCLASS_LARGEOBJECT:
2846  appendStringInfo(&buffer, _("large object %u"),
2847  object->objectId);
2848  break;
2849 
2850  case OCLASS_OPERATOR:
2851  appendStringInfo(&buffer, _("operator %s"),
2852  format_operator(object->objectId));
2853  break;
2854 
2855  case OCLASS_OPCLASS:
2856  {
2857  HeapTuple opcTup;
2858  Form_pg_opclass opcForm;
2859  HeapTuple amTup;
2860  Form_pg_am amForm;
2861  char *nspname;
2862 
2863  opcTup = SearchSysCache1(CLAOID,
2864  ObjectIdGetDatum(object->objectId));
2865  if (!HeapTupleIsValid(opcTup))
2866  elog(ERROR, "cache lookup failed for opclass %u",
2867  object->objectId);
2868  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
2869 
2870  amTup = SearchSysCache1(AMOID,
2871  ObjectIdGetDatum(opcForm->opcmethod));
2872  if (!HeapTupleIsValid(amTup))
2873  elog(ERROR, "cache lookup failed for access method %u",
2874  opcForm->opcmethod);
2875  amForm = (Form_pg_am) GETSTRUCT(amTup);
2876 
2877  /* Qualify the name if not visible in search path */
2878  if (OpclassIsVisible(object->objectId))
2879  nspname = NULL;
2880  else
2881  nspname = get_namespace_name(opcForm->opcnamespace);
2882 
2883  appendStringInfo(&buffer, _("operator class %s for access method %s"),
2885  NameStr(opcForm->opcname)),
2886  NameStr(amForm->amname));
2887 
2888  ReleaseSysCache(amTup);
2889  ReleaseSysCache(opcTup);
2890  break;
2891  }
2892 
2893  case OCLASS_OPFAMILY:
2894  getOpFamilyDescription(&buffer, object->objectId);
2895  break;
2896 
2897  case OCLASS_AM:
2898  {
2899  HeapTuple tup;
2900 
2901  tup = SearchSysCache1(AMOID,
2902  ObjectIdGetDatum(object->objectId));
2903  if (!HeapTupleIsValid(tup))
2904  elog(ERROR, "cache lookup failed for access method %u",
2905  object->objectId);
2906  appendStringInfo(&buffer, _("access method %s"),
2907  NameStr(((Form_pg_am) GETSTRUCT(tup))->amname));
2908  ReleaseSysCache(tup);
2909  break;
2910  }
2911 
2912  case OCLASS_AMOP:
2913  {
2914  Relation amopDesc;
2915  HeapTuple tup;
2916  ScanKeyData skey[1];
2917  SysScanDesc amscan;
2918  Form_pg_amop amopForm;
2919  StringInfoData opfam;
2920 
2921  amopDesc = heap_open(AccessMethodOperatorRelationId,
2922  AccessShareLock);
2923 
2924  ScanKeyInit(&skey[0],
2926  BTEqualStrategyNumber, F_OIDEQ,
2927  ObjectIdGetDatum(object->objectId));
2928 
2929  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
2930  NULL, 1, skey);
2931 
2932  tup = systable_getnext(amscan);
2933 
2934  if (!HeapTupleIsValid(tup))
2935  elog(ERROR, "could not find tuple for amop entry %u",
2936  object->objectId);
2937 
2938  amopForm = (Form_pg_amop) GETSTRUCT(tup);
2939 
2940  initStringInfo(&opfam);
2941  getOpFamilyDescription(&opfam, amopForm->amopfamily);
2942 
2943  /*------
2944  translator: %d is the operator strategy (a number), the
2945  first two %s's are data type names, the third %s is the
2946  description of the operator family, and the last %s is the
2947  textual form of the operator with arguments. */
2948  appendStringInfo(&buffer, _("operator %d (%s, %s) of %s: %s"),
2949  amopForm->amopstrategy,
2950  format_type_be(amopForm->amoplefttype),
2951  format_type_be(amopForm->amoprighttype),
2952  opfam.data,
2953  format_operator(amopForm->amopopr));
2954 
2955  pfree(opfam.data);
2956 
2957  systable_endscan(amscan);
2958  heap_close(amopDesc, AccessShareLock);
2959  break;
2960  }
2961 
2962  case OCLASS_AMPROC:
2963  {
2964  Relation amprocDesc;
2965  ScanKeyData skey[1];
2966  SysScanDesc amscan;
2967  HeapTuple tup;
2968  Form_pg_amproc amprocForm;
2969  StringInfoData opfam;
2970 
2971  amprocDesc = heap_open(AccessMethodProcedureRelationId,
2972  AccessShareLock);
2973 
2974  ScanKeyInit(&skey[0],
2976  BTEqualStrategyNumber, F_OIDEQ,
2977  ObjectIdGetDatum(object->objectId));
2978 
2979  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
2980  NULL, 1, skey);
2981 
2982  tup = systable_getnext(amscan);
2983 
2984  if (!HeapTupleIsValid(tup))
2985  elog(ERROR, "could not find tuple for amproc entry %u",
2986  object->objectId);
2987 
2988  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
2989 
2990  initStringInfo(&opfam);
2991  getOpFamilyDescription(&opfam, amprocForm->amprocfamily);
2992 
2993  /*------
2994  translator: %d is the function number, the first two %s's
2995  are data type names, the third %s is the description of the
2996  operator family, and the last %s is the textual form of the
2997  function with arguments. */
2998  appendStringInfo(&buffer, _("function %d (%s, %s) of %s: %s"),
2999  amprocForm->amprocnum,
3000  format_type_be(amprocForm->amproclefttype),
3001  format_type_be(amprocForm->amprocrighttype),
3002  opfam.data,
3003  format_procedure(amprocForm->amproc));
3004 
3005  pfree(opfam.data);
3006 
3007  systable_endscan(amscan);
3008  heap_close(amprocDesc, AccessShareLock);
3009  break;
3010  }
3011 
3012  case OCLASS_REWRITE:
3013  {
3014  Relation ruleDesc;
3015  ScanKeyData skey[1];
3016  SysScanDesc rcscan;
3017  HeapTuple tup;
3019 
3020  ruleDesc = heap_open(RewriteRelationId, AccessShareLock);
3021 
3022  ScanKeyInit(&skey[0],
3024  BTEqualStrategyNumber, F_OIDEQ,
3025  ObjectIdGetDatum(object->objectId));
3026 
3027  rcscan = systable_beginscan(ruleDesc, RewriteOidIndexId, true,
3028  NULL, 1, skey);
3029 
3030  tup = systable_getnext(rcscan);
3031 
3032  if (!HeapTupleIsValid(tup))
3033  elog(ERROR, "could not find tuple for rule %u",
3034  object->objectId);
3035 
3036  rule = (Form_pg_rewrite) GETSTRUCT(tup);
3037 
3038  appendStringInfo(&buffer, _("rule %s on "),
3039  NameStr(rule->rulename));
3040  getRelationDescription(&buffer, rule->ev_class);
3041 
3042  systable_endscan(rcscan);
3043  heap_close(ruleDesc, AccessShareLock);
3044  break;
3045  }
3046 
3047  case OCLASS_TRIGGER:
3048  {
3049  Relation trigDesc;
3050  ScanKeyData skey[1];
3051  SysScanDesc tgscan;
3052  HeapTuple tup;
3053  Form_pg_trigger trig;
3054 
3055  trigDesc = heap_open(TriggerRelationId, AccessShareLock);
3056 
3057  ScanKeyInit(&skey[0],
3059  BTEqualStrategyNumber, F_OIDEQ,
3060  ObjectIdGetDatum(object->objectId));
3061 
3062  tgscan = systable_beginscan(trigDesc, TriggerOidIndexId, true,
3063  NULL, 1, skey);
3064 
3065  tup = systable_getnext(tgscan);
3066 
3067  if (!HeapTupleIsValid(tup))
3068  elog(ERROR, "could not find tuple for trigger %u",
3069  object->objectId);
3070 
3071  trig = (Form_pg_trigger) GETSTRUCT(tup);
3072 
3073  appendStringInfo(&buffer, _("trigger %s on "),
3074  NameStr(trig->tgname));
3075  getRelationDescription(&buffer, trig->tgrelid);
3076 
3077  systable_endscan(tgscan);
3078  heap_close(trigDesc, AccessShareLock);
3079  break;
3080  }
3081 
3082  case OCLASS_SCHEMA:
3083  {
3084  char *nspname;
3085 
3086  nspname = get_namespace_name(object->objectId);
3087  if (!nspname)
3088  elog(ERROR, "cache lookup failed for namespace %u",
3089  object->objectId);
3090  appendStringInfo(&buffer, _("schema %s"), nspname);
3091  break;
3092  }
3093 
3094  case OCLASS_STATISTIC_EXT:
3095  {
3096  HeapTuple stxTup;
3097  Form_pg_statistic_ext stxForm;
3098 
3099  stxTup = SearchSysCache1(STATEXTOID,
3100  ObjectIdGetDatum(object->objectId));
3101  if (!HeapTupleIsValid(stxTup))
3102  elog(ERROR, "could not find tuple for statistics object %u",
3103  object->objectId);
3104 
3105  stxForm = (Form_pg_statistic_ext) GETSTRUCT(stxTup);
3106 
3107  appendStringInfo(&buffer, _("statistics object %s"),
3108  NameStr(stxForm->stxname));
3109 
3110  ReleaseSysCache(stxTup);
3111  break;
3112  }
3113 
3114  case OCLASS_TSPARSER:
3115  {
3116  HeapTuple tup;
3117 
3119  ObjectIdGetDatum(object->objectId));
3120  if (!HeapTupleIsValid(tup))
3121  elog(ERROR, "cache lookup failed for text search parser %u",
3122  object->objectId);
3123  appendStringInfo(&buffer, _("text search parser %s"),
3124  NameStr(((Form_pg_ts_parser) GETSTRUCT(tup))->prsname));
3125  ReleaseSysCache(tup);
3126  break;
3127  }
3128 
3129  case OCLASS_TSDICT:
3130  {
3131  HeapTuple tup;
3132 
3133  tup = SearchSysCache1(TSDICTOID,
3134  ObjectIdGetDatum(object->objectId));
3135  if (!HeapTupleIsValid(tup))
3136  elog(ERROR, "cache lookup failed for text search dictionary %u",
3137  object->objectId);
3138  appendStringInfo(&buffer, _("text search dictionary %s"),
3139  NameStr(((Form_pg_ts_dict) GETSTRUCT(tup))->dictname));
3140  ReleaseSysCache(tup);
3141  break;
3142  }
3143 
3144  case OCLASS_TSTEMPLATE:
3145  {
3146  HeapTuple tup;
3147 
3149  ObjectIdGetDatum(object->objectId));
3150  if (!HeapTupleIsValid(tup))
3151  elog(ERROR, "cache lookup failed for text search template %u",
3152  object->objectId);
3153  appendStringInfo(&buffer, _("text search template %s"),
3154  NameStr(((Form_pg_ts_template) GETSTRUCT(tup))->tmplname));
3155  ReleaseSysCache(tup);
3156  break;
3157  }
3158 
3159  case OCLASS_TSCONFIG:
3160  {
3161  HeapTuple tup;
3162 
3164  ObjectIdGetDatum(object->objectId));
3165  if (!HeapTupleIsValid(tup))
3166  elog(ERROR, "cache lookup failed for text search configuration %u",
3167  object->objectId);
3168  appendStringInfo(&buffer, _("text search configuration %s"),
3169  NameStr(((Form_pg_ts_config) GETSTRUCT(tup))->cfgname));
3170  ReleaseSysCache(tup);
3171  break;
3172  }
3173 
3174  case OCLASS_ROLE:
3175  {
3176  appendStringInfo(&buffer, _("role %s"),
3177  GetUserNameFromId(object->objectId, false));
3178  break;
3179  }
3180 
3181  case OCLASS_DATABASE:
3182  {
3183  char *datname;
3184 
3185  datname = get_database_name(object->objectId);
3186  if (!datname)
3187  elog(ERROR, "cache lookup failed for database %u",
3188  object->objectId);
3189  appendStringInfo(&buffer, _("database %s"), datname);
3190  break;
3191  }
3192 
3193  case OCLASS_TBLSPACE:
3194  {
3195  char *tblspace;
3196 
3197  tblspace = get_tablespace_name(object->objectId);
3198  if (!tblspace)
3199  elog(ERROR, "cache lookup failed for tablespace %u",
3200  object->objectId);
3201  appendStringInfo(&buffer, _("tablespace %s"), tblspace);
3202  break;
3203  }
3204 
3205  case OCLASS_FDW:
3206  {
3207  ForeignDataWrapper *fdw;
3208 
3209  fdw = GetForeignDataWrapper(object->objectId);
3210  appendStringInfo(&buffer, _("foreign-data wrapper %s"), fdw->fdwname);
3211  break;
3212  }
3213 
3214  case OCLASS_FOREIGN_SERVER:
3215  {
3216  ForeignServer *srv;
3217 
3218  srv = GetForeignServer(object->objectId);
3219  appendStringInfo(&buffer, _("server %s"), srv->servername);
3220  break;
3221  }
3222 
3223  case OCLASS_USER_MAPPING:
3224  {
3225  HeapTuple tup;
3226  Oid useid;
3227  char *usename;
3228  Form_pg_user_mapping umform;
3229  ForeignServer *srv;
3230 
3232  ObjectIdGetDatum(object->objectId));
3233  if (!HeapTupleIsValid(tup))
3234  elog(ERROR, "cache lookup failed for user mapping %u",
3235  object->objectId);
3236  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
3237  useid = umform->umuser;
3238  srv = GetForeignServer(umform->umserver);
3239 
3240  ReleaseSysCache(tup);
3241 
3242  if (OidIsValid(useid))
3243  usename = GetUserNameFromId(useid, false);
3244  else
3245  usename = "public";
3246 
3247  appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
3248  srv->servername);
3249  break;
3250  }
3251 
3252  case OCLASS_DEFACL:
3253  {
3254  Relation defaclrel;
3255  ScanKeyData skey[1];
3256  SysScanDesc rcscan;
3257  HeapTuple tup;
3258  Form_pg_default_acl defacl;
3259 
3260  defaclrel = heap_open(DefaultAclRelationId, AccessShareLock);
3261 
3262  ScanKeyInit(&skey[0],
3264  BTEqualStrategyNumber, F_OIDEQ,
3265  ObjectIdGetDatum(object->objectId));
3266 
3267  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
3268  true, NULL, 1, skey);
3269 
3270  tup = systable_getnext(rcscan);
3271 
3272  if (!HeapTupleIsValid(tup))
3273  elog(ERROR, "could not find tuple for default ACL %u",
3274  object->objectId);
3275 
3276  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
3277 
3278  switch (defacl->defaclobjtype)
3279  {
3280  case DEFACLOBJ_RELATION:
3281  appendStringInfo(&buffer,
3282  _("default privileges on new relations belonging to role %s"),
3283  GetUserNameFromId(defacl->defaclrole, false));
3284  break;
3285  case DEFACLOBJ_SEQUENCE:
3286  appendStringInfo(&buffer,
3287  _("default privileges on new sequences belonging to role %s"),
3288  GetUserNameFromId(defacl->defaclrole, false));
3289  break;
3290  case DEFACLOBJ_FUNCTION:
3291  appendStringInfo(&buffer,
3292  _("default privileges on new functions belonging to role %s"),
3293  GetUserNameFromId(defacl->defaclrole, false));
3294  break;
3295  case DEFACLOBJ_TYPE:
3296  appendStringInfo(&buffer,
3297  _("default privileges on new types belonging to role %s"),
3298  GetUserNameFromId(defacl->defaclrole, false));
3299  break;
3300  case DEFACLOBJ_NAMESPACE:
3301  appendStringInfo(&buffer,
3302  _("default privileges on new schemas belonging to role %s"),
3303  GetUserNameFromId(defacl->defaclrole, false));
3304  break;
3305  default:
3306  /* shouldn't get here */
3307  appendStringInfo(&buffer,
3308  _("default privileges belonging to role %s"),
3309  GetUserNameFromId(defacl->defaclrole, false));
3310  break;
3311  }
3312 
3313  if (OidIsValid(defacl->defaclnamespace))
3314  {
3315  appendStringInfo(&buffer,
3316  _(" in schema %s"),
3317  get_namespace_name(defacl->defaclnamespace));
3318  }
3319 
3320  systable_endscan(rcscan);
3321  heap_close(defaclrel, AccessShareLock);
3322  break;
3323  }
3324 
3325  case OCLASS_EXTENSION:
3326  {
3327  char *extname;
3328 
3329  extname = get_extension_name(object->objectId);
3330  if (!extname)
3331  elog(ERROR, "cache lookup failed for extension %u",
3332  object->objectId);
3333  appendStringInfo(&buffer, _("extension %s"), extname);
3334  break;
3335  }
3336 
3337  case OCLASS_EVENT_TRIGGER:
3338  {
3339  HeapTuple tup;
3340 
3342  ObjectIdGetDatum(object->objectId));
3343  if (!HeapTupleIsValid(tup))
3344  elog(ERROR, "cache lookup failed for event trigger %u",
3345  object->objectId);
3346  appendStringInfo(&buffer, _("event trigger %s"),
3347  NameStr(((Form_pg_event_trigger) GETSTRUCT(tup))->evtname));
3348  ReleaseSysCache(tup);
3349  break;
3350  }
3351 
3352  case OCLASS_POLICY:
3353  {
3354  Relation policy_rel;
3355  ScanKeyData skey[1];
3356  SysScanDesc sscan;
3357  HeapTuple tuple;
3358  Form_pg_policy form_policy;
3359 
3360  policy_rel = heap_open(PolicyRelationId, AccessShareLock);
3361 
3362  ScanKeyInit(&skey[0],
3364  BTEqualStrategyNumber, F_OIDEQ,
3365  ObjectIdGetDatum(object->objectId));
3366 
3367  sscan = systable_beginscan(policy_rel, PolicyOidIndexId,
3368  true, NULL, 1, skey);
3369 
3370  tuple = systable_getnext(sscan);
3371 
3372  if (!HeapTupleIsValid(tuple))
3373  elog(ERROR, "could not find tuple for policy %u",
3374  object->objectId);
3375 
3376  form_policy = (Form_pg_policy) GETSTRUCT(tuple);
3377 
3378  appendStringInfo(&buffer, _("policy %s on "),
3379  NameStr(form_policy->polname));
3380  getRelationDescription(&buffer, form_policy->polrelid);
3381 
3382  systable_endscan(sscan);
3383  heap_close(policy_rel, AccessShareLock);
3384  break;
3385  }
3386 
3387  case OCLASS_PUBLICATION:
3388  {
3389  appendStringInfo(&buffer, _("publication %s"),
3390  get_publication_name(object->objectId));
3391  break;
3392  }
3393 
3395  {
3396  HeapTuple tup;
3397  char *pubname;
3398  Form_pg_publication_rel prform;
3399 
3401  ObjectIdGetDatum(object->objectId));
3402  if (!HeapTupleIsValid(tup))
3403  elog(ERROR, "cache lookup failed for publication table %u",
3404  object->objectId);
3405 
3406  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
3407  pubname = get_publication_name(prform->prpubid);
3408 
3409  appendStringInfo(&buffer, _("publication table %s in publication %s"),
3410  get_rel_name(prform->prrelid), pubname);
3411  ReleaseSysCache(tup);
3412  break;
3413  }
3414 
3415  case OCLASS_SUBSCRIPTION:
3416  {
3417  appendStringInfo(&buffer, _("subscription %s"),
3418  get_subscription_name(object->objectId));
3419  break;
3420  }
3421 
3422  case OCLASS_TRANSFORM:
3423  {
3424  HeapTuple trfTup;
3425  Form_pg_transform trfForm;
3426 
3427  trfTup = SearchSysCache1(TRFOID,
3428  ObjectIdGetDatum(object->objectId));
3429  if (!HeapTupleIsValid(trfTup))
3430  elog(ERROR, "could not find tuple for transform %u",
3431  object->objectId);
3432 
3433  trfForm = (Form_pg_transform) GETSTRUCT(trfTup);
3434 
3435  appendStringInfo(&buffer, _("transform for %s language %s"),
3436  format_type_be(trfForm->trftype),
3437  get_language_name(trfForm->trflang, false));
3438 
3439  ReleaseSysCache(trfTup);
3440  break;
3441  }
3442 
3443  /*
3444  * There's intentionally no default: case here; we want the
3445  * compiler to warn if a new OCLASS hasn't been handled above.
3446  */
3447  }
3448 
3449  return buffer.data;
3450 }
#define RewriteOidIndexId
Definition: indexing.h:222
#define TriggerOidIndexId
Definition: indexing.h:252
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:502
#define GETSTRUCT(TUP)
Definition: htup_details.h:668
Definition: syscache.h:36
char * get_language_name(Oid langoid, bool missing_ok)
Definition: lsyscache.c:1003
FormData_pg_ts_config * Form_pg_ts_config
Definition: pg_ts_config.h:38
#define ObjectIdAttributeNumber
Definition: sysattr.h:22
char * fdwname
Definition: foreign.h:39
#define PolicyOidIndexId
Definition: indexing.h:328
FormData_pg_amproc * Form_pg_amproc
Definition: pg_amproc.h:66
char * get_extension_name(Oid ext_oid)
Definition: extension.c:180
#define DefaultAclOidIndexId
Definition: indexing.h:308
#define AccessShareLock
Definition: lockdefs.h:36
static void getOpFamilyDescription(StringInfo buffer, Oid opfid)
#define AttrDefaultOidIndexId
Definition: indexing.h:88
#define AccessMethodOperatorOidIndexId
Definition: indexing.h:78
char * format_type_be(Oid type_oid)
Definition: format_type.c:328
char * format_operator(Oid operator_oid)
Definition: regproc.c:820
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2416
#define OidIsValid(objectId)
Definition: c.h:605
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:331
char * getObjectDescription(const ObjectAddress *object)
Definition: localtime.c:77
#define AccessMethodProcedureOidIndexId
Definition: indexing.h:83
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:419
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:42
#define ObjectIdGetDatum(X)
Definition: postgres.h:492
#define ERROR
Definition: elog.h:43
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2056
FormData_pg_user_mapping * Form_pg_user_mapping
FormData_pg_ts_dict * Form_pg_ts_dict
Definition: pg_ts_dict.h:41
FormData_pg_default_acl * Form_pg_default_acl
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3051
#define CastOidIndexId
Definition: indexing.h:106
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:54
void initStringInfo(StringInfo str)
Definition: stringinfo.c:46
FormData_pg_attrdef * Form_pg_attrdef
Definition: pg_attrdef.h:45
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:10574
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1112
ForeignServer * GetForeignServer(Oid serverid)
Definition: foreign.c:93
char * get_publication_name(Oid pubid)
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1160
FormData_pg_ts_parser * Form_pg_ts_parser
Definition: pg_ts_parser.h:53
FormData_pg_conversion * Form_pg_conversion
Definition: pg_conversion.h:56
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1294
bool OpclassIsVisible(Oid opcid)
Definition: namespace.c:1812
FormData_pg_policy * Form_pg_policy
Definition: pg_policy.h:48
char * format_procedure(Oid procedure_oid)
Definition: regproc.c:323
static void getRelationDescription(StringInfo buffer, Oid relid)
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:787
WalTimeSample buffer[LAG_TRACKER_BUFFER_SIZE]
Definition: walsender.c:215
FormData_pg_trigger * Form_pg_trigger
Definition: pg_trigger.h:70
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:49
FormData_pg_rewrite * Form_pg_rewrite
Definition: pg_rewrite.h:51
FormData_pg_am * Form_pg_am
Definition: pg_am.h:46
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:86
char * get_tablespace_name(Oid spc_oid)
Definition: tablespace.c:1428
char * servername
Definition: foreign.h:50
FormData_pg_ts_template * Form_pg_ts_template
FormData_pg_publication_rel * Form_pg_publication_rel
#define NameStr(name)
Definition: c.h:576
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
#define elog
Definition: elog.h:219
FormData_pg_opclass * Form_pg_opclass
Definition: pg_opclass.h:81
char * get_rel_name(Oid relid)
Definition: lsyscache.c:1730
#define _(x)
Definition: elog.c:84
#define BTEqualStrategyNumber
Definition: stratnum.h:31
FormData_pg_statistic_ext * Form_pg_statistic_ext
char * get_subscription_name(Oid subid)

◆ getObjectDescriptionOids()

char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 3456 of file objectaddress.c.

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

3457 {
3458  ObjectAddress address;
3459 
3460  address.classId = classid;
3461  address.objectId = objid;
3462  address.objectSubId = 0;
3463 
3464  return getObjectDescription(&address);
3465 }
char * getObjectDescription(const ObjectAddress *object)

◆ getObjectIdentity()

◆ getObjectIdentityParts()

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

Definition at line 4081 of file objectaddress.c.

References _, AccessMethodOperatorOidIndexId, AccessMethodProcedureOidIndexId, AccessShareLock, AMOID, appendStringInfo(), appendStringInfoString(), Assert, AttrDefaultOidIndexId, BTEqualStrategyNumber, buffer, CLAOID, ObjectAddress::classId, COLLOID, CONSTROID, CONVOID, StringInfoData::data, 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_rel_name(), get_subscription_name(), get_tablespace_name(), GetForeignDataWrapper(), GetForeignServer(), getObjectClass(), getObjectIdentityParts(), getOpFamilyIdentity(), getRelationIdentity(), GETSTRUCT, GetUserNameFromId(), heap_close, heap_open(), HeapTupleIsValid, initStringInfo(), LANGOID, lappend(), list_make1, list_make2, list_make3, NameStr, NIL, ObjectAddress::objectId, ObjectIdAttributeNumber, 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(), TSCONFIGOID, TSDICTOID, TSPARSEROID, TSTEMPLATEOID, USERMAPPINGOID, and username.

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

4083 {
4085 
4086  initStringInfo(&buffer);
4087 
4088  /*
4089  * Make sure that both objname and objargs were passed, or none was; and
4090  * initialize them to empty lists. For objname this is useless because it
4091  * will be initialized in all cases inside the switch; but we do it anyway
4092  * so that we can test below that no branch leaves it unset.
4093  */
4094  Assert(PointerIsValid(objname) == PointerIsValid(objargs));
4095  if (objname)
4096  {
4097  *objname = NIL;
4098  *objargs = NIL;
4099  }
4100 
4101  switch (getObjectClass(object))
4102  {
4103  case OCLASS_CLASS:
4104  getRelationIdentity(&buffer, object->objectId, objname);
4105  if (object->objectSubId != 0)
4106  {
4107  char *attr;
4108 
4109  attr = get_attname(object->objectId, object->objectSubId,
4110  false);
4111  appendStringInfo(&buffer, ".%s", quote_identifier(attr));
4112  if (objname)
4113  *objname = lappend(*objname, attr);
4114  }
4115  break;
4116 
4117  case OCLASS_PROC:
4118  appendStringInfoString(&buffer,
4120  if (objname)
4121  format_procedure_parts(object->objectId, objname, objargs);
4122  break;
4123 
4124  case OCLASS_TYPE:
4125  {
4126  char *typeout;
4127 
4128  typeout = format_type_be_qualified(object->objectId);
4129  appendStringInfoString(&buffer, typeout);
4130  if (objname)
4131  *objname = list_make1(typeout);
4132  }
4133  break;
4134 
4135  case OCLASS_CAST:
4136  {
4137  Relation castRel;
4138  HeapTuple tup;
4139  Form_pg_cast castForm;
4140 
4141  castRel = heap_open(CastRelationId, AccessShareLock);
4142 
4143  tup = get_catalog_object_by_oid(castRel, object->objectId);
4144 
4145  if (!HeapTupleIsValid(tup))
4146  elog(ERROR, "could not find tuple for cast %u",
4147  object->objectId);
4148 
4149  castForm = (Form_pg_cast) GETSTRUCT(tup);
4150 
4151  appendStringInfo(&buffer, "(%s AS %s)",
4152  format_type_be_qualified(castForm->castsource),
4153  format_type_be_qualified(castForm->casttarget));
4154 
4155  if (objname)
4156  {
4157  *objname = list_make1(format_type_be_qualified(castForm->castsource));
4158  *objargs = list_make1(format_type_be_qualified(castForm->casttarget));
4159  }
4160 
4161  heap_close(castRel, AccessShareLock);
4162  break;
4163  }
4164 
4165  case OCLASS_COLLATION:
4166  {
4167  HeapTuple collTup;
4168  Form_pg_collation coll;
4169  char *schema;
4170 
4171  collTup = SearchSysCache1(COLLOID,
4172  ObjectIdGetDatum(object->objectId));
4173  if (!HeapTupleIsValid(collTup))
4174  elog(ERROR, "cache lookup failed for collation %u",
4175  object->objectId);
4176  coll = (Form_pg_collation) GETSTRUCT(collTup);
4177  schema = get_namespace_name_or_temp(coll->collnamespace);
4178  appendStringInfoString(&buffer,
4180  NameStr(coll->collname)));
4181  if (objname)
4182  *objname = list_make2(schema,
4183  pstrdup(NameStr(coll->collname)));
4184  ReleaseSysCache(collTup);
4185  break;
4186  }
4187 
4188  case OCLASS_CONSTRAINT:
4189  {
4190  HeapTuple conTup;
4191  Form_pg_constraint con;
4192 
4193  conTup = SearchSysCache1(CONSTROID,
4194  ObjectIdGetDatum(object->objectId));
4195  if (!HeapTupleIsValid(conTup))
4196  elog(ERROR, "cache lookup failed for constraint %u",
4197  object->objectId);
4198  con = (Form_pg_constraint) GETSTRUCT(conTup);
4199 
4200  if (OidIsValid(con->conrelid))
4201  {
4202  appendStringInfo(&buffer, "%s on ",
4203  quote_identifier(NameStr(con->conname)));
4204  getRelationIdentity(&buffer, con->conrelid, objname);
4205  if (objname)
4206  *objname = lappend(*objname, pstrdup(NameStr(con->conname)));
4207  }
4208  else
4209  {
4210  ObjectAddress domain;
4211 
4212  Assert(OidIsValid(con->contypid));
4213  domain.classId = TypeRelationId;
4214  domain.objectId = con->contypid;
4215  domain.objectSubId = 0;
4216 
4217  appendStringInfo(&buffer, "%s on %s",
4218  quote_identifier(NameStr(con->conname)),
4219  getObjectIdentityParts(&domain, objname, objargs));
4220 
4221  if (objname)
4222  *objargs = lappend(*objargs, pstrdup(NameStr(con->conname)));
4223  }
4224 
4225  ReleaseSysCache(conTup);
4226  break;
4227  }
4228 
4229  case OCLASS_CONVERSION:
4230  {
4231  HeapTuple conTup;
4232  Form_pg_conversion conForm;
4233  char *schema;
4234 
4235  conTup = SearchSysCache1(CONVOID,
4236  ObjectIdGetDatum(object->objectId));
4237  if (!HeapTupleIsValid(conTup))
4238  elog(ERROR, "cache lookup failed for conversion %u",
4239  object->objectId);
4240  conForm = (Form_pg_conversion) GETSTRUCT(conTup);
4241  schema = get_namespace_name_or_temp(conForm->connamespace);
4242  appendStringInfoString(&buffer,
4244  NameStr(conForm->conname)));
4245  if (objname)
4246  *objname = list_make2(schema,
4247  pstrdup(NameStr(conForm->conname)));
4248  ReleaseSysCache(conTup);
4249  break;
4250  }
4251 
4252  case OCLASS_DEFAULT:
4253  {
4254  Relation attrdefDesc;
4255  ScanKeyData skey[1];
4256  SysScanDesc adscan;
4257 
4258  HeapTuple tup;
4259  Form_pg_attrdef attrdef;
4260  ObjectAddress colobject;
4261 
4262  attrdefDesc = heap_open(AttrDefaultRelationId, AccessShareLock);
4263 
4264  ScanKeyInit(&skey[0],
4266  BTEqualStrategyNumber, F_OIDEQ,
4267  ObjectIdGetDatum(object->objectId));
4268 
4269  adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndexId,
4270  true, NULL, 1, skey);
4271 
4272  tup = systable_getnext(adscan);
4273 
4274  if (!HeapTupleIsValid(tup))
4275  elog(ERROR, "could not find tuple for attrdef %u",
4276  object->objectId);
4277 
4278  attrdef = (Form_pg_attrdef) GETSTRUCT(tup);
4279 
4280  colobject.classId = RelationRelationId;
4281  colobject.objectId = attrdef->adrelid;
4282  colobject.objectSubId = attrdef->adnum;
4283 
4284  appendStringInfo(&buffer, "for %s",
4285  getObjectIdentityParts(&colobject,
4286  objname, objargs));
4287 
4288  systable_endscan(adscan);
4289  heap_close(attrdefDesc, AccessShareLock);
4290  break;
4291  }
4292 
4293  case OCLASS_LANGUAGE:
4294  {
4295  HeapTuple langTup;
4296  Form_pg_language langForm;
4297 
4298  langTup = SearchSysCache1(LANGOID,
4299  ObjectIdGetDatum(object->objectId));
4300  if (!HeapTupleIsValid(langTup))
4301  elog(ERROR, "cache lookup failed for language %u",
4302  object->objectId);
4303  langForm = (Form_pg_language) GETSTRUCT(langTup);
4304  appendStringInfoString(&buffer,
4305  quote_identifier(NameStr(langForm->lanname)));
4306  if (objname)
4307  *objname = list_make1(pstrdup(NameStr(langForm->lanname)));
4308  ReleaseSysCache(langTup);
4309  break;
4310  }
4311  case OCLASS_LARGEOBJECT:
4312  appendStringInfo(&buffer, "%u",
4313  object->objectId);
4314  if (objname)
4315  *objname = list_make1(psprintf("%u", object->objectId));
4316  break;
4317 
4318  case OCLASS_OPERATOR:
4319  appendStringInfoString(&buffer,
4321  if (objname)
4322  format_operator_parts(object->objectId, objname, objargs);
4323  break;
4324 
4325  case OCLASS_OPCLASS:
4326  {
4327  HeapTuple opcTup;
4328  Form_pg_opclass opcForm;
4329  HeapTuple amTup;
4330  Form_pg_am amForm;
4331  char *schema;
4332 
4333  opcTup = SearchSysCache1(CLAOID,
4334  ObjectIdGetDatum(object->objectId));
4335  if (!HeapTupleIsValid(opcTup))
4336  elog(ERROR, "cache lookup failed for opclass %u",
4337  object->objectId);
4338  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
4339  schema = get_namespace_name_or_temp(opcForm->opcnamespace);
4340 
4341  amTup = SearchSysCache1(AMOID,
4342  ObjectIdGetDatum(opcForm->opcmethod));
4343  if (!HeapTupleIsValid(amTup))
4344  elog(ERROR, "cache lookup failed for access method %u",
4345  opcForm->opcmethod);
4346  amForm = (Form_pg_am) GETSTRUCT(amTup);
4347 
4348  appendStringInfo(&buffer, "%s USING %s",
4350  NameStr(opcForm->opcname)),
4351  quote_identifier(NameStr(amForm->amname)));
4352  if (objname)
4353  *objname = list_make3(pstrdup(NameStr(amForm->amname)),
4354  schema,
4355  pstrdup(NameStr(opcForm->opcname)));
4356 
4357  ReleaseSysCache(amTup);
4358  ReleaseSysCache(opcTup);
4359  break;
4360  }
4361 
4362  case OCLASS_OPFAMILY:
4363  getOpFamilyIdentity(&buffer, object->objectId, objname);
4364  break;
4365 
4366  case OCLASS_AM:
4367  {
4368  char *amname;
4369 
4370  amname = get_am_name(object->objectId);
4371  if (!amname)
4372  elog(ERROR, "cache lookup failed for access method %u",
4373  object->objectId);
4374  appendStringInfoString(&buffer, quote_identifier(amname));
4375  if (objname)
4376  *objname = list_make1(amname);
4377  }
4378  break;
4379 
4380  case OCLASS_AMOP:
4381  {
4382  Relation amopDesc;
4383  HeapTuple tup;
4384  ScanKeyData skey[1];
4385  SysScanDesc amscan;
4386  Form_pg_amop amopForm;
4387  StringInfoData opfam;
4388  char *ltype;
4389  char *rtype;
4390 
4391  amopDesc = heap_open(AccessMethodOperatorRelationId,
4392  AccessShareLock);
4393 
4394  ScanKeyInit(&skey[0],
4396  BTEqualStrategyNumber, F_OIDEQ,
4397  ObjectIdGetDatum(object->objectId));
4398 
4399  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
4400  NULL, 1, skey);
4401 
4402  tup = systable_getnext(amscan);
4403 
4404  if (!HeapTupleIsValid(tup))
4405  elog(ERROR, "could not find tuple for amop entry %u",
4406  object->objectId);
4407 
4408  amopForm = (Form_pg_amop) GETSTRUCT(tup);
4409 
4410  initStringInfo(&opfam);
4411  getOpFamilyIdentity(&opfam, amopForm->amopfamily, objname);
4412 
4413  ltype = format_type_be_qualified(amopForm->amoplefttype);
4414  rtype = format_type_be_qualified(amopForm->amoprighttype);
4415 
4416  if (objname)
4417  {
4418  *objname = lappend(*objname,
4419  psprintf("%d", amopForm->amopstrategy));
4420  *objargs = list_make2(ltype, rtype);
4421  }
4422 
4423  appendStringInfo(&buffer, "operator %d (%s, %s) of %s",
4424  amopForm->amopstrategy,
4425  ltype, rtype, opfam.data);
4426 
4427  pfree(opfam.data);
4428 
4429  systable_endscan(amscan);
4430  heap_close(amopDesc, AccessShareLock);
4431  break;
4432  }
4433 
4434  case OCLASS_AMPROC:
4435  {
4436  Relation amprocDesc;
4437  ScanKeyData skey[1];
4438  SysScanDesc amscan;
4439  HeapTuple tup;
4440  Form_pg_amproc amprocForm;
4441  StringInfoData opfam;
4442  char *ltype;
4443  char *rtype;
4444 
4445  amprocDesc = heap_open(AccessMethodProcedureRelationId,
4446  AccessShareLock);
4447 
4448  ScanKeyInit(&skey[0],
4450  BTEqualStrategyNumber, F_OIDEQ,
4451  ObjectIdGetDatum(object->objectId));
4452 
4453  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
4454  NULL, 1, skey);
4455 
4456  tup = systable_getnext(amscan);
4457 
4458  if (!HeapTupleIsValid(tup))
4459  elog(ERROR, "could not find tuple for amproc entry %u",
4460  object->objectId);
4461 
4462  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
4463 
4464  initStringInfo(&opfam);
4465  getOpFamilyIdentity(&opfam, amprocForm->amprocfamily, objname);
4466 
4467  ltype = format_type_be_qualified(amprocForm->amproclefttype);
4468  rtype = format_type_be_qualified(amprocForm->amprocrighttype);
4469 
4470  if (objname)
4471  {
4472  *objname = lappend(*objname,
4473  psprintf("%d", amprocForm->amprocnum));
4474  *objargs = list_make2(ltype, rtype);
4475  }
4476 
4477  appendStringInfo(&buffer, "function %d (%s, %s) of %s",
4478  amprocForm->amprocnum,
4479  ltype, rtype, opfam.data);
4480 
4481  pfree(opfam.data);
4482 
4483  systable_endscan(amscan);
4484  heap_close(amprocDesc, AccessShareLock);
4485  break;
4486  }
4487 
4488  case OCLASS_REWRITE:
4489  {
4490  Relation ruleDesc;
4491  HeapTuple tup;
4493 
4494  ruleDesc = heap_open(RewriteRelationId, AccessShareLock);
4495 
4496  tup = get_catalog_object_by_oid(ruleDesc, object->objectId);
4497 
4498  if (!HeapTupleIsValid(tup))
4499  elog(ERROR, "could not find tuple for rule %u",
4500  object->objectId);
4501 
4502  rule = (Form_pg_rewrite) GETSTRUCT(tup);
4503 
4504  appendStringInfo(&buffer, "%s on ",
4505  quote_identifier(NameStr(rule->rulename)));
4506  getRelationIdentity(&buffer, rule->ev_class, objname);
4507  if (objname)
4508  *objname = lappend(*objname, pstrdup(NameStr(rule->rulename)));
4509 
4510  heap_close(ruleDesc, AccessShareLock);
4511  break;
4512  }
4513 
4514  case OCLASS_TRIGGER:
4515  {
4516  Relation trigDesc;
4517  HeapTuple tup;
4518  Form_pg_trigger trig;
4519 
4520  trigDesc = heap_open(TriggerRelationId, AccessShareLock);
4521 
4522  tup = get_catalog_object_by_oid(trigDesc, object->objectId);
4523 
4524  if (!HeapTupleIsValid(tup))
4525  elog(ERROR, "could not find tuple for trigger %u",
4526  object->objectId);
4527 
4528  trig = (Form_pg_trigger) GETSTRUCT(tup);
4529 
4530  appendStringInfo(&buffer, "%s on ",
4531  quote_identifier(NameStr(trig->tgname)));
4532  getRelationIdentity(&buffer, trig->tgrelid, objname);
4533  if (objname)
4534  *objname = lappend(*objname, pstrdup(NameStr(trig->tgname)));
4535 
4536  heap_close(trigDesc, AccessShareLock);
4537  break;
4538  }
4539 
4540  case OCLASS_SCHEMA:
4541  {
4542  char *nspname;
4543 
4544  nspname = get_namespace_name_or_temp(object->objectId);
4545  if (!nspname)
4546  elog(ERROR, "cache lookup failed for namespace %u",
4547  object->objectId);
4548  appendStringInfoString(&buffer,
4549  quote_identifier(nspname));
4550  if (objname)
4551  *objname = list_make1(nspname);
4552  break;
4553  }
4554 
4555  case OCLASS_STATISTIC_EXT:
4556  {
4557  HeapTuple tup;
4558  Form_pg_statistic_ext formStatistic;
4559  char *schema;
4560 
4562  ObjectIdGetDatum(object->objectId));
4563  if (!HeapTupleIsValid(tup))
4564  elog(ERROR, "cache lookup failed for statistics object %u",
4565  object->objectId);
4566  formStatistic = (Form_pg_statistic_ext) GETSTRUCT(tup);
4567  schema = get_namespace_name_or_temp(formStatistic->stxnamespace);
4568  appendStringInfoString(&buffer,
4570  NameStr(formStatistic->stxname)));
4571  if (objname)
4572  *objname = list_make2(schema,
4573  pstrdup(NameStr(formStatistic->stxname)));
4574  ReleaseSysCache(tup);
4575  }
4576  break;
4577 
4578  case OCLASS_TSPARSER:
4579  {
4580  HeapTuple tup;
4581  Form_pg_ts_parser formParser;
4582  char *schema;
4583 
4585  ObjectIdGetDatum(object->objectId));
4586  if (!HeapTupleIsValid(tup))
4587  elog(ERROR, "cache lookup failed for text search parser %u",
4588  object->objectId);
4589  formParser = (Form_pg_ts_parser) GETSTRUCT(tup);
4590  schema = get_namespace_name_or_temp(formParser->prsnamespace);
4591  appendStringInfoString(&buffer,
4593  NameStr(formParser->prsname)));
4594  if (objname)
4595  *objname = list_make2(schema,
4596  pstrdup(NameStr(formParser->prsname)));
4597  ReleaseSysCache(tup);
4598  break;
4599  }
4600 
4601  case OCLASS_TSDICT:
4602  {
4603  HeapTuple tup;
4604  Form_pg_ts_dict formDict;
4605  char *schema;
4606 
4607  tup = SearchSysCache1(TSDICTOID,
4608  ObjectIdGetDatum(object->objectId));
4609  if (!HeapTupleIsValid(tup))
4610  elog(ERROR, "cache lookup failed for text search dictionary %u",
4611  object->objectId);
4612  formDict = (Form_pg_ts_dict) GETSTRUCT(tup);
4613  schema = get_namespace_name_or_temp(formDict->dictnamespace);
4614  appendStringInfoString(&buffer,
4616  NameStr(formDict->dictname)));
4617  if (objname)
4618  *objname = list_make2(schema,
4619  pstrdup(NameStr(formDict->dictname)));
4620  ReleaseSysCache(tup);
4621  break;
4622  }
4623 
4624  case OCLASS_TSTEMPLATE:
4625  {
4626  HeapTuple tup;
4627  Form_pg_ts_template formTmpl;
4628  char *schema;
4629 
4631  ObjectIdGetDatum(object->objectId));
4632  if (!HeapTupleIsValid(tup))
4633  elog(ERROR, "cache lookup failed for text search template %u",
4634  object->objectId);
4635  formTmpl = (Form_pg_ts_template) GETSTRUCT(tup);
4636  schema = get_namespace_name_or_temp(formTmpl->tmplnamespace);
4637  appendStringInfoString(&buffer,
4639  NameStr(formTmpl->tmplname)));
4640  if (objname)
4641  *objname = list_make2(schema,
4642  pstrdup(NameStr(formTmpl->tmplname)));
4643  ReleaseSysCache(tup);
4644  break;
4645  }
4646 
4647  case OCLASS_TSCONFIG:
4648  {
4649  HeapTuple tup;
4650  Form_pg_ts_config formCfg;
4651  char *schema;
4652 
4654  ObjectIdGetDatum(object->objectId));
4655  if (!HeapTupleIsValid(tup))
4656  elog(ERROR, "cache lookup failed for text search configuration %u",
4657  object->objectId);
4658  formCfg = (Form_pg_ts_config) GETSTRUCT(tup);
4659  schema = get_namespace_name_or_temp(formCfg->cfgnamespace);
4660  appendStringInfoString(&buffer,
4662  NameStr(formCfg->cfgname)));
4663  if (objname)
4664  *objname = list_make2(schema,
4665  pstrdup(NameStr(formCfg->cfgname)));
4666  ReleaseSysCache(tup);
4667  break;
4668  }
4669 
4670  case OCLASS_ROLE:
4671  {
4672  char *username;
4673 
4674  username = GetUserNameFromId(object->objectId, false);
4675  if (objname)
4676  *objname = list_make1(username);
4677  appendStringInfoString(&buffer,
4678  quote_identifier(username));
4679  break;
4680  }
4681 
4682  case OCLASS_DATABASE:
4683  {
4684  char *datname;
4685 
4686  datname = get_database_name(object->objectId);
4687  if (!datname)
4688  elog(ERROR, "cache lookup failed for database %u",
4689  object->objectId);
4690  if (objname)
4691  *objname = list_make1(datname);
4692  appendStringInfoString(&buffer,
4693  quote_identifier(datname));
4694  break;
4695  }
4696 
4697  case OCLASS_TBLSPACE:
4698  {
4699  char *tblspace;
4700 
4701  tblspace = get_tablespace_name(object->objectId);
4702  if (!tblspace)
4703  elog(ERROR, "cache lookup failed for tablespace %u",
4704  object->objectId);
4705  if (objname)
4706  *objname = list_make1(tblspace);
4707  appendStringInfoString(&buffer,
4708  quote_identifier(tblspace));
4709  break;
4710  }
4711 
4712  case OCLASS_FDW:
4713  {
4714  ForeignDataWrapper *fdw;
4715 
4716  fdw = GetForeignDataWrapper(object->objectId);
4718  if (objname)
4719  *objname = list_make1(pstrdup(fdw->fdwname));
4720  break;
4721  }
4722 
4723  case OCLASS_FOREIGN_SERVER:
4724  {
4725  ForeignServer *srv;
4726 
4727  srv = GetForeignServer(object->objectId);
4728  appendStringInfoString(&buffer,
4730  if (objname)
4731  *objname = list_make1(pstrdup(srv->servername));
4732  break;
4733  }
4734 
4735  case OCLASS_USER_MAPPING:
4736  {
4737  HeapTuple tup;
4738  Oid useid;
4739  Form_pg_user_mapping umform;
4740  ForeignServer *srv;
4741  const char *usename;
4742 
4744  ObjectIdGetDatum(object->objectId));
4745  if (!HeapTupleIsValid(tup))
4746  elog(ERROR, "cache lookup failed for user mapping %u",
4747  object->objectId);
4748  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
4749  useid = umform->umuser;
4750  srv = GetForeignServer(umform->umserver);
4751 
4752  ReleaseSysCache(tup);
4753 
4754  if (OidIsValid(useid))
4755  usename = GetUserNameFromId(useid, false);
4756  else
4757  usename = "public";
4758 
4759  if (objname)
4760  {
4761  *objname = list_make1(pstrdup(usename));
4762  *objargs = list_make1(pstrdup(srv->servername));
4763  }
4764 
4765  appendStringInfo(&buffer, "%s on server %s",
4766  quote_identifier(usename),
4767  srv->servername);
4768  break;
4769  }
4770 
4771  case OCLASS_DEFACL:
4772  {
4773  Relation defaclrel;
4774  ScanKeyData skey[1];
4775  SysScanDesc rcscan;
4776  HeapTuple tup;
4777  Form_pg_default_acl defacl;
4778  char *schema;
4779  char *username;
4780 
4781  defaclrel = heap_open(DefaultAclRelationId, AccessShareLock);
4782 
4783  ScanKeyInit(&skey[0],
4785  BTEqualStrategyNumber, F_OIDEQ,
4786  ObjectIdGetDatum(object->objectId));
4787 
4788  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
4789  true, NULL, 1, skey);
4790 
4791  tup = systable_getnext(rcscan);
4792 
4793  if (!HeapTupleIsValid(tup))
4794  elog(ERROR, "could not find tuple for default ACL %u",
4795  object->objectId);
4796 
4797  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
4798 
4799  username = GetUserNameFromId(defacl->defaclrole, false);
4800  appendStringInfo(&buffer,
4801  "for role %s",
4802  quote_identifier(username));
4803 
4804  if (OidIsValid(defacl->defaclnamespace))
4805  {
4806  schema = get_namespace_name_or_temp(defacl->defaclnamespace);
4807  appendStringInfo(&buffer,
4808  " in schema %s",
4809  quote_identifier(schema));
4810  }
4811  else
4812  schema = NULL;
4813 
4814  switch (defacl->defaclobjtype)
4815  {
4816  case DEFACLOBJ_RELATION:
4817  appendStringInfoString(&buffer,
4818  " on tables");
4819  break;
4820  case DEFACLOBJ_SEQUENCE:
4821  appendStringInfoString(&buffer,
4822  " on sequences");
4823  break;
4824  case DEFACLOBJ_FUNCTION:
4825  appendStringInfoString(&buffer,
4826  " on functions");
4827  break;
4828  case DEFACLOBJ_TYPE:
4829  appendStringInfoString(&buffer,
4830  " on types");
4831  break;
4832  case DEFACLOBJ_NAMESPACE:
4833  appendStringInfoString(&buffer,
4834  " on schemas");
4835  break;
4836  }
4837 
4838  if (objname)
4839  {
4840  *objname = list_make1(username);
4841  if (schema)
4842  *objname = lappend(*objname, schema);
4843  *objargs = list_make1(psprintf("%c", defacl->defaclobjtype));
4844  }
4845 
4846  systable_endscan(rcscan);
4847  heap_close(defaclrel, AccessShareLock);
4848  break;
4849  }
4850 
4851  case OCLASS_EXTENSION:
4852  {
4853  char *extname;
4854 
4855  extname = get_extension_name(object->objectId);
4856  if (!extname)
4857  elog(ERROR, "cache lookup failed for extension %u",
4858  object->objectId);
4859  appendStringInfoString(&buffer, quote_identifier(extname));
4860  if (objname)
4861  *objname = list_make1(extname);
4862  break;
4863  }
4864 
4865  case OCLASS_EVENT_TRIGGER:
4866  {
4867  HeapTuple tup;
4868  Form_pg_event_trigger trigForm;
4869 
4870  /* no objname support here */
4871  if (objname)
4872  *objname = NIL;
4873 
4875  ObjectIdGetDatum(object->objectId));
4876  if (!HeapTupleIsValid(tup))
4877  elog(ERROR, "cache lookup failed for event trigger %u",
4878  object->objectId);
4879  trigForm = (Form_pg_event_trigger) GETSTRUCT(tup);
4880  appendStringInfoString(&buffer,
4881  quote_identifier(NameStr(trigForm->evtname)));
4882  ReleaseSysCache(tup);
4883  break;
4884  }
4885 
4886  case OCLASS_POLICY:
4887  {
4888  Relation polDesc;
4889  HeapTuple tup;
4890  Form_pg_policy policy;
4891 
4892  polDesc = heap_open(PolicyRelationId, AccessShareLock);
4893 
4894  tup = get_catalog_object_by_oid(polDesc, object->objectId);
4895 
4896  if (!HeapTupleIsValid(tup))
4897  elog(ERROR, "could not find tuple for policy %u",
4898  object->objectId);
4899 
4900  policy = (Form_pg_policy) GETSTRUCT(tup);
4901 
4902  appendStringInfo(&buffer, "%s on ",
4903  quote_identifier(NameStr(policy->polname)));
4904  getRelationIdentity(&buffer, policy->polrelid, objname);
4905  if (objname)
4906  *objname = lappend(*objname, pstrdup(NameStr(policy->polname)));
4907 
4908  heap_close(polDesc, AccessShareLock);
4909  break;
4910  }
4911 
4912  case OCLASS_PUBLICATION:
4913  {
4914  char *pubname;
4915 
4916  pubname = get_publication_name(object->objectId);
4917  appendStringInfoString(&buffer,
4918  quote_identifier(pubname));
4919  if (objname)
4920  *objname = list_make1(pubname);
4921  break;
4922  }
4923 
4925  {
4926  HeapTuple tup;
4927  char *pubname;
4928  Form_pg_publication_rel prform;
4929 
4931  ObjectIdGetDatum(object->objectId));
4932  if (!HeapTupleIsValid(tup))
4933  elog(ERROR, "cache lookup failed for publication table %u",
4934  object->objectId);
4935 
4936  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
4937  pubname = get_publication_name(prform->prpubid);
4938 
4939  appendStringInfo(&buffer, _("%s in publication %s"),
4940  get_rel_name(prform->prrelid), pubname);
4941 
4942  if (objname)
4943  {
4944  getRelationIdentity(&buffer, prform->prrelid, objname);
4945  *objargs = list_make1(pubname);
4946  }
4947 
4948  ReleaseSysCache(tup);
4949  break;
4950  }
4951 
4952  case OCLASS_SUBSCRIPTION: