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 2215 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, lo_compat_privileges, lsecond, 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_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().

2217 {
2218  switch (objtype)
2219  {
2220  case OBJECT_INDEX:
2221  case OBJECT_SEQUENCE:
2222  case OBJECT_TABLE:
2223  case OBJECT_VIEW:
2224  case OBJECT_MATVIEW:
2225  case OBJECT_FOREIGN_TABLE:
2226  case OBJECT_COLUMN:
2227  case OBJECT_RULE:
2228  case OBJECT_TRIGGER:
2229  case OBJECT_POLICY:
2230  case OBJECT_TABCONSTRAINT:
2231  if (!pg_class_ownercheck(RelationGetRelid(relation), roleid))
2233  RelationGetRelationName(relation));
2234  break;
2235  case OBJECT_DATABASE:
2236  if (!pg_database_ownercheck(address.objectId, roleid))
2238  strVal((Value *) object));
2239  break;
2240  case OBJECT_TYPE:
2241  case OBJECT_DOMAIN:
2242  case OBJECT_ATTRIBUTE:
2243  case OBJECT_DOMCONSTRAINT:
2244  if (!pg_type_ownercheck(address.objectId, roleid))
2246  break;
2247  case OBJECT_AGGREGATE:
2248  case OBJECT_FUNCTION:
2249  if (!pg_proc_ownercheck(address.objectId, roleid))
2251  NameListToString((castNode(ObjectWithArgs, object))->objname));
2252  break;
2253  case OBJECT_OPERATOR:
2254  if (!pg_oper_ownercheck(address.objectId, roleid))
2256  NameListToString((castNode(ObjectWithArgs, object))->objname));
2257  break;
2258  case OBJECT_SCHEMA:
2259  if (!pg_namespace_ownercheck(address.objectId, roleid))
2261  strVal((Value *) object));
2262  break;
2263  case OBJECT_COLLATION:
2264  if (!pg_collation_ownercheck(address.objectId, roleid))
2266  NameListToString(castNode(List, object)));
2267  break;
2268  case OBJECT_CONVERSION:
2269  if (!pg_conversion_ownercheck(address.objectId, roleid))
2271  NameListToString(castNode(List, object)));
2272  break;
2273  case OBJECT_EXTENSION:
2274  if (!pg_extension_ownercheck(address.objectId, roleid))
2276  strVal((Value *) object));
2277  break;
2278  case OBJECT_FDW:
2279  if (!pg_foreign_data_wrapper_ownercheck(address.objectId, roleid))
2281  strVal((Value *) object));
2282  break;
2283  case OBJECT_FOREIGN_SERVER:
2284  if (!pg_foreign_server_ownercheck(address.objectId, roleid))
2286  strVal((Value *) object));
2287  break;
2288  case OBJECT_EVENT_TRIGGER:
2289  if (!pg_event_trigger_ownercheck(address.objectId, roleid))
2291  strVal((Value *) object));
2292  break;
2293  case OBJECT_LANGUAGE:
2294  if (!pg_language_ownercheck(address.objectId, roleid))
2296  strVal((Value *) object));
2297  break;
2298  case OBJECT_OPCLASS:
2299  if (!pg_opclass_ownercheck(address.objectId, roleid))
2301  NameListToString(castNode(List, object)));
2302  break;
2303  case OBJECT_OPFAMILY:
2304  if (!pg_opfamily_ownercheck(address.objectId, roleid))
2306  NameListToString(castNode(List, object)));
2307  break;
2308  case OBJECT_LARGEOBJECT:
2309  if (!lo_compat_privileges &&
2310  !pg_largeobject_ownercheck(address.objectId, roleid))
2311  ereport(ERROR,
2312  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2313  errmsg("must be owner of large object %u",
2314  address.objectId)));
2315  break;
2316  case OBJECT_CAST:
2317  {
2318  /* We can only check permissions on the source/target types */
2319  TypeName *sourcetype = castNode(TypeName, linitial(castNode(List, object)));
2320  TypeName *targettype = castNode(TypeName, lsecond(castNode(List, object)));
2321  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2322  Oid targettypeid = typenameTypeId(NULL, targettype);
2323 
2324  if (!pg_type_ownercheck(sourcetypeid, roleid)
2325  && !pg_type_ownercheck(targettypeid, roleid))
2326  ereport(ERROR,
2327  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2328  errmsg("must be owner of type %s or type %s",
2329  format_type_be(sourcetypeid),
2330  format_type_be(targettypeid))));
2331  }
2332  break;
2333  case OBJECT_PUBLICATION:
2334  if (!pg_publication_ownercheck(address.objectId, roleid))
2336  strVal((Value *) object));
2337  break;
2338  case OBJECT_SUBSCRIPTION:
2339  if (!pg_subscription_ownercheck(address.objectId, roleid))
2341  strVal((Value *) object));
2342  break;
2343  case OBJECT_TRANSFORM:
2344  {
2345  TypeName *typename = castNode(TypeName, linitial(castNode(List, object)));
2346  Oid typeid = typenameTypeId(NULL, typename);
2347 
2348  if (!pg_type_ownercheck(typeid, roleid))
2350  }
2351  break;
2352  case OBJECT_TABLESPACE:
2353  if (!pg_tablespace_ownercheck(address.objectId, roleid))
2355  strVal((Value *) object));
2356  break;
2357  case OBJECT_TSDICTIONARY:
2358  if (!pg_ts_dict_ownercheck(address.objectId, roleid))
2360  NameListToString(castNode(List, object)));
2361  break;
2363  if (!pg_ts_config_ownercheck(address.objectId, roleid))
2365  NameListToString(castNode(List, object)));
2366  break;
2367  case OBJECT_ROLE:
2368 
2369  /*
2370  * We treat roles as being "owned" by those with CREATEROLE priv,
2371  * except that superusers are only owned by superusers.
2372  */
2373  if (superuser_arg(address.objectId))
2374  {
2375  if (!superuser_arg(roleid))
2376  ereport(ERROR,
2377  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2378  errmsg("must be superuser")));
2379  }
2380  else
2381  {
2382  if (!has_createrole_privilege(roleid))
2383  ereport(ERROR,
2384  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2385  errmsg("must have CREATEROLE privilege")));
2386  }
2387  break;
2388  case OBJECT_TSPARSER:
2389  case OBJECT_TSTEMPLATE:
2390  case OBJECT_ACCESS_METHOD:
2391  /* We treat these object types as being owned by superusers */
2392  if (!superuser_arg(roleid))
2393  ereport(ERROR,
2394  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2395  errmsg("must be superuser")));
2396  break;
2397  case OBJECT_STATISTIC_EXT:
2398  if (!pg_statistics_ownercheck(address.objectId, roleid))
2400  break;
2401  default:
2402  elog(ERROR, "unrecognized object type: %d",
2403  (int) objtype);
2404  }
2405 }
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:5153
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:4973
bool pg_largeobject_ownercheck(Oid lobj_oid, Oid roleid)
Definition: aclchk.c:4662
bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid)
Definition: aclchk.c:4812
bool pg_language_ownercheck(Oid lan_oid, Oid roleid)
Definition: aclchk.c:4633
#define castNode(_type_, nodeptr)
Definition: nodes.h:575
bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid)
Definition: aclchk.c:4839
bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:4893
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5067
#define strVal(v)
Definition: value.h:54
bool pg_oper_ownercheck(Oid oper_oid, Oid roleid)
Definition: aclchk.c:4581
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:4705
unsigned int Oid
Definition: postgres_ext.h:31
bool pg_type_ownercheck(Oid type_oid, Oid roleid)
Definition: aclchk.c:4555
#define lsecond(l)
Definition: pg_list.h:114
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3440
bool lo_compat_privileges
Definition: be-fsstubs.c:57
#define linitial(l)
Definition: pg_list.h:110
#define ERROR
Definition: elog.h:43
bool pg_statistics_ownercheck(Oid stat_oid, Oid roleid)
Definition: aclchk.c:5119
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:4920
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5025
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3382
#define RelationGetRelationName(relation)
Definition: rel.h:437
bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid)
Definition: aclchk.c:4731
bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
Definition: aclchk.c:4785
#define ereport(elevel, rest)
Definition: elog.h:122
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
Definition: aclchk.c:4947
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
char * NameListToString(List *names)
Definition: namespace.c:2953
bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid)
Definition: aclchk.c:4758
bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid)
Definition: aclchk.c:4999
#define NULL
Definition: c.h:229
Definition: value.h:42
bool pg_class_ownercheck(Oid class_oid, Oid roleid)
Definition: aclchk.c:4529
bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:4866
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:417
bool pg_proc_ownercheck(Oid proc_oid, Oid roleid)
Definition: aclchk.c:4607
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:274
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5093
HeapTuple get_catalog_object_by_oid ( Relation  catalog,
Oid  objectId 
)

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

2602 {
2603  HeapTuple tuple;
2604  Oid classId = RelationGetRelid(catalog);
2605  int oidCacheId = get_object_catcache_oid(classId);
2606 
2607  if (oidCacheId > 0)
2608  {
2609  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2610  if (!HeapTupleIsValid(tuple)) /* should not happen */
2611  return NULL;
2612  }
2613  else
2614  {
2615  Oid oidIndexId = get_object_oid_index(classId);
2616  SysScanDesc scan;
2617  ScanKeyData skey;
2618 
2619  Assert(OidIsValid(oidIndexId));
2620 
2621  ScanKeyInit(&skey,
2623  BTEqualStrategyNumber, F_OIDEQ,
2624  ObjectIdGetDatum(objectId));
2625 
2626  scan = systable_beginscan(catalog, oidIndexId, true,
2627  NULL, 1, &skey);
2628  tuple = systable_getnext(scan);
2629  if (!HeapTupleIsValid(tuple))
2630  {
2631  systable_endscan(scan);
2632  return NULL;
2633  }
2634  tuple = heap_copytuple(tuple);
2635 
2636  systable_endscan(scan);
2637  }
2638 
2639  return tuple;
2640 }
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:161
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define RelationGetRelid(relation)
Definition: rel.h:417
#define BTEqualStrategyNumber
Definition: stratnum.h:31
AclObjectKind get_object_aclkind ( Oid  class_id)

Definition at line 2529 of file objectaddress.c.

References ObjectPropertyType::acl_kind, and get_object_property_data().

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

2530 {
2531  const ObjectPropertyType *prop = get_object_property_data(class_id);
2532 
2533  return prop->acl_kind;
2534 }
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 796 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_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, LockDatabaseObject(), LockSharedObject(), LookupAggWithArgs(), LookupFuncWithArgs(), LookupOperWithArgs(), LookupTypeNameOid(), lsecond, 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().

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

1415 {
1416  ObjectAddress address;
1417  List *relname;
1418  Oid reloid;
1419  Relation relation;
1420  const char *attname;
1421  AttrNumber attnum;
1422  TupleDesc tupdesc;
1423  Oid defoid;
1424 
1425  /* Extract relation name and open relation. */
1426  if (list_length(object) < 2)
1427  ereport(ERROR,
1428  (errcode(ERRCODE_SYNTAX_ERROR),
1429  errmsg("column name must be qualified")));
1430  attname = strVal(llast(object));
1431  relname = list_truncate(list_copy(object), list_length(object) - 1);
1432  /* XXX no missing_ok support here */
1433  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1434  reloid = RelationGetRelid(relation);
1435 
1436  tupdesc = RelationGetDescr(relation);
1437 
1438  /* Look up attribute number and scan pg_attrdef to find its tuple */
1439  attnum = get_attnum(reloid, attname);
1440  defoid = InvalidOid;
1441  if (attnum != InvalidAttrNumber && tupdesc->constr != NULL)
1442  {
1443  Relation attrdef;
1444  ScanKeyData keys[2];
1445  SysScanDesc scan;
1446  HeapTuple tup;
1447 
1449  ScanKeyInit(&keys[0],
1452  F_OIDEQ,
1453  ObjectIdGetDatum(reloid));
1454  ScanKeyInit(&keys[1],
1457  F_INT2EQ,
1458  Int16GetDatum(attnum));
1459  scan = systable_beginscan(attrdef, AttrDefaultIndexId, true,
1460  NULL, 2, keys);
1461  if (HeapTupleIsValid(tup = systable_getnext(scan)))
1462  defoid = HeapTupleGetOid(tup);
1463 
1464  systable_endscan(scan);
1465  relation_close(attrdef, AccessShareLock);
1466  }
1467  if (!OidIsValid(defoid))
1468  {
1469  if (!missing_ok)
1470  ereport(ERROR,
1471  (errcode(ERRCODE_UNDEFINED_COLUMN),
1472  errmsg("default value for column \"%s\" of relation \"%s\" does not exist",
1473  attname, NameListToString(relname))));
1474 
1475  address.classId = AttrDefaultRelationId;
1476  address.objectId = InvalidOid;
1477  address.objectSubId = InvalidAttrNumber;
1478  relation_close(relation, lockmode);
1479  return address;
1480  }
1481 
1482  address.classId = AttrDefaultRelationId;
1483  address.objectId = defoid;
1484  address.objectSubId = 0;
1485 
1486  *relp = relation;
1487  return address;
1488 }
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: heapam.c:1195
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:499
#define RelationGetDescr(relation)
Definition: rel.h:429
#define llast(l)
Definition: pg_list.h:126
#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:1263
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:2913
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:2953
#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:1117
#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:417
#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 1361 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().

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

Definition at line 1804 of file objectaddress.c.

References AUTHNAME, CharGetDatum, CStringGetDatum, DEFACLOBJ_FUNCTION, 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().

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

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

Referenced by get_object_address(), and get_object_address_opf_member().

1534 {
1535  Oid amoid;
1536  ObjectAddress address;
1537 
1538  /* XXX no missing_ok support here */
1539  amoid = get_index_am_oid(strVal(linitial(object)), false);
1540  object = list_copy_tail(object, 1);
1541 
1542  switch (objtype)
1543  {
1544  case OBJECT_OPCLASS:
1545  address.classId = OperatorClassRelationId;
1546  address.objectId = get_opclass_oid(amoid, object, missing_ok);
1547  address.objectSubId = 0;
1548  break;
1549  case OBJECT_OPFAMILY:
1551  address.objectId = get_opfamily_oid(amoid, object, missing_ok);
1552  address.objectSubId = 0;
1553  break;
1554  default:
1555  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1556  /* placate compiler, which doesn't know elog won't return */
1557  address.classId = InvalidOid;
1558  address.objectId = InvalidOid;
1559  address.objectSubId = 0;
1560  }
1561 
1562  return address;
1563 }
#define 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:110
#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 1571 of file objectaddress.c.

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

Referenced by get_object_address().

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

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

Definition at line 1282 of file objectaddress.c.

References AccessShareLock, ObjectAddress::classId, 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().

1284 {
1285  ObjectAddress address;
1286  Relation relation = NULL;
1287  int nnames;
1288  const char *depname;
1289  List *relname;
1290  Oid reloid;
1291 
1292  /* Extract name of dependent object. */
1293  depname = strVal(llast(object));
1294 
1295  /* Separate relation name from dependent object name. */
1296  nnames = list_length(object);
1297  if (nnames < 2)
1298  ereport(ERROR,
1299  (errcode(ERRCODE_SYNTAX_ERROR),
1300  errmsg("must specify relation and object name")));
1301 
1302  /* Extract relation name and open relation. */
1303  relname = list_truncate(list_copy(object), nnames - 1);
1304  relation = heap_openrv_extended(makeRangeVarFromNameList(relname),
1306  missing_ok);
1307 
1308  reloid = relation ? RelationGetRelid(relation) : InvalidOid;
1309 
1310  switch (objtype)
1311  {
1312  case OBJECT_RULE:
1313  address.classId = RewriteRelationId;
1314  address.objectId = relation ?
1315  get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
1316  address.objectSubId = 0;
1317  break;
1318  case OBJECT_TRIGGER:
1319  address.classId = TriggerRelationId;
1320  address.objectId = relation ?
1321  get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
1322  address.objectSubId = 0;
1323  break;
1324  case OBJECT_TABCONSTRAINT:
1325  address.classId = ConstraintRelationId;
1326  address.objectId = relation ?
1327  get_relation_constraint_oid(reloid, depname, missing_ok) :
1328  InvalidOid;
1329  address.objectSubId = 0;
1330  break;
1331  case OBJECT_POLICY:
1332  address.classId = PolicyRelationId;
1333  address.objectId = relation ?
1334  get_relation_policy_oid(reloid, depname, missing_ok) :
1335  InvalidOid;
1336  address.objectSubId = 0;
1337  break;
1338  default:
1339  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1340  }
1341 
1342  /* Avoid relcache leak when object not found. */
1343  if (!OidIsValid(address.objectId))
1344  {
1345  if (relation != NULL)
1346  heap_close(relation, AccessShareLock);
1347 
1348  relation = NULL; /* department of accident prevention */
1349  return address;
1350  }
1351 
1352  /* Done. */
1353  *relp = relation;
1354  return address;
1355 }
Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok)
#define llast(l)
Definition: pg_list.h:126
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:2913
#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:1344
#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:1310
#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:1268
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:417
ObjectAddress get_object_address_rv ( ObjectType  objtype,
RangeVar rel,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)

Definition at line 1093 of file objectaddress.c.

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

Referenced by ExecAlterObjectDependsStmt().

1096 {
1097  if (rel)
1098  {
1099  object = lcons(makeString(rel->relname), object);
1100  if (rel->schemaname)
1101  object = lcons(makeString(rel->schemaname), object);
1102  if (rel->catalogname)
1103  object = lcons(makeString(rel->catalogname), object);
1104  }
1105 
1106  return get_object_address(objtype, (Node *) object,
1107  relp, lockmode, missing_ok);
1108 }
Value * makeString(char *str)
Definition: value.c:53
Definition: nodes.h:506
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 1494 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().

1495 {
1496  ObjectAddress address;
1497  Type tup;
1498 
1499  address.classId = TypeRelationId;
1500  address.objectId = InvalidOid;
1501  address.objectSubId = 0;
1502 
1503  tup = LookupTypeName(NULL, typename, NULL, missing_ok);
1504  if (!HeapTupleIsValid(tup))
1505  {
1506  if (!missing_ok)
1507  ereport(ERROR,
1508  (errcode(ERRCODE_UNDEFINED_OBJECT),
1509  errmsg("type \"%s\" does not exist",
1510  TypeNameToString(typename))));
1511  return address;
1512  }
1513  address.objectId = typeTypeId(tup);
1514 
1515  if (objtype == OBJECT_DOMAIN)
1516  {
1517  if (((Form_pg_type) GETSTRUCT(tup))->typtype != TYPTYPE_DOMAIN)
1518  ereport(ERROR,
1519  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1520  errmsg("\"%s\" is not a domain",
1521  TypeNameToString(typename))));
1522  }
1523 
1524  ReleaseSysCache(tup);
1525 
1526  return address;
1527 }
Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:57
#define TYPTYPE_DOMAIN
Definition: pg_type.h:718
#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:1116
#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 1115 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().

1117 {
1118  const char *name;
1119  ObjectAddress address;
1120 
1121  name = strVal(strval);
1122 
1123  /* Translate name to OID. */
1124  switch (objtype)
1125  {
1126  case OBJECT_ACCESS_METHOD:
1127  address.classId = AccessMethodRelationId;
1128  address.objectId = get_am_oid(name, missing_ok);
1129  address.objectSubId = 0;
1130  break;
1131  case OBJECT_DATABASE:
1132  address.classId = DatabaseRelationId;
1133  address.objectId = get_database_oid(name, missing_ok);
1134  address.objectSubId = 0;
1135  break;
1136  case OBJECT_EXTENSION:
1137  address.classId = ExtensionRelationId;
1138  address.objectId = get_extension_oid(name, missing_ok);
1139  address.objectSubId = 0;
1140  break;
1141  case OBJECT_TABLESPACE:
1142  address.classId = TableSpaceRelationId;
1143  address.objectId = get_tablespace_oid(name, missing_ok);
1144  address.objectSubId = 0;
1145  break;
1146  case OBJECT_ROLE:
1147  address.classId = AuthIdRelationId;
1148  address.objectId = get_role_oid(name, missing_ok);
1149  address.objectSubId = 0;
1150  break;
1151  case OBJECT_SCHEMA:
1152  address.classId = NamespaceRelationId;
1153  address.objectId = get_namespace_oid(name, missing_ok);
1154  address.objectSubId = 0;
1155  break;
1156  case OBJECT_LANGUAGE:
1157  address.classId = LanguageRelationId;
1158  address.objectId = get_language_oid(name, missing_ok);
1159  address.objectSubId = 0;
1160  break;
1161  case OBJECT_FDW:
1163  address.objectId = get_foreign_data_wrapper_oid(name, missing_ok);
1164  address.objectSubId = 0;
1165  break;
1166  case OBJECT_FOREIGN_SERVER:
1167  address.classId = ForeignServerRelationId;
1168  address.objectId = get_foreign_server_oid(name, missing_ok);
1169  address.objectSubId = 0;
1170  break;
1171  case OBJECT_EVENT_TRIGGER:
1172  address.classId = EventTriggerRelationId;
1173  address.objectId = get_event_trigger_oid(name, missing_ok);
1174  address.objectSubId = 0;
1175  break;
1176  case OBJECT_PUBLICATION:
1177  address.classId = PublicationRelationId;
1178  address.objectId = get_publication_oid(name, missing_ok);
1179  address.objectSubId = 0;
1180  break;
1181  case OBJECT_SUBSCRIPTION:
1182  address.classId = SubscriptionRelationId;
1183  address.objectId = get_subscription_oid(name, missing_ok);
1184  address.objectSubId = 0;
1185  break;
1186  default:
1187  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1188  /* placate compiler, which doesn't know elog won't return */
1189  address.classId = InvalidOid;
1190  address.objectId = InvalidOid;
1191  address.objectSubId = 0;
1192  }
1193 
1194  return address;
1195 }
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:2895
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:2001
#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:134
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 1681 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, USERMAPPINGUSERSERVER, and username.

Referenced by get_object_address().

1682 {
1683  ObjectAddress address;
1684  Oid userid;
1685  char *username;
1686  char *servername;
1687  ForeignServer *server;
1688  HeapTuple tp;
1689 
1691 
1692  /* fetch string names from input lists, for error messages */
1693  username = strVal(linitial(object));
1694  servername = strVal(lsecond(object));
1695 
1696  /* look up pg_authid OID of mapped user; InvalidOid if PUBLIC */
1697  if (strcmp(username, "public") == 0)
1698  userid = InvalidOid;
1699  else
1700  {
1702  CStringGetDatum(username));
1703  if (!HeapTupleIsValid(tp))
1704  {
1705  if (!missing_ok)
1706  ereport(ERROR,
1707  (errcode(ERRCODE_UNDEFINED_OBJECT),
1708  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1709  username, servername)));
1710  return address;
1711  }
1712  userid = HeapTupleGetOid(tp);
1713  ReleaseSysCache(tp);
1714  }
1715 
1716  /* Now look up the pg_user_mapping tuple */
1717  server = GetForeignServerByName(servername, true);
1718  if (!server)
1719  {
1720  if (!missing_ok)
1721  ereport(ERROR,
1722  (errcode(ERRCODE_UNDEFINED_OBJECT),
1723  errmsg("server \"%s\" does not exist", servername)));
1724  return address;
1725  }
1727  ObjectIdGetDatum(userid),
1728  ObjectIdGetDatum(server->serverid));
1729  if (!HeapTupleIsValid(tp))
1730  {
1731  if (!missing_ok)
1732  ereport(ERROR,
1733  (errcode(ERRCODE_UNDEFINED_OBJECT),
1734  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1735  username, servername)));
1736  return address;
1737  }
1738 
1739  address.objectId = HeapTupleGetOid(tp);
1740 
1741  ReleaseSysCache(tp);
1742 
1743  return address;
1744 }
#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:114
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
#define linitial(l)
Definition: pg_list.h:110
#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:1116
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:154
AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 2521 of file objectaddress.c.

References ObjectPropertyType::attnum_acl, and get_object_property_data().

Referenced by AlterObjectOwner_internal().

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

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

2498 {
2499  const ObjectPropertyType *prop = get_object_property_data(class_id);
2500 
2501  return prop->attnum_name;
2502 }
AttrNumber attnum_name
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber get_object_attnum_namespace ( Oid  class_id)

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

2506 {
2507  const ObjectPropertyType *prop = get_object_property_data(class_id);
2508 
2509  return prop->attnum_namespace;
2510 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_namespace
AttrNumber get_object_attnum_owner ( Oid  class_id)

Definition at line 2513 of file objectaddress.c.

References ObjectPropertyType::attnum_owner, and get_object_property_data().

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

2514 {
2515  const ObjectPropertyType *prop = get_object_property_data(class_id);
2516 
2517  return prop->attnum_owner;
2518 }
AttrNumber attnum_owner
static const ObjectPropertyType * get_object_property_data(Oid class_id)
int get_object_catcache_name ( Oid  class_id)

Definition at line 2489 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

2490 {
2491  const ObjectPropertyType *prop = get_object_property_data(class_id);
2492 
2493  return prop->name_catcache_id;
2494 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
int get_object_catcache_oid ( Oid  class_id)

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

2482 {
2483  const ObjectPropertyType *prop = get_object_property_data(class_id);
2484 
2485  return prop->oid_catcache_id;
2486 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
bool get_object_namensp_unique ( Oid  class_id)

Definition at line 2537 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::is_nsp_name_unique.

Referenced by EventTriggerSQLDropAddObject(), and pg_identify_object().

2538 {
2539  const ObjectPropertyType *prop = get_object_property_data(class_id);
2540 
2541  return prop->is_nsp_name_unique;
2542 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
Oid get_object_namespace ( const ObjectAddress address)

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

2415 {
2416  int cache;
2417  HeapTuple tuple;
2418  bool isnull;
2419  Oid oid;
2420  const ObjectPropertyType *property;
2421 
2422  /* If not owned by a namespace, just return InvalidOid. */
2423  property = get_object_property_data(address->classId);
2424  if (property->attnum_namespace == InvalidAttrNumber)
2425  return InvalidOid;
2426 
2427  /* Currently, we can only handle object types with system caches. */
2428  cache = property->oid_catcache_id;
2429  Assert(cache != -1);
2430 
2431  /* Fetch tuple from syscache and extract namespace attribute. */
2432  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2433  if (!HeapTupleIsValid(tuple))
2434  elog(ERROR, "cache lookup failed for cache %d oid %u",
2435  cache, address->objectId);
2436  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2437  tuple,
2438  property->attnum_namespace,
2439  &isnull));
2440  Assert(!isnull);
2441  ReleaseSysCache(tuple);
2442 
2443  return oid;
2444 }
#define DatumGetObjectId(X)
Definition: postgres.h:506
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:152
#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:1116
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1278
#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 2473 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by get_catalog_object_by_oid().

2474 {
2475  const ObjectPropertyType *prop = get_object_property_data(class_id);
2476 
2477  return prop->oid_index_oid;
2478 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
static const ObjectPropertyType * get_object_property_data ( Oid  class_id)
static

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

2567 {
2568  static const ObjectPropertyType *prop_last = NULL;
2569  int index;
2570 
2571  /*
2572  * A shortcut to speed up multiple consecutive lookups of a particular
2573  * object class.
2574  */
2575  if (prop_last && prop_last->class_oid == class_id)
2576  return prop_last;
2577 
2578  for (index = 0; index < lengthof(ObjectProperty); index++)
2579  {
2580  if (ObjectProperty[index].class_oid == class_id)
2581  {
2582  prop_last = &ObjectProperty[index];
2583  return &ObjectProperty[index];
2584  }
2585  }
2586 
2587  ereport(ERROR,
2588  (errmsg_internal("unrecognized class ID: %u", class_id)));
2589 
2590  return NULL; /* keep MSC compiler happy */
2591 }
#define lengthof(array)
Definition: c.h:562
Definition: type.h:90
#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 1201 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().

1204 {
1205  Relation relation;
1206  ObjectAddress address;
1207 
1208  address.classId = RelationRelationId;
1209  address.objectId = InvalidOid;
1210  address.objectSubId = 0;
1211 
1213  lockmode, missing_ok);
1214  if (!relation)
1215  return address;
1216 
1217  switch (objtype)
1218  {
1219  case OBJECT_INDEX:
1220  if (relation->rd_rel->relkind != RELKIND_INDEX)
1221  ereport(ERROR,
1222  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1223  errmsg("\"%s\" is not an index",
1224  RelationGetRelationName(relation))));
1225  break;
1226  case OBJECT_SEQUENCE:
1227  if (relation->rd_rel->relkind != RELKIND_SEQUENCE)
1228  ereport(ERROR,
1229  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1230  errmsg("\"%s\" is not a sequence",
1231  RelationGetRelationName(relation))));
1232  break;
1233  case OBJECT_TABLE:
1234  if (relation->rd_rel->relkind != RELKIND_RELATION &&
1235  relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1236  ereport(ERROR,
1237  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1238  errmsg("\"%s\" is not a table",
1239  RelationGetRelationName(relation))));
1240  break;
1241  case OBJECT_VIEW:
1242  if (relation->rd_rel->relkind != RELKIND_VIEW)
1243  ereport(ERROR,
1244  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1245  errmsg("\"%s\" is not a view",
1246  RelationGetRelationName(relation))));
1247  break;
1248  case OBJECT_MATVIEW:
1249  if (relation->rd_rel->relkind != RELKIND_MATVIEW)
1250  ereport(ERROR,
1251  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1252  errmsg("\"%s\" is not a materialized view",
1253  RelationGetRelationName(relation))));
1254  break;
1255  case OBJECT_FOREIGN_TABLE:
1256  if (relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE)
1257  ereport(ERROR,
1258  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1259  errmsg("\"%s\" is not a foreign table",
1260  RelationGetRelationName(relation))));
1261  break;
1262  default:
1263  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1264  break;
1265  }
1266 
1267  /* Done. */
1268  address.objectId = RelationGetRelid(relation);
1269  *relp = relation;
1270 
1271  return address;
1272 }
#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:2913
Form_pg_class rd_rel
Definition: rel.h:114
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:437
#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:417
Relation relation_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: heapam.c:1230
static void getConstraintTypeDescription ( StringInfo  buffer,
Oid  constroid 
)
static

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

3959 {
3960  Relation constrRel;
3961  HeapTuple constrTup;
3962  Form_pg_constraint constrForm;
3963 
3965  constrTup = get_catalog_object_by_oid(constrRel, constroid);
3966  if (!HeapTupleIsValid(constrTup))
3967  elog(ERROR, "cache lookup failed for constraint %u", constroid);
3968 
3969  constrForm = (Form_pg_constraint) GETSTRUCT(constrTup);
3970 
3971  if (OidIsValid(constrForm->conrelid))
3972  appendStringInfoString(buffer, "table constraint");
3973  else if (OidIsValid(constrForm->contypid))
3974  appendStringInfoString(buffer, "domain constraint");
3975  else
3976  elog(ERROR, "invalid constraint %u", HeapTupleGetOid(constrTup));
3977 
3978  heap_close(constrRel, AccessShareLock);
3979 }
#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:189
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1287
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 2648 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_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_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, 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().

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

Definition at line 3405 of file objectaddress.c.

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

3406 {
3407  ObjectAddress address;
3408 
3409  address.classId = classid;
3410  address.objectId = objid;
3411  address.objectSubId = 0;
3412 
3413  return getObjectDescription(&address);
3414 }
char * getObjectDescription(const ObjectAddress *object)
char* getObjectIdentityParts ( const ObjectAddress object,
List **  objname,
List **  objargs 
)

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

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