PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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_constraint_fn.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 "libpq/be-fsstubs.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/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)
 
AclObjectKind get_object_aclkind (Oid class_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)
 

Variables

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

Function Documentation

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

Definition at line 2222 of file objectaddress.c.

References ACL_KIND_CLASS, ACL_KIND_COLLATION, ACL_KIND_CONVERSION, ACL_KIND_DATABASE, ACL_KIND_EVENT_TRIGGER, ACL_KIND_EXTENSION, ACL_KIND_FDW, ACL_KIND_FOREIGN_SERVER, ACL_KIND_LANGUAGE, ACL_KIND_NAMESPACE, ACL_KIND_OPCLASS, ACL_KIND_OPER, ACL_KIND_OPFAMILY, ACL_KIND_PROC, ACL_KIND_PUBLICATION, ACL_KIND_SUBSCRIPTION, ACL_KIND_TABLESPACE, ACL_KIND_TSCONFIGURATION, ACL_KIND_TSDICTIONARY, 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(), NULL, 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_PUBLICATION, OBJECT_ROLE, 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().

2224 {
2225  switch (objtype)
2226  {
2227  case OBJECT_INDEX:
2228  case OBJECT_SEQUENCE:
2229  case OBJECT_TABLE:
2230  case OBJECT_VIEW:
2231  case OBJECT_MATVIEW:
2232  case OBJECT_FOREIGN_TABLE:
2233  case OBJECT_COLUMN:
2234  case OBJECT_RULE:
2235  case OBJECT_TRIGGER:
2236  case OBJECT_POLICY:
2237  case OBJECT_TABCONSTRAINT:
2238  if (!pg_class_ownercheck(RelationGetRelid(relation), roleid))
2240  RelationGetRelationName(relation));
2241  break;
2242  case OBJECT_DATABASE:
2243  if (!pg_database_ownercheck(address.objectId, roleid))
2245  strVal((Value *) object));
2246  break;
2247  case OBJECT_TYPE:
2248  case OBJECT_DOMAIN:
2249  case OBJECT_ATTRIBUTE:
2250  case OBJECT_DOMCONSTRAINT:
2251  if (!pg_type_ownercheck(address.objectId, roleid))
2253  break;
2254  case OBJECT_AGGREGATE:
2255  case OBJECT_FUNCTION:
2256  if (!pg_proc_ownercheck(address.objectId, roleid))
2258  NameListToString((castNode(ObjectWithArgs, object))->objname));
2259  break;
2260  case OBJECT_OPERATOR:
2261  if (!pg_oper_ownercheck(address.objectId, roleid))
2263  NameListToString((castNode(ObjectWithArgs, object))->objname));
2264  break;
2265  case OBJECT_SCHEMA:
2266  if (!pg_namespace_ownercheck(address.objectId, roleid))
2268  strVal((Value *) object));
2269  break;
2270  case OBJECT_COLLATION:
2271  if (!pg_collation_ownercheck(address.objectId, roleid))
2273  NameListToString(castNode(List, object)));
2274  break;
2275  case OBJECT_CONVERSION:
2276  if (!pg_conversion_ownercheck(address.objectId, roleid))
2278  NameListToString(castNode(List, object)));
2279  break;
2280  case OBJECT_EXTENSION:
2281  if (!pg_extension_ownercheck(address.objectId, roleid))
2283  strVal((Value *) object));
2284  break;
2285  case OBJECT_FDW:
2286  if (!pg_foreign_data_wrapper_ownercheck(address.objectId, roleid))
2288  strVal((Value *) object));
2289  break;
2290  case OBJECT_FOREIGN_SERVER:
2291  if (!pg_foreign_server_ownercheck(address.objectId, roleid))
2293  strVal((Value *) object));
2294  break;
2295  case OBJECT_EVENT_TRIGGER:
2296  if (!pg_event_trigger_ownercheck(address.objectId, roleid))
2298  strVal((Value *) object));
2299  break;
2300  case OBJECT_LANGUAGE:
2301  if (!pg_language_ownercheck(address.objectId, roleid))
2303  strVal((Value *) object));
2304  break;
2305  case OBJECT_OPCLASS:
2306  if (!pg_opclass_ownercheck(address.objectId, roleid))
2308  NameListToString(castNode(List, object)));
2309  break;
2310  case OBJECT_OPFAMILY:
2311  if (!pg_opfamily_ownercheck(address.objectId, roleid))
2313  NameListToString(castNode(List, object)));
2314  break;
2315  case OBJECT_LARGEOBJECT:
2316  if (!lo_compat_privileges &&
2317  !pg_largeobject_ownercheck(address.objectId, roleid))
2318  ereport(ERROR,
2319  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2320  errmsg("must be owner of large object %u",
2321  address.objectId)));
2322  break;
2323  case OBJECT_CAST:
2324  {
2325  /* We can only check permissions on the source/target types */
2326  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2327  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2328  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2329  Oid targettypeid = typenameTypeId(NULL, targettype);
2330 
2331  if (!pg_type_ownercheck(sourcetypeid, roleid)
2332  && !pg_type_ownercheck(targettypeid, roleid))
2333  ereport(ERROR,
2334  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2335  errmsg("must be owner of type %s or type %s",
2336  format_type_be(sourcetypeid),
2337  format_type_be(targettypeid))));
2338  }
2339  break;
2340  case OBJECT_PUBLICATION:
2341  if (!pg_publication_ownercheck(address.objectId, roleid))
2343  strVal((Value *) object));
2344  break;
2345  case OBJECT_SUBSCRIPTION:
2346  if (!pg_subscription_ownercheck(address.objectId, roleid))
2348  strVal((Value *) object));
2349  break;
2350  case OBJECT_TRANSFORM:
2351  {
2352  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2353  Oid typeid = typenameTypeId(NULL, typename);
2354 
2355  if (!pg_type_ownercheck(typeid, roleid))
2357  }
2358  break;
2359  case OBJECT_TABLESPACE:
2360  if (!pg_tablespace_ownercheck(address.objectId, roleid))
2362  strVal((Value *) object));
2363  break;
2364  case OBJECT_TSDICTIONARY:
2365  if (!pg_ts_dict_ownercheck(address.objectId, roleid))
2367  NameListToString(castNode(List, object)));
2368  break;
2370  if (!pg_ts_config_ownercheck(address.objectId, roleid))
2372  NameListToString(castNode(List, object)));
2373  break;
2374  case OBJECT_ROLE:
2375 
2376  /*
2377  * We treat roles as being "owned" by those with CREATEROLE priv,
2378  * except that superusers are only owned by superusers.
2379  */
2380  if (superuser_arg(address.objectId))
2381  {
2382  if (!superuser_arg(roleid))
2383  ereport(ERROR,
2384  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2385  errmsg("must be superuser")));
2386  }
2387  else
2388  {
2389  if (!has_createrole_privilege(roleid))
2390  ereport(ERROR,
2391  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2392  errmsg("must have CREATEROLE privilege")));
2393  }
2394  break;
2395  case OBJECT_TSPARSER:
2396  case OBJECT_TSTEMPLATE:
2397  case OBJECT_ACCESS_METHOD:
2398  /* We treat these object types as being owned by superusers */
2399  if (!superuser_arg(roleid))
2400  ereport(ERROR,
2401  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2402  errmsg("must be superuser")));
2403  break;
2404  case OBJECT_STATISTIC_EXT:
2405  if (!pg_statistics_object_ownercheck(address.objectId, roleid))
2407  break;
2408  default:
2409  elog(ERROR, "unrecognized object type: %d",
2410  (int) objtype);
2411  }
2412 }
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:5171
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:4990
bool pg_largeobject_ownercheck(Oid lobj_oid, Oid roleid)
Definition: aclchk.c:4679
bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid)
Definition: aclchk.c:4829
bool pg_language_ownercheck(Oid lan_oid, Oid roleid)
Definition: aclchk.c:4650
#define castNode(_type_, nodeptr)
Definition: nodes.h:578
bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid)
Definition: aclchk.c:4856
bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:4910
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5084
#define strVal(v)
Definition: value.h:54
bool pg_oper_ownercheck(Oid oper_oid, Oid roleid)
Definition: aclchk.c:4598
int errcode(int sqlerrcode)
Definition: elog.c:575
char * format_type_be(Oid type_oid)
Definition: format_type.c:94
bool pg_namespace_ownercheck(Oid nsp_oid, Oid roleid)
Definition: aclchk.c:4722
unsigned int Oid
Definition: postgres_ext.h:31
bool pg_type_ownercheck(Oid type_oid, Oid roleid)
Definition: aclchk.c:4572
#define linitial_node(type, l)
Definition: pg_list.h:114
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3457
bool lo_compat_privileges
Definition: be-fsstubs.c:57
#define ERROR
Definition: elog.h:43
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:4937
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5042
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3399
#define RelationGetRelationName(relation)
Definition: rel.h:436
bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid)
Definition: aclchk.c:4748
bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
Definition: aclchk.c:4802
#define ereport(elevel, rest)
Definition: elog.h:122
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
Definition: aclchk.c:4964
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
char * NameListToString(List *names)
Definition: namespace.c:3063
#define lsecond_node(type, l)
Definition: pg_list.h:119
bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid)
Definition: aclchk.c:4775
bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid)
Definition: aclchk.c:5016
#define NULL
Definition: c.h:229
Definition: value.h:42
bool pg_class_ownercheck(Oid class_oid, Oid roleid)
Definition: aclchk.c:4546
bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:4883
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:416
bool pg_proc_ownercheck(Oid proc_oid, Oid roleid)
Definition: aclchk.c:4624
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:274
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5110
bool pg_statistics_object_ownercheck(Oid stat_oid, Oid roleid)
Definition: aclchk.c:5136
HeapTuple get_catalog_object_by_oid ( Relation  catalog,
Oid  objectId 
)

Definition at line 2608 of file objectaddress.c.

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

2609 {
2610  HeapTuple tuple;
2611  Oid classId = RelationGetRelid(catalog);
2612  int oidCacheId = get_object_catcache_oid(classId);
2613 
2614  if (oidCacheId > 0)
2615  {
2616  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2617  if (!HeapTupleIsValid(tuple)) /* should not happen */
2618  return NULL;
2619  }
2620  else
2621  {
2622  Oid oidIndexId = get_object_oid_index(classId);
2623  SysScanDesc scan;
2624  ScanKeyData skey;
2625 
2626  Assert(OidIsValid(oidIndexId));
2627 
2628  ScanKeyInit(&skey,
2630  BTEqualStrategyNumber, F_OIDEQ,
2631  ObjectIdGetDatum(objectId));
2632 
2633  scan = systable_beginscan(catalog, oidIndexId, true,
2634  NULL, 1, &skey);
2635  tuple = systable_getnext(scan);
2636  if (!HeapTupleIsValid(tuple))
2637  {
2638  systable_endscan(scan);
2639  return NULL;
2640  }
2641  tuple = heap_copytuple(tuple);
2642 
2643  systable_endscan(scan);
2644  }
2645 
2646  return tuple;
2647 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:608
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:499
#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:538
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:328
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:416
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
int get_object_catcache_oid(Oid class_id)
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:165
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define RelationGetRelid(relation)
Definition: rel.h:416
#define BTEqualStrategyNumber
Definition: stratnum.h:31
AclObjectKind get_object_aclkind ( Oid  class_id)

Definition at line 2536 of file objectaddress.c.

References ObjectPropertyType::acl_kind, and get_object_property_data().

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

2537 {
2538  const ObjectPropertyType *prop = get_object_property_data(class_id);
2539 
2540  return prop->acl_kind;
2541 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AclObjectKind acl_kind
ObjectAddress get_object_address ( ObjectType  objtype,
Node object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)

Definition at line 795 of file objectaddress.c.

References Assert, castNode, CastRelationId, ObjectAddress::classId, CollationRelationId, ConstraintRelationId, ConversionRelationId, 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(), LargeObjectRelationId, linitial_node, LockDatabaseObject(), LockSharedObject(), LookupAggWithArgs(), LookupFuncWithArgs(), LookupOperWithArgs(), LookupTypeNameOid(), lsecond, lsecond_node, NoLock, NULL, 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_PUBLICATION, OBJECT_PUBLICATION_REL, OBJECT_ROLE, 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(), OperatorRelationId, ProcedureRelationId, RelationRelationId, SharedInvalidMessageCounter, StatisticExtRelationId, strVal, TransformRelationId, TSConfigRelationId, TSDictionaryRelationId, TSParserRelationId, TSTemplateRelationId, UnlockDatabaseObject(), and UnlockSharedObject().

Referenced by CommentObject(), ExecAlterExtensionContentsStmt(), ExecAlterObjectDependsStmt(), ExecAlterObjectSchemaStmt(), ExecAlterOwnerStmt(), ExecRenameStmt(), ExecSecLabelStmt(), get_object_address_rv(), pg_get_object_address(), and RemoveObjects().

797 {
798  ObjectAddress address;
799  ObjectAddress old_address = {InvalidOid, InvalidOid, 0};
800  Relation relation = NULL;
801  uint64 inval_count;
802 
803  /* Some kind of lock must be taken. */
804  Assert(lockmode != NoLock);
805 
806  for (;;)
807  {
808  /*
809  * Remember this value, so that, after looking up the object name and
810  * locking it, we can check whether any invalidation messages have
811  * been processed that might require a do-over.
812  */
813  inval_count = SharedInvalidMessageCounter;
814 
815  /* Look up object address. */
816  switch (objtype)
817  {
818  case OBJECT_INDEX:
819  case OBJECT_SEQUENCE:
820  case OBJECT_TABLE:
821  case OBJECT_VIEW:
822  case OBJECT_MATVIEW:
824  address =
825  get_relation_by_qualified_name(objtype, castNode(List, object),
826  &relation, lockmode,
827  missing_ok);
828  break;
829  case OBJECT_COLUMN:
830  address =
831  get_object_address_attribute(objtype, castNode(List, object),
832  &relation, lockmode,
833  missing_ok);
834  break;
835  case OBJECT_DEFAULT:
836  address =
837  get_object_address_attrdef(objtype, castNode(List, object),
838  &relation, lockmode,
839  missing_ok);
840  break;
841  case OBJECT_RULE:
842  case OBJECT_TRIGGER:
844  case OBJECT_POLICY:
845  address = get_object_address_relobject(objtype, castNode(List, object),
846  &relation, missing_ok);
847  break;
849  {
850  List *objlist;
851  ObjectAddress domaddr;
852  char *constrname;
853 
854  objlist = castNode(List, object);
856  linitial_node(TypeName, objlist),
857  missing_ok);
858  constrname = strVal(lsecond(objlist));
859 
860  address.classId = ConstraintRelationId;
861  address.objectId = get_domain_constraint_oid(domaddr.objectId,
862  constrname, missing_ok);
863  address.objectSubId = 0;
864 
865  }
866  break;
867  case OBJECT_DATABASE:
868  case OBJECT_EXTENSION:
869  case OBJECT_TABLESPACE:
870  case OBJECT_ROLE:
871  case OBJECT_SCHEMA:
872  case OBJECT_LANGUAGE:
873  case OBJECT_FDW:
877  case OBJECT_PUBLICATION:
878  case OBJECT_SUBSCRIPTION:
879  address = get_object_address_unqualified(objtype,
880  (Value *) object, missing_ok);
881  break;
882  case OBJECT_TYPE:
883  case OBJECT_DOMAIN:
884  address = get_object_address_type(objtype, castNode(TypeName, object), missing_ok);
885  break;
886  case OBJECT_AGGREGATE:
887  address.classId = ProcedureRelationId;
888  address.objectId = LookupAggWithArgs(castNode(ObjectWithArgs, object), missing_ok);
889  address.objectSubId = 0;
890  break;
891  case OBJECT_FUNCTION:
892  address.classId = ProcedureRelationId;
893  address.objectId = LookupFuncWithArgs(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:
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;
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
#define OperatorRelationId
Definition: pg_operator.h:32
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
#define TransformRelationId
Definition: pg_transform.h:25
static ObjectAddress get_object_address_attribute(ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
#define castNode(_type_, nodeptr)
Definition: nodes.h:578
#define ProcedureRelationId
Definition: pg_proc.h:33
#define RelationRelationId
Definition: pg_class.h:29
Oid get_language_oid(const char *langname, bool missing_ok)
Definition: proclang.c:553
#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:2639
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:538
#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)
#define TSConfigRelationId
Definition: pg_ts_config.h:31
Oid get_ts_dict_oid(List *names, bool missing_ok)
Definition: namespace.c:2386
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:892
#define TSDictionaryRelationId
Definition: pg_ts_dict.h:31
Oid get_statistics_object_oid(List *names, bool missing_ok)
Definition: namespace.c:2138
Oid get_ts_template_oid(List *names, bool missing_ok)
Definition: namespace.c:2513
#define NoLock
Definition: lockdefs.h:34
static ObjectAddress get_object_address_relobject(ObjectType objtype, List *object, Relation *relp, bool missing_ok)
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:830
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
Oid LookupFuncWithArgs(ObjectWithArgs *func, bool noError)
Definition: parse_func.c:1990
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:851
#define lsecond_node(type, l)
Definition: pg_list.h:119
Oid LookupAggWithArgs(ObjectWithArgs *agg, bool noError)
Definition: parse_func.c:2027
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:220
#define TSParserRelationId
Definition: pg_ts_parser.h:31
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:871
uint64 SharedInvalidMessageCounter
Definition: sinval.c:26
#define CollationRelationId
Definition: pg_collation.h:30
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
Oid get_ts_parser_oid(List *names, bool missing_ok)
Definition: namespace.c:2260
#define Assert(condition)
Definition: c.h:675
#define StatisticExtRelationId
Definition: value.h:42
static ObjectAddress get_object_address_opf_member(ObjectType objtype, List *object, bool missing_ok)
#define CastRelationId
Definition: pg_cast.h:31
Oid get_conversion_oid(List *name, bool missing_ok)
Definition: namespace.c:3547
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 ConstraintRelationId
Definition: pg_constraint.h:29
#define elog
Definition: elog.h:219
#define LargeObjectRelationId
Oid get_collation_oid(List *name, bool missing_ok)
Definition: namespace.c:3493
Definition: pg_list.h:45
#define ConversionRelationId
Definition: pg_conversion.h:38
#define TSTemplateRelationId
Oid LookupTypeNameOid(ParseState *pstate, const TypeName *typeName, bool missing_ok)
Definition: parse_type.c:215
static ObjectAddress get_object_address_attrdef ( ObjectType  objtype,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
static

Definition at line 1411 of file objectaddress.c.

References AccessShareLock, Anum_pg_attrdef_adnum, Anum_pg_attrdef_adrelid, AttrDefaultIndexId, AttrDefaultRelationId, 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(), NULL, 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().

1414 {
1415  ObjectAddress address;
1416  List *relname;
1417  Oid reloid;
1418  Relation relation;
1419  const char *attname;
1420  AttrNumber attnum;
1421  TupleDesc tupdesc;
1422  Oid defoid;
1423 
1424  /* Extract relation name and open relation. */
1425  if (list_length(object) < 2)
1426  ereport(ERROR,
1427  (errcode(ERRCODE_SYNTAX_ERROR),
1428  errmsg("column name must be qualified")));
1429  attname = strVal(llast(object));
1430  relname = list_truncate(list_copy(object), list_length(object) - 1);
1431  /* XXX no missing_ok support here */
1432  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1433  reloid = RelationGetRelid(relation);
1434 
1435  tupdesc = RelationGetDescr(relation);
1436 
1437  /* Look up attribute number and scan pg_attrdef to find its tuple */
1438  attnum = get_attnum(reloid, attname);
1439  defoid = InvalidOid;
1440  if (attnum != InvalidAttrNumber && tupdesc->constr != NULL)
1441  {
1442  Relation attrdef;
1443  ScanKeyData keys[2];
1444  SysScanDesc scan;
1445  HeapTuple tup;
1446 
1448  ScanKeyInit(&keys[0],
1451  F_OIDEQ,
1452  ObjectIdGetDatum(reloid));
1453  ScanKeyInit(&keys[1],
1456  F_INT2EQ,
1457  Int16GetDatum(attnum));
1458  scan = systable_beginscan(attrdef, AttrDefaultIndexId, true,
1459  NULL, 2, keys);
1460  if (HeapTupleIsValid(tup = systable_getnext(scan)))
1461  defoid = HeapTupleGetOid(tup);
1462 
1463  systable_endscan(scan);
1464  relation_close(attrdef, AccessShareLock);
1465  }
1466  if (!OidIsValid(defoid))
1467  {
1468  if (!missing_ok)
1469  ereport(ERROR,
1470  (errcode(ERRCODE_UNDEFINED_COLUMN),
1471  errmsg("default value for column \"%s\" of relation \"%s\" does not exist",
1472  attname, NameListToString(relname))));
1473 
1474  address.classId = AttrDefaultRelationId;
1475  address.objectId = InvalidOid;
1476  address.objectSubId = InvalidAttrNumber;
1477  relation_close(relation, lockmode);
1478  return address;
1479  }
1480 
1481  address.classId = AttrDefaultRelationId;
1482  address.objectId = defoid;
1483  address.objectSubId = 0;
1484 
1485  *relp = relation;
1486  return address;
1487 }
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: heapam.c:1192
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:499
#define RelationGetDescr(relation)
Definition: rel.h:428
#define llast(l)
Definition: pg_list.h:131
#define Int16GetDatum(X)
Definition: postgres.h:457
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:1260
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3023
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:328
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:416
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define AttrDefaultIndexId
Definition: indexing.h:87
AttrNumber get_attnum(Oid relid, const char *attname)
Definition: lsyscache.c:821
#define ereport(elevel, rest)
Definition: elog.h:122
char * NameListToString(List *names)
Definition: namespace.c:3063
#define InvalidOid
Definition: postgres_ext.h:36
#define Anum_pg_attrdef_adrelid
Definition: pg_attrdef.h:54
#define Anum_pg_attrdef_adnum
Definition: pg_attrdef.h:55
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:229
TupleConstr * constr
Definition: tupdesc.h:76
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:1114
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
#define AttrDefaultRelationId
Definition: pg_attrdef.h:29
Definition: pg_list.h:45
int16 AttrNumber
Definition: attnum.h:21
#define RelationGetRelid(relation)
Definition: rel.h:416
#define BTEqualStrategyNumber
Definition: stratnum.h:31
static ObjectAddress get_object_address_attribute ( ObjectType  objtype,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
static

Definition at line 1360 of file objectaddress.c.

References 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, RelationRelationId, and strVal.

Referenced by get_object_address().

1363 {
1364  ObjectAddress address;
1365  List *relname;
1366  Oid reloid;
1367  Relation relation;
1368  const char *attname;
1369  AttrNumber attnum;
1370 
1371  /* Extract relation name and open relation. */
1372  if (list_length(object) < 2)
1373  ereport(ERROR,
1374  (errcode(ERRCODE_SYNTAX_ERROR),
1375  errmsg("column name must be qualified")));
1376  attname = strVal(lfirst(list_tail(object)));
1377  relname = list_truncate(list_copy(object), list_length(object) - 1);
1378  /* XXX no missing_ok support here */
1379  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1380  reloid = RelationGetRelid(relation);
1381 
1382  /* Look up attribute and construct return value. */
1383  attnum = get_attnum(reloid, attname);
1384  if (attnum == InvalidAttrNumber)
1385  {
1386  if (!missing_ok)
1387  ereport(ERROR,
1388  (errcode(ERRCODE_UNDEFINED_COLUMN),
1389  errmsg("column \"%s\" of relation \"%s\" does not exist",
1390  attname, NameListToString(relname))));
1391 
1392  address.classId = RelationRelationId;
1393  address.objectId = InvalidOid;
1394  address.objectSubId = InvalidAttrNumber;
1395  relation_close(relation, lockmode);
1396  return address;
1397  }
1398 
1399  address.classId = RelationRelationId;
1400  address.objectId = reloid;
1401  address.objectSubId = attnum;
1402 
1403  *relp = relation;
1404  return address;
1405 }
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: heapam.c:1192
#define RelationRelationId
Definition: pg_class.h:29
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:1260
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3023
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
AttrNumber get_attnum(Oid relid, const char *attname)
Definition: lsyscache.c:821
#define ereport(elevel, rest)
Definition: elog.h:122
char * NameListToString(List *names)
Definition: namespace.c:3063
#define InvalidOid
Definition: postgres_ext.h:36
#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:416
static ObjectAddress get_object_address_defacl ( List object,
bool  missing_ok 
)
static

Definition at line 1803 of file objectaddress.c.

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

Referenced by get_object_address().

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

Definition at line 1532 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, OperatorClassRelationId, OperatorFamilyRelationId, and strVal.

Referenced by get_object_address(), and get_object_address_opf_member().

1533 {
1534  Oid amoid;
1535  ObjectAddress address;
1536 
1537  /* XXX no missing_ok support here */
1538  amoid = get_index_am_oid(strVal(linitial(object)), false);
1539  object = list_copy_tail(object, 1);
1540 
1541  switch (objtype)
1542  {
1543  case OBJECT_OPCLASS:
1544  address.classId = OperatorClassRelationId;
1545  address.objectId = get_opclass_oid(amoid, object, missing_ok);
1546  address.objectSubId = 0;
1547  break;
1548  case OBJECT_OPFAMILY:
1550  address.objectId = get_opfamily_oid(amoid, object, missing_ok);
1551  address.objectSubId = 0;
1552  break;
1553  default:
1554  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1555  /* placate compiler, which doesn't know elog won't return */
1556  address.classId = InvalidOid;
1557  address.objectId = InvalidOid;
1558  address.objectSubId = 0;
1559  }
1560 
1561  return address;
1562 }
#define OperatorClassRelationId
Definition: pg_opclass.h:49
#define OperatorFamilyRelationId
Definition: pg_opfamily.h:29
#define strVal(v)
Definition: value.h:54
Oid get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
Definition: opclasscmds.c:220
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:141
#define elog
Definition: elog.h:219
static ObjectAddress get_object_address_opf_member ( ObjectType  objtype,
List object,
bool  missing_ok 
)
static

Definition at line 1570 of file objectaddress.c.

References AccessMethodOperatorRelationId, AccessMethodProcedureRelationId, 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().

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

Definition at line 1751 of file objectaddress.c.

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

Referenced by get_object_address().

1753 {
1754  ObjectAddress address;
1755  Relation relation;
1756  List *relname;
1757  char *pubname;
1758  Publication *pub;
1759 
1761 
1762  relname = linitial(object);
1764  AccessShareLock, missing_ok);
1765  if (!relation)
1766  return address;
1767 
1768  /* fetch publication name from input list */
1769  pubname = strVal(lsecond(object));
1770 
1771  /* Now look up the pg_publication tuple */
1772  pub = GetPublicationByName(pubname, missing_ok);
1773  if (!pub)
1774  {
1775  relation_close(relation, AccessShareLock);
1776  return address;
1777  }
1778 
1779  /* Find the publication relation mapping in syscache. */
1780  address.objectId =
1783  ObjectIdGetDatum(pub->oid));
1784  if (!OidIsValid(address.objectId))
1785  {
1786  if (!missing_ok)
1787  ereport(ERROR,
1788  (errcode(ERRCODE_UNDEFINED_OBJECT),
1789  errmsg("publication relation \"%s\" in publication \"%s\" does not exist",
1790  RelationGetRelationName(relation), pubname)));
1791  relation_close(relation, AccessShareLock);
1792  return address;
1793  }
1794 
1795  *relp = relation;
1796  return address;
1797 }
#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:1260
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3023
#define OidIsValid(objectId)
Definition: c.h:538
Publication * GetPublicationByName(const char *pubname, bool missing_ok)
#define lsecond(l)
Definition: pg_list.h:116
#define GetSysCacheOid2(cacheId, key1, key2)
Definition: syscache.h:185
#define PublicationRelRelationId
#define linitial(l)
Definition: pg_list.h:111
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:436
#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:416
Relation relation_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: heapam.c:1227
static ObjectAddress get_object_address_relobject ( ObjectType  objtype,
List object,
Relation relp,
bool  missing_ok 
)
static

Definition at line 1281 of file objectaddress.c.

References AccessShareLock, ObjectAddress::classId, ConstraintRelationId, 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(), NULL, OBJECT_POLICY, OBJECT_RULE, OBJECT_TABCONSTRAINT, OBJECT_TRIGGER, ObjectAddress::objectId, ObjectAddress::objectSubId, OidIsValid, PolicyRelationId, RelationGetRelid, RewriteRelationId, strVal, and TriggerRelationId.

Referenced by get_object_address().

1283 {
1284  ObjectAddress address;
1285  Relation relation = NULL;
1286  int nnames;
1287  const char *depname;
1288  List *relname;
1289  Oid reloid;
1290 
1291  /* Extract name of dependent object. */
1292  depname = strVal(llast(object));
1293 
1294  /* Separate relation name from dependent object name. */
1295  nnames = list_length(object);
1296  if (nnames < 2)
1297  ereport(ERROR,
1298  (errcode(ERRCODE_SYNTAX_ERROR),
1299  errmsg("must specify relation and object name")));
1300 
1301  /* Extract relation name and open relation. */
1302  relname = list_truncate(list_copy(object), nnames - 1);
1303  relation = heap_openrv_extended(makeRangeVarFromNameList(relname),
1305  missing_ok);
1306 
1307  reloid = relation ? RelationGetRelid(relation) : InvalidOid;
1308 
1309  switch (objtype)
1310  {
1311  case OBJECT_RULE:
1312  address.classId = RewriteRelationId;
1313  address.objectId = relation ?
1314  get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
1315  address.objectSubId = 0;
1316  break;
1317  case OBJECT_TRIGGER:
1318  address.classId = TriggerRelationId;
1319  address.objectId = relation ?
1320  get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
1321  address.objectSubId = 0;
1322  break;
1323  case OBJECT_TABCONSTRAINT:
1324  address.classId = ConstraintRelationId;
1325  address.objectId = relation ?
1326  get_relation_constraint_oid(reloid, depname, missing_ok) :
1327  InvalidOid;
1328  address.objectSubId = 0;
1329  break;
1330  case OBJECT_POLICY:
1331  address.classId = PolicyRelationId;
1332  address.objectId = relation ?
1333  get_relation_policy_oid(reloid, depname, missing_ok) :
1334  InvalidOid;
1335  address.objectSubId = 0;
1336  break;
1337  default:
1338  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1339  }
1340 
1341  /* Avoid relcache leak when object not found. */
1342  if (!OidIsValid(address.objectId))
1343  {
1344  if (relation != NULL)
1345  heap_close(relation, AccessShareLock);
1346 
1347  relation = NULL; /* department of accident prevention */
1348  return address;
1349  }
1350 
1351  /* Done. */
1352  *relp = relation;
1353  return address;
1354 }
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:3023
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
Relation heap_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: heapam.c:1341
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define InvalidOid
Definition: postgres_ext.h:36
#define PolicyRelationId
Definition: pg_policy.h:19
#define RewriteRelationId
Definition: pg_rewrite.h:32
#define NULL
Definition: c.h:229
Oid get_relation_policy_oid(Oid relid, const char *policy_name, bool missing_ok)
Definition: policy.c:1311
#define TriggerRelationId
Definition: pg_trigger.h:34
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:1294
Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok)
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define ConstraintRelationId
Definition: pg_constraint.h:29
#define elog
Definition: elog.h:219
Definition: pg_list.h:45
#define RelationGetRelid(relation)
Definition: rel.h:416
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:509
char * schemaname
Definition: primnodes.h:67
char * relname
Definition: primnodes.h:68
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:66
static ObjectAddress get_object_address_type ( ObjectType  objtype,
TypeName typename,
bool  missing_ok 
)
static

Definition at line 1493 of file objectaddress.c.

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

Referenced by get_object_address(), and get_object_address_opf_member().

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

Definition at line 1114 of file objectaddress.c.

References AccessMethodRelationId, AuthIdRelationId, ObjectAddress::classId, DatabaseRelationId, elog, ERROR, EventTriggerRelationId, ExtensionRelationId, ForeignDataWrapperRelationId, ForeignServerRelationId, 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, LanguageRelationId, name, NamespaceRelationId, 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, PublicationRelationId, strVal, SubscriptionRelationId, and TableSpaceRelationId.

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:
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:1380
#define NamespaceRelationId
Definition: pg_namespace.h:34
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3005
Oid get_am_oid(const char *amname, bool missing_ok)
Definition: amcmds.c:193
#define DatabaseRelationId
Definition: pg_database.h:29
Oid get_language_oid(const char *langname, bool missing_ok)
Definition: proclang.c:553
#define strVal(v)
Definition: value.h:54
#define PublicationRelationId
Oid get_event_trigger_oid(const char *trigname, bool missing_ok)
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5096
#define AuthIdRelationId
Definition: pg_authid.h:42
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition: foreign.c:659
#define ERROR
Definition: elog.h:43
#define SubscriptionRelationId
#define AccessMethodRelationId
Definition: pg_am.h:32
#define InvalidOid
Definition: postgres_ext.h:36
Oid get_database_oid(const char *dbname, bool missing_ok)
Definition: dbcommands.c:2009
#define ForeignServerRelationId
Oid get_subscription_oid(const char *subname, bool missing_ok)
#define EventTriggerRelationId
#define ForeignDataWrapperRelationId
const char * name
Definition: encode.c:521
#define TableSpaceRelationId
Definition: pg_tablespace.h:29
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 LanguageRelationId
Definition: pg_language.h:29
#define elog
Definition: elog.h:219
#define ExtensionRelationId
Definition: pg_extension.h:29
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition: foreign.c:680
static ObjectAddress get_object_address_usermapping ( List object,
bool  missing_ok 
)
static

Definition at line 1680 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, UserMappingRelationId, and username.

Referenced by get_object_address().

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

Definition at line 2528 of file objectaddress.c.

References ObjectPropertyType::attnum_acl, and get_object_property_data().

Referenced by AlterObjectOwner_internal().

2529 {
2530  const ObjectPropertyType *prop = get_object_property_data(class_id);
2531 
2532  return prop->attnum_acl;
2533 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_acl
AttrNumber get_object_attnum_name ( Oid  class_id)

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

2505 {
2506  const ObjectPropertyType *prop = get_object_property_data(class_id);
2507 
2508  return prop->attnum_name;
2509 }
AttrNumber attnum_name
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber get_object_attnum_namespace ( Oid  class_id)

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

2513 {
2514  const ObjectPropertyType *prop = get_object_property_data(class_id);
2515 
2516  return prop->attnum_namespace;
2517 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_namespace
AttrNumber get_object_attnum_owner ( Oid  class_id)

Definition at line 2520 of file objectaddress.c.

References ObjectPropertyType::attnum_owner, and get_object_property_data().

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

2521 {
2522  const ObjectPropertyType *prop = get_object_property_data(class_id);
2523 
2524  return prop->attnum_owner;
2525 }
AttrNumber attnum_owner
static const ObjectPropertyType * get_object_property_data(Oid class_id)
int get_object_catcache_name ( Oid  class_id)

Definition at line 2496 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

2497 {
2498  const ObjectPropertyType *prop = get_object_property_data(class_id);
2499 
2500  return prop->name_catcache_id;
2501 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
int get_object_catcache_oid ( Oid  class_id)

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

2489 {
2490  const ObjectPropertyType *prop = get_object_property_data(class_id);
2491 
2492  return prop->oid_catcache_id;
2493 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
bool get_object_namensp_unique ( Oid  class_id)

Definition at line 2544 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::is_nsp_name_unique.

Referenced by EventTriggerSQLDropAddObject(), and pg_identify_object().

2545 {
2546  const ObjectPropertyType *prop = get_object_property_data(class_id);
2547 
2548  return prop->is_nsp_name_unique;
2549 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
Oid get_object_namespace ( const ObjectAddress address)

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

2422 {
2423  int cache;
2424  HeapTuple tuple;
2425  bool isnull;
2426  Oid oid;
2427  const ObjectPropertyType *property;
2428 
2429  /* If not owned by a namespace, just return InvalidOid. */
2430  property = get_object_property_data(address->classId);
2431  if (property->attnum_namespace == InvalidAttrNumber)
2432  return InvalidOid;
2433 
2434  /* Currently, we can only handle object types with system caches. */
2435  cache = property->oid_catcache_id;
2436  Assert(cache != -1);
2437 
2438  /* Fetch tuple from syscache and extract namespace attribute. */
2439  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2440  if (!HeapTupleIsValid(tuple))
2441  elog(ERROR, "cache lookup failed for cache %d oid %u",
2442  cache, address->objectId);
2443  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2444  tuple,
2445  property->attnum_namespace,
2446  &isnull));
2447  Assert(!isnull);
2448  ReleaseSysCache(tuple);
2449 
2450  return oid;
2451 }
#define DatumGetObjectId(X)
Definition: postgres.h:506
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:156
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
static const ObjectPropertyType * get_object_property_data(Oid class_id)
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1117
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1279
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define Assert(condition)
Definition: c.h:675
AttrNumber attnum_namespace
#define InvalidAttrNumber
Definition: attnum.h:23
#define elog
Definition: elog.h:219
Oid get_object_oid_index ( Oid  class_id)

Definition at line 2480 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by get_catalog_object_by_oid().

2481 {
2482  const ObjectPropertyType *prop = get_object_property_data(class_id);
2483 
2484  return prop->oid_index_oid;
2485 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
static const ObjectPropertyType * get_object_property_data ( Oid  class_id)
static

Definition at line 2573 of file objectaddress.c.

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

Referenced by get_object_aclkind(), 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(), and get_object_oid_index().

2574 {
2575  static const ObjectPropertyType *prop_last = NULL;
2576  int index;
2577 
2578  /*
2579  * A shortcut to speed up multiple consecutive lookups of a particular
2580  * object class.
2581  */
2582  if (prop_last && prop_last->class_oid == class_id)
2583  return prop_last;
2584 
2585  for (index = 0; index < lengthof(ObjectProperty); index++)
2586  {
2587  if (ObjectProperty[index].class_oid == class_id)
2588  {
2589  prop_last = &ObjectProperty[index];
2590  return &ObjectProperty[index];
2591  }
2592  }
2593 
2594  ereport(ERROR,
2595  (errmsg_internal("unrecognized class ID: %u", class_id)));
2596 
2597  return NULL; /* keep MSC compiler happy */
2598 }
#define lengthof(array)
Definition: c.h:562
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
#define NULL
Definition: c.h:229
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, RelationGetRelid, RelationRelationId, RELKIND_FOREIGN_TABLE, RELKIND_INDEX, RELKIND_MATVIEW, RELKIND_PARTITIONED_TABLE, RELKIND_RELATION, RELKIND_SEQUENCE, and RELKIND_VIEW.

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  ereport(ERROR,
1221  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1222  errmsg("\"%s\" is not an index",
1223  RelationGetRelationName(relation))));
1224  break;
1225  case OBJECT_SEQUENCE:
1226  if (relation->rd_rel->relkind != RELKIND_SEQUENCE)
1227  ereport(ERROR,
1228  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1229  errmsg("\"%s\" is not a sequence",
1230  RelationGetRelationName(relation))));
1231  break;
1232  case OBJECT_TABLE:
1233  if (relation->rd_rel->relkind != RELKIND_RELATION &&
1234  relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1235  ereport(ERROR,
1236  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1237  errmsg("\"%s\" is not a table",
1238  RelationGetRelationName(relation))));
1239  break;
1240  case OBJECT_VIEW:
1241  if (relation->rd_rel->relkind != RELKIND_VIEW)
1242  ereport(ERROR,
1243  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1244  errmsg("\"%s\" is not a view",
1245  RelationGetRelationName(relation))));
1246  break;
1247  case OBJECT_MATVIEW:
1248  if (relation->rd_rel->relkind != RELKIND_MATVIEW)
1249  ereport(ERROR,
1250  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1251  errmsg("\"%s\" is not a materialized view",
1252  RelationGetRelationName(relation))));
1253  break;
1254  case OBJECT_FOREIGN_TABLE:
1255  if (relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE)
1256  ereport(ERROR,
1257  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1258  errmsg("\"%s\" is not a foreign table",
1259  RelationGetRelationName(relation))));
1260  break;
1261  default:
1262  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1263  break;
1264  }
1265 
1266  /* Done. */
1267  address.objectId = RelationGetRelid(relation);
1268  *relp = relation;
1269 
1270  return address;
1271 }
#define RelationRelationId
Definition: pg_class.h:29
#define RELKIND_MATVIEW
Definition: pg_class.h:165
int errcode(int sqlerrcode)
Definition: elog.c:575
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3023
Form_pg_class rd_rel
Definition: rel.h:114
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:436
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:167
#define ereport(elevel, rest)
Definition: elog.h:122
#define RELKIND_PARTITIONED_TABLE
Definition: pg_class.h:168
#define InvalidOid
Definition: postgres_ext.h:36
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define RELKIND_VIEW
Definition: pg_class.h:164
#define RELKIND_INDEX
Definition: pg_class.h:161
#define elog
Definition: elog.h:219
#define RELKIND_RELATION
Definition: pg_class.h:160
#define RELKIND_SEQUENCE
Definition: pg_class.h:162
#define RelationGetRelid(relation)
Definition: rel.h:416
Relation relation_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: heapam.c:1227
static void getConstraintTypeDescription ( StringInfo  buffer,
Oid  constroid 
)
static

Definition at line 3989 of file objectaddress.c.

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

Referenced by getObjectTypeDescription().

3990 {
3991  Relation constrRel;
3992  HeapTuple constrTup;
3993  Form_pg_constraint constrForm;
3994 
3996  constrTup = get_catalog_object_by_oid(constrRel, constroid);
3997  if (!HeapTupleIsValid(constrTup))
3998  elog(ERROR, "cache lookup failed for constraint %u", constroid);
3999 
4000  constrForm = (Form_pg_constraint) GETSTRUCT(constrTup);
4001 
4002  if (OidIsValid(constrForm->conrelid))
4003  appendStringInfoString(buffer, "table constraint");
4004  else if (OidIsValid(constrForm->contypid))
4005  appendStringInfoString(buffer, "domain constraint");
4006  else
4007  elog(ERROR, "invalid constraint %u", HeapTupleGetOid(constrTup));
4008 
4009  heap_close(constrRel, AccessShareLock);
4010 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:656
#define AccessShareLock
Definition: lockdefs.h:36
#define heap_close(r, l)
Definition: heapam.h:97
#define OidIsValid(objectId)
Definition: c.h:538
#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:1284
FormData_pg_constraint * Form_pg_constraint
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
HeapTuple get_catalog_object_by_oid(Relation catalog, Oid objectId)
#define ConstraintRelationId
Definition: pg_constraint.h:29
#define elog
Definition: elog.h:219
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
char* getObjectDescription ( const ObjectAddress object)

Definition at line 2655 of file objectaddress.c.

References _, AccessMethodOperatorOidIndexId, AccessMethodOperatorRelationId, AccessMethodProcedureOidIndexId, AccessMethodProcedureRelationId, AccessShareLock, AMOID, appendStringInfo(), AttrDefaultOidIndexId, AttrDefaultRelationId, BTEqualStrategyNumber, buffer, CastOidIndexId, CastRelationId, CLAOID, ObjectAddress::classId, COLLOID, CONSTROID, CONVOID, StringInfoData::data, DEFACLOBJ_FUNCTION, DEFACLOBJ_NAMESPACE, DEFACLOBJ_RELATION, DEFACLOBJ_SEQUENCE, DEFACLOBJ_TYPE, DefaultAclOidIndexId, DefaultAclRelationId, elog, ERROR, EVENTTRIGGEROID, ForeignDataWrapper::fdwname, format_operator(), format_procedure(), format_type_be(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name(), get_publication_name(), get_rel_name(), get_relid_attribute_name(), get_subscription_name(), get_tablespace_name(), GetForeignDataWrapper(), GetForeignServer(), getObjectClass(), getObjectDescription(), getOpFamilyDescription(), getRelationDescription(), GETSTRUCT, GetUserNameFromId(), heap_close, heap_open(), HeapTupleIsValid, initStringInfo(), NameStr, NULL, 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, PolicyRelationId, PUBLICATIONREL, quote_qualified_identifier(), RelationRelationId, ReleaseSysCache(), RewriteOidIndexId, RewriteRelationId, ScanKeyInit(), SearchSysCache1, ForeignServer::servername, STATEXTOID, systable_beginscan(), systable_endscan(), systable_getnext(), TRFOID, TriggerOidIndexId, TriggerRelationId, 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().

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

Definition at line 3435 of file objectaddress.c.

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

3436 {
3437  ObjectAddress address;
3438 
3439  address.classId = classid;
3440  address.objectId = objid;
3441  address.objectSubId = 0;
3442 
3443  return getObjectDescription(&address);
3444 }
char * getObjectDescription(const ObjectAddress *object)
char* getObjectIdentityParts ( const ObjectAddress object,
List **  objname,
List **  objargs 
)

Definition at line 4056 of file objectaddress.c.

References _, AccessMethodOperatorOidIndexId, AccessMethodOperatorRelationId, AccessMethodProcedureOidIndexId, AccessMethodProcedureRelationId, AccessShareLock, AMOID, appendStringInfo(), appendStringInfoString(), Assert, AttrDefaultOidIndexId, AttrDefaultRelationId, BTEqualStrategyNumber, buffer, CastRelationId, CLAOID, ObjectAddress::classId, COLLOID, CONSTROID, CONVOID, StringInfoData::data, DEFACLOBJ_FUNCTION, DEFACLOBJ_NAMESPACE, DEFACLOBJ_RELATION, DEFACLOBJ_SEQUENCE, DEFACLOBJ_TYPE, DefaultAclOidIndexId, DefaultAclRelationId, 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_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_relid_attribute_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, NULL, 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, PolicyRelationId, psprintf(), pstrdup(), PUBLICATIONREL, quote_identifier(), quote_qualified_identifier(), RelationRelationId, ReleaseSysCache(), RewriteRelationId, ScanKeyInit(), SearchSysCache1, ForeignServer::servername, STATEXTOID, systable_beginscan(), systable_endscan(), systable_getnext(), TransformRelationId, TriggerRelationId, TSCONFIGOID, TSDICTOID, TSPARSEROID, TSTEMPLATEOID, TypeRelationId, USERMAPPINGOID, and username.

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

4058 {
4060 
4061  initStringInfo(&buffer);
4062 
4063  /*
4064  * Make sure that both objname and objargs were passed, or none was; and
4065  * initialize them to empty lists. For objname this is useless because it
4066  * will be initialized in all cases inside the switch; but we do it anyway
4067  * so that we can test below that no branch leaves it unset.
4068  */
4069  Assert(PointerIsValid(objname) == PointerIsValid(objargs));
4070  if (objname)
4071  {
4072  *objname = NIL;
4073  *objargs = NIL;
4074  }
4075 
4076  switch (getObjectClass(object))
4077  {
4078  case OCLASS_CLASS:
4079  getRelationIdentity(&buffer, object->objectId, objname);
4080  if (object->objectSubId != 0)
4081  {
4082  char *attr;
4083 
4084  attr = get_relid_attribute_name(object->objectId,
4085  object->objectSubId);
4086  appendStringInfo(&buffer, ".%s", quote_identifier(attr));
4087  if (objname)
4088  *objname = lappend(*objname, attr);
4089  }
4090  break;
4091 
4092  case OCLASS_PROC:
4093  appendStringInfoString(&buffer,
4095  if (objname)
4096  format_procedure_parts(object->objectId, objname, objargs);
4097  break;
4098 
4099  case OCLASS_TYPE:
4100  {
4101  char *typeout;
4102 
4103  typeout = format_type_be_qualified(object->objectId);
4104  appendStringInfoString(&buffer, typeout);
4105  if (objname)
4106  *objname = list_make1(typeout);
4107  }
4108  break;
4109 
4110  case OCLASS_CAST:
4111  {
4112  Relation castRel;
4113  HeapTuple tup;
4114  Form_pg_cast castForm;
4115 
4117 
4118  tup = get_catalog_object_by_oid(castRel, object->objectId);
4119 
4120  if (!HeapTupleIsValid(tup))
4121  elog(ERROR, "could not find tuple for cast %u",
4122  object->objectId);
4123 
4124  castForm = (Form_pg_cast) GETSTRUCT(tup);
4125 
4126  appendStringInfo(&buffer, "(%s AS %s)",
4127  format_type_be_qualified(castForm->castsource),
4128  format_type_be_qualified(castForm->casttarget));
4129 
4130  if (objname)
4131  {
4132  *objname = list_make1(format_type_be_qualified(castForm->castsource));
4133  *objargs = list_make1(format_type_be_qualified(castForm->casttarget));
4134  }
4135 
4136  heap_close(castRel, AccessShareLock);
4137  break;
4138  }
4139 
4140  case OCLASS_COLLATION:
4141  {
4142  HeapTuple collTup;
4143  Form_pg_collation coll;
4144  char *schema;
4145 
4146  collTup = SearchSysCache1(COLLOID,
4147  ObjectIdGetDatum(object->objectId));
4148  if (!HeapTupleIsValid(collTup))
4149  elog(ERROR, "cache lookup failed for collation %u",
4150  object->objectId);
4151  coll = (Form_pg_collation) GETSTRUCT(collTup);
4152  schema = get_namespace_name_or_temp(coll->collnamespace);
4153  appendStringInfoString(&buffer,
4155  NameStr(coll->collname)));
4156  if (objname)
4157  *objname = list_make2(schema,
4158  pstrdup(NameStr(coll->collname)));
4159  ReleaseSysCache(collTup);
4160  break;
4161  }
4162 
4163  case OCLASS_CONSTRAINT:
4164  {
4165  HeapTuple conTup;
4166  Form_pg_constraint con;
4167 
4168  conTup = SearchSysCache1(CONSTROID,
4169  ObjectIdGetDatum(object->objectId));
4170  if (!HeapTupleIsValid(conTup))
4171  elog(ERROR, "cache lookup failed for constraint %u",
4172  object->objectId);
4173  con = (Form_pg_constraint) GETSTRUCT(conTup);
4174 
4175  if (OidIsValid(con->conrelid))
4176  {
4177  appendStringInfo(&buffer, "%s on ",
4178  quote_identifier(NameStr(con->conname)));
4179  getRelationIdentity(&buffer, con->conrelid, objname);
4180  if (objname)
4181  *objname = lappend(*objname, pstrdup(NameStr(con->conname)));
4182  }
4183  else
4184  {
4185  ObjectAddress domain;
4186 
4187  Assert(OidIsValid(con->contypid));
4188  domain.classId = TypeRelationId;
4189  domain.objectId = con->contypid;
4190  domain.objectSubId = 0;
4191 
4192  appendStringInfo(&buffer, "%s on %s",
4193  quote_identifier(NameStr(con->conname)),
4194  getObjectIdentityParts(&domain, objname, objargs));
4195 
4196  if (objname)
4197  *objargs = lappend(*objargs, pstrdup(NameStr(con->conname)));
4198  }
4199 
4200  ReleaseSysCache(conTup);
4201  break;
4202  }
4203 
4204  case OCLASS_CONVERSION:
4205  {
4206  HeapTuple conTup;
4207  Form_pg_conversion conForm;
4208  char *schema;
4209 
4210  conTup = SearchSysCache1(CONVOID,
4211  ObjectIdGetDatum(object->objectId));
4212  if (!HeapTupleIsValid(conTup))
4213  elog(ERROR, "cache lookup failed for conversion %u",
4214  object->objectId);
4215  conForm = (Form_pg_conversion) GETSTRUCT(conTup);
4216  schema = get_namespace_name_or_temp(conForm->connamespace);
4217  appendStringInfoString(&buffer,
4219  NameStr(conForm->conname)));
4220  if (objname)
4221  *objname = list_make2(schema,
4222  pstrdup(NameStr(conForm->conname)));
4223  ReleaseSysCache(conTup);
4224  break;
4225  }
4226 
4227  case OCLASS_DEFAULT:
4228  {
4229  Relation attrdefDesc;
4230  ScanKeyData skey[1];
4231  SysScanDesc adscan;
4232 
4233  HeapTuple tup;
4234  Form_pg_attrdef attrdef;
4235  ObjectAddress colobject;
4236 
4238 
4239  ScanKeyInit(&skey[0],
4241  BTEqualStrategyNumber, F_OIDEQ,
4242  ObjectIdGetDatum(object->objectId));
4243 
4244  adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndexId,
4245  true, NULL, 1, skey);
4246 
4247  tup = systable_getnext(adscan);
4248 
4249  if (!HeapTupleIsValid(tup))
4250  elog(ERROR, "could not find tuple for attrdef %u",
4251  object->objectId);
4252 
4253  attrdef = (Form_pg_attrdef) GETSTRUCT(tup);
4254 
4255  colobject.classId = RelationRelationId;
4256  colobject.objectId = attrdef->adrelid;
4257  colobject.objectSubId = attrdef->adnum;
4258 
4259  appendStringInfo(&buffer, "for %s",
4260  getObjectIdentityParts(&colobject,
4261  objname, objargs));
4262 
4263  systable_endscan(adscan);
4264  heap_close(attrdefDesc, AccessShareLock);
4265  break;
4266  }
4267 
4268  case OCLASS_LANGUAGE:
4269  {
4270  HeapTuple langTup;
4271  Form_pg_language langForm;
4272 
4273  langTup = SearchSysCache1(LANGOID,
4274  ObjectIdGetDatum(object->objectId));
4275  if (!HeapTupleIsValid(langTup))
4276  elog(ERROR, "cache lookup failed for language %u",
4277  object->objectId);
4278  langForm = (Form_pg_language) GETSTRUCT(langTup);
4279  appendStringInfoString(&buffer,
4280  quote_identifier(NameStr(langForm->lanname)));
4281  if (objname)
4282  *objname = list_make1(pstrdup(NameStr(langForm->lanname)));
4283  ReleaseSysCache(langTup);
4284  break;
4285  }
4286  case OCLASS_LARGEOBJECT:
4287  appendStringInfo(&buffer, "%u",
4288  object->objectId);
4289  if (objname)
4290  *objname = list_make1(psprintf("%u", object->objectId));
4291  break;
4292 
4293  case OCLASS_OPERATOR:
4294  appendStringInfoString(&buffer,
4296  if (objname)
4297  format_operator_parts(object->objectId, objname, objargs);
4298  break;
4299 
4300  case OCLASS_OPCLASS:
4301  {
4302  HeapTuple opcTup;
4303  Form_pg_opclass opcForm;
4304  HeapTuple amTup;
4305  Form_pg_am amForm;
4306  char *schema;
4307 
4308  opcTup = SearchSysCache1(CLAOID,
4309  ObjectIdGetDatum(object->objectId));
4310  if (!HeapTupleIsValid(opcTup))
4311  elog(ERROR, "cache lookup failed for opclass %u",
4312  object->objectId);
4313  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
4314  schema = get_namespace_name_or_temp(opcForm->opcnamespace);
4315 
4316  amTup = SearchSysCache1(AMOID,
4317  ObjectIdGetDatum(opcForm->opcmethod));
4318  if (!HeapTupleIsValid(amTup))
4319  elog(ERROR, "cache lookup failed for access method %u",
4320  opcForm->opcmethod);
4321  amForm = (Form_pg_am) GETSTRUCT(amTup);
4322 
4323  appendStringInfo(&buffer, "%s USING %s",
4325  NameStr(opcForm->opcname)),
4326  quote_identifier(NameStr(amForm->amname)));
4327  if (objname)
4328  *objname = list_make3(pstrdup(NameStr(amForm->amname)),
4329  schema,
4330  pstrdup(NameStr(opcForm->opcname)));
4331 
4332  ReleaseSysCache(amTup);
4333  ReleaseSysCache(opcTup);
4334  break;
4335  }
4336 
4337  case OCLASS_OPFAMILY:
4338  getOpFamilyIdentity(&buffer, object->objectId, objname);
4339  break;
4340 
4341  case OCLASS_AM:
4342  {
4343  char *amname;
4344 
4345  amname = get_am_name(object->objectId);
4346  if (!amname)
4347  elog(ERROR, "cache lookup failed for access method %u",
4348  object->objectId);
4349  appendStringInfoString(&buffer, quote_identifier(amname));
4350  if (objname)
4351  *objname = list_make1(amname);
4352  }
4353  break;
4354 
4355  case OCLASS_AMOP:
4356  {
4357  Relation amopDesc;
4358  HeapTuple tup;
4359  ScanKeyData skey[1];
4360  SysScanDesc amscan;
4361  Form_pg_amop amopForm;
4362  StringInfoData opfam;
4363  char *ltype;
4364  char *rtype;
4365 
4367  AccessShareLock);
4368 
4369  ScanKeyInit(&skey[0],
4371  BTEqualStrategyNumber, F_OIDEQ,
4372  ObjectIdGetDatum(object->objectId));
4373 
4374  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
4375  NULL, 1, skey);
4376 
4377  tup = systable_getnext(amscan);
4378 
4379  if (!HeapTupleIsValid(tup))
4380  elog(ERROR, "could not find tuple for amop entry %u",
4381  object->objectId);
4382 
4383  amopForm = (Form_pg_amop) GETSTRUCT(tup);
4384 
4385  initStringInfo(&opfam);
4386  getOpFamilyIdentity(&opfam, amopForm->amopfamily, objname);
4387 
4388  ltype = format_type_be_qualified(amopForm->amoplefttype);
4389  rtype = format_type_be_qualified(amopForm->amoprighttype);
4390 
4391  if (objname)
4392  {
4393  *objname = lappend(*objname,
4394  psprintf("%d", amopForm->amopstrategy));
4395  *objargs = list_make2(ltype, rtype);
4396  }
4397 
4398  appendStringInfo(&buffer, "operator %d (%s, %s) of %s",
4399  amopForm->amopstrategy,
4400  ltype, rtype, opfam.data);
4401 
4402  pfree(opfam.data);
4403 
4404  systable_endscan(amscan);
4405  heap_close(amopDesc, AccessShareLock);
4406  break;
4407  }
4408 
4409  case OCLASS_AMPROC:
4410  {
4411  Relation amprocDesc;
4412  ScanKeyData skey[1];
4413  SysScanDesc amscan;
4414  HeapTuple tup;
4415  Form_pg_amproc amprocForm;
4416  StringInfoData opfam;
4417  char *ltype;
4418  char *rtype;
4419 
4421  AccessShareLock);
4422 
4423  ScanKeyInit(&skey[0],
4425  BTEqualStrategyNumber, F_OIDEQ,
4426  ObjectIdGetDatum(object->objectId));
4427 
4428  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
4429  NULL, 1, skey);
4430 
4431  tup = systable_getnext(amscan);
4432 
4433  if (!HeapTupleIsValid(tup))
4434  elog(ERROR, "could not find tuple for amproc entry %u",
4435  object->objectId);
4436 
4437  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
4438 
4439  initStringInfo(&opfam);
4440  getOpFamilyIdentity(&opfam, amprocForm->amprocfamily, objname);
4441 
4442  ltype = format_type_be_qualified(amprocForm->amproclefttype);
4443  rtype = format_type_be_qualified(amprocForm->amprocrighttype);
4444 
4445  if (objname)
4446  {
4447  *objname = lappend(*objname,
4448  psprintf("%d", amprocForm->amprocnum));
4449  *objargs = list_make2(ltype, rtype);
4450  }
4451 
4452  appendStringInfo(&buffer, "function %d (%s, %s) of %s",
4453  amprocForm->amprocnum,
4454  ltype, rtype, opfam.data);
4455 
4456  pfree(opfam.data);
4457 
4458  systable_endscan(amscan);
4459  heap_close(amprocDesc, AccessShareLock);
4460  break;
4461  }
4462 
4463  case OCLASS_REWRITE:
4464  {
4465  Relation ruleDesc;
4466  HeapTuple tup;
4468 
4470 
4471  tup = get_catalog_object_by_oid(ruleDesc, object->objectId);
4472 
4473  if (!HeapTupleIsValid(tup))
4474  elog(ERROR, "could not find tuple for rule %u",
4475  object->objectId);
4476 
4477  rule = (Form_pg_rewrite) GETSTRUCT(tup);
4478 
4479  appendStringInfo(&buffer, "%s on ",
4480  quote_identifier(NameStr(rule->rulename)));
4481  getRelationIdentity(&buffer, rule->ev_class, objname);
4482  if (objname)
4483  *objname = lappend(*objname, pstrdup(NameStr(rule->rulename)));
4484 
4485  heap_close(ruleDesc, AccessShareLock);
4486  break;
4487  }
4488 
4489  case OCLASS_TRIGGER:
4490  {
4491  Relation trigDesc;
4492  HeapTuple tup;
4493  Form_pg_trigger trig;
4494 
4496 
4497  tup = get_catalog_object_by_oid(trigDesc, object->objectId);
4498 
4499  if (!HeapTupleIsValid(tup))
4500  elog(ERROR, "could not find tuple for trigger %u",
4501  object->objectId);
4502 
4503  trig = (Form_pg_trigger) GETSTRUCT(tup);
4504 
4505  appendStringInfo(&buffer, "%s on ",
4506  quote_identifier(NameStr(trig->tgname)));
4507  getRelationIdentity(&buffer, trig->tgrelid, objname);
4508  if (objname)
4509  *objname = lappend(*objname, pstrdup(NameStr(trig->tgname)));
4510 
4511  heap_close(trigDesc, AccessShareLock);
4512  break;
4513  }
4514 
4515  case OCLASS_SCHEMA:
4516  {
4517  char *nspname;
4518 
4519  nspname = get_namespace_name_or_temp(object->objectId);
4520  if (!nspname)
4521  elog(ERROR, "cache lookup failed for namespace %u",
4522  object->objectId);
4523  appendStringInfoString(&buffer,
4524  quote_identifier(nspname));
4525  if (objname)
4526  *objname = list_make1(nspname);
4527  break;
4528  }
4529 
4530  case OCLASS_STATISTIC_EXT:
4531  {
4532  HeapTuple tup;
4533  Form_pg_statistic_ext formStatistic;
4534  char *schema;
4535 
4537  ObjectIdGetDatum(object->objectId));
4538  if (!HeapTupleIsValid(tup))
4539  elog(ERROR, "cache lookup failed for statistics object %u",
4540  object->objectId);
4541  formStatistic = (Form_pg_statistic_ext) GETSTRUCT(tup);
4542  schema = get_namespace_name_or_temp(formStatistic->stxnamespace);
4543  appendStringInfoString(&buffer,
4545  NameStr(formStatistic->stxname)));
4546  if (objname)
4547  *objname = list_make2(schema,
4548  pstrdup(NameStr(formStatistic->stxname)));
4549  ReleaseSysCache(tup);
4550  }
4551  break;
4552 
4553  case OCLASS_TSPARSER:
4554  {
4555  HeapTuple tup;
4556  Form_pg_ts_parser formParser;
4557  char *schema;
4558 
4560  ObjectIdGetDatum(object->objectId));
4561  if (!HeapTupleIsValid(tup))
4562  elog(ERROR, "cache lookup failed for text search parser %u",
4563  object->objectId);
4564  formParser = (Form_pg_ts_parser) GETSTRUCT(tup);
4565  schema = get_namespace_name_or_temp(formParser->prsnamespace);
4566  appendStringInfoString(&buffer,
4568  NameStr(formParser->prsname)));
4569  if (objname)
4570  *objname = list_make2(schema,
4571  pstrdup(NameStr(formParser->prsname)));
4572  ReleaseSysCache(tup);
4573  break;
4574  }
4575 
4576  case OCLASS_TSDICT:
4577  {
4578  HeapTuple tup;
4579  Form_pg_ts_dict formDict;
4580  char *schema;
4581 
4582  tup = SearchSysCache1(TSDICTOID,
4583  ObjectIdGetDatum(object->objectId));
4584  if (!HeapTupleIsValid(tup))
4585  elog(ERROR, "cache lookup failed for text search dictionary %u",
4586  object->objectId);
4587  formDict = (Form_pg_ts_dict) GETSTRUCT(tup);
4588  schema = get_namespace_name_or_temp(formDict->dictnamespace);
4589  appendStringInfoString(&buffer,
4591  NameStr(formDict->dictname)));
4592  if (objname)
4593  *objname = list_make2(schema,
4594  pstrdup(NameStr(formDict->dictname)));
4595  ReleaseSysCache(tup);
4596  break;
4597  }
4598 
4599  case OCLASS_TSTEMPLATE:
4600  {
4601  HeapTuple tup;
4602  Form_pg_ts_template formTmpl;
4603  char *schema;
4604 
4606  ObjectIdGetDatum(object->objectId));
4607  if (!HeapTupleIsValid(tup))
4608  elog(ERROR, "cache lookup failed for text search template %u",
4609  object->objectId);
4610  formTmpl = (Form_pg_ts_template) GETSTRUCT(tup);
4611  schema = get_namespace_name_or_temp(formTmpl->tmplnamespace);
4612  appendStringInfoString(&buffer,
4614  NameStr(formTmpl->tmplname)));
4615  if (objname)
4616  *objname = list_make2(schema,
4617  pstrdup(NameStr(formTmpl->tmplname)));
4618  ReleaseSysCache(tup);
4619  break;
4620  }
4621 
4622  case OCLASS_TSCONFIG:
4623  {
4624  HeapTuple tup;
4625  Form_pg_ts_config formCfg;
4626  char *schema;
4627 
4629  ObjectIdGetDatum(object->objectId));
4630  if (!HeapTupleIsValid(tup))
4631  elog(ERROR, "cache lookup failed for text search configuration %u",
4632  object->objectId);
4633  formCfg = (Form_pg_ts_config) GETSTRUCT(tup);
4634  schema = get_namespace_name_or_temp(formCfg->cfgnamespace);
4635  appendStringInfoString(&buffer,
4637  NameStr(formCfg->cfgname)));
4638  if (objname)
4639  *objname = list_make2(schema,
4640  pstrdup(NameStr(formCfg->cfgname)));
4641  ReleaseSysCache(tup);
4642  break;
4643  }
4644 
4645  case OCLASS_ROLE:
4646  {
4647  char *username;
4648 
4649  username = GetUserNameFromId(object->objectId, false);
4650  if (objname)
4651  *objname = list_make1(username);
4652  appendStringInfoString(&buffer,
4653  quote_identifier(username));
4654  break;
4655  }
4656 
4657  case OCLASS_DATABASE:
4658  {
4659  char *datname;
4660 
4661  datname = get_database_name(object->objectId);
4662  if (!datname)
4663  elog(ERROR, "cache lookup failed for database %u",
4664  object->objectId);
4665  if (objname)
4666  *objname = list_make1(datname);
4667  appendStringInfoString(&buffer,
4668  quote_identifier(datname));
4669  break;
4670  }
4671 
4672  case OCLASS_TBLSPACE:
4673  {
4674  char *tblspace;
4675 
4676  tblspace = get_tablespace_name(object->objectId);
4677  if (!tblspace)
4678  elog(ERROR, "cache lookup failed for tablespace %u",
4679  object->objectId);
4680  if (objname)
4681  *objname = list_make1(tblspace);
4682  appendStringInfoString(&buffer,
4683  quote_identifier(tblspace));
4684  break;
4685  }
4686 
4687  case OCLASS_FDW:
4688  {
4689  ForeignDataWrapper *fdw;
4690 
4691  fdw = GetForeignDataWrapper(object->objectId);
4693  if (objname)
4694  *objname = list_make1(pstrdup(fdw->fdwname));
4695  break;
4696  }
4697 
4698  case OCLASS_FOREIGN_SERVER:
4699  {
4700  ForeignServer *srv;
4701 
4702  srv = GetForeignServer(object->objectId);
4703  appendStringInfoString(&buffer,
4705  if (objname)
4706  *objname = list_make1(pstrdup(srv->servername));
4707  break;
4708  }
4709 
4710  case OCLASS_USER_MAPPING:
4711  {
4712  HeapTuple tup;
4713  Oid useid;
4714  Form_pg_user_mapping umform;
4715  ForeignServer *srv;
4716  const char *usename;
4717 
4719  ObjectIdGetDatum(object->objectId));
4720  if (!HeapTupleIsValid(tup))
4721  elog(ERROR, "cache lookup failed for user mapping %u",
4722  object->objectId);
4723  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
4724  useid = umform->umuser;
4725  srv = GetForeignServer(umform->umserver);
4726 
4727  ReleaseSysCache(tup);
4728 
4729  if (OidIsValid(useid))
4730  usename = GetUserNameFromId(useid, false);
4731  else
4732  usename = "public";
4733 
4734  if (objname)
4735  {
4736  *