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_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, List *qualname, bool missing_ok)
 
static ObjectAddress get_relation_by_qualified_name (ObjectType objtype, List *objname, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static ObjectAddress get_object_address_relobject (ObjectType objtype, List *objname, Relation *relp, bool missing_ok)
 
static ObjectAddress get_object_address_attribute (ObjectType objtype, List *objname, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static ObjectAddress get_object_address_attrdef (ObjectType objtype, List *objname, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static ObjectAddress get_object_address_type (ObjectType objtype, ListCell *typecell, bool missing_ok)
 
static ObjectAddress get_object_address_opcf (ObjectType objtype, List *objname, bool missing_ok)
 
static ObjectAddress get_object_address_opf_member (ObjectType objtype, List *objname, List *objargs, bool missing_ok)
 
static ObjectAddress get_object_address_usermapping (List *objname, List *objargs, bool missing_ok)
 
static ObjectAddress get_object_address_publication_rel (List *objname, List *objargs, Relation *relp, bool missing_ok)
 
static ObjectAddress get_object_address_defacl (List *objname, List *objargs, 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 **objname)
 
static void getRelationIdentity (StringInfo buffer, Oid relid, List **objname)
 
ObjectAddress get_object_address (ObjectType objtype, List *objname, List *objargs, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
ObjectAddress get_object_address_rv (ObjectType objtype, RangeVar *rel, List *objname, List *objargs, 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, List *objname, List *objargs, 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,
List objname,
List objargs,
Relation  relation 
)

Definition at line 2158 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, elog, ereport, errcode(), errmsg(), ERROR, format_type_be(), has_createrole_privilege(), linitial, lo_compat_privileges, 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_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_subscription_ownercheck(), pg_tablespace_ownercheck(), pg_ts_config_ownercheck(), pg_ts_dict_ownercheck(), pg_type_ownercheck(), RelationGetRelationName, RelationGetRelid, superuser_arg(), and typenameTypeId().

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

2160 {
2161  switch (objtype)
2162  {
2163  case OBJECT_INDEX:
2164  case OBJECT_SEQUENCE:
2165  case OBJECT_TABLE:
2166  case OBJECT_VIEW:
2167  case OBJECT_MATVIEW:
2168  case OBJECT_FOREIGN_TABLE:
2169  case OBJECT_COLUMN:
2170  case OBJECT_RULE:
2171  case OBJECT_TRIGGER:
2172  case OBJECT_POLICY:
2173  case OBJECT_TABCONSTRAINT:
2174  if (!pg_class_ownercheck(RelationGetRelid(relation), roleid))
2176  RelationGetRelationName(relation));
2177  break;
2178  case OBJECT_DATABASE:
2179  if (!pg_database_ownercheck(address.objectId, roleid))
2181  NameListToString(objname));
2182  break;
2183  case OBJECT_TYPE:
2184  case OBJECT_DOMAIN:
2185  case OBJECT_ATTRIBUTE:
2186  case OBJECT_DOMCONSTRAINT:
2187  if (!pg_type_ownercheck(address.objectId, roleid))
2189  break;
2190  case OBJECT_AGGREGATE:
2191  case OBJECT_FUNCTION:
2192  if (!pg_proc_ownercheck(address.objectId, roleid))
2194  NameListToString(objname));
2195  break;
2196  case OBJECT_OPERATOR:
2197  if (!pg_oper_ownercheck(address.objectId, roleid))
2199  NameListToString(objname));
2200  break;
2201  case OBJECT_SCHEMA:
2202  if (!pg_namespace_ownercheck(address.objectId, roleid))
2204  NameListToString(objname));
2205  break;
2206  case OBJECT_COLLATION:
2207  if (!pg_collation_ownercheck(address.objectId, roleid))
2209  NameListToString(objname));
2210  break;
2211  case OBJECT_CONVERSION:
2212  if (!pg_conversion_ownercheck(address.objectId, roleid))
2214  NameListToString(objname));
2215  break;
2216  case OBJECT_EXTENSION:
2217  if (!pg_extension_ownercheck(address.objectId, roleid))
2219  NameListToString(objname));
2220  break;
2221  case OBJECT_FDW:
2222  if (!pg_foreign_data_wrapper_ownercheck(address.objectId, roleid))
2224  NameListToString(objname));
2225  break;
2226  case OBJECT_FOREIGN_SERVER:
2227  if (!pg_foreign_server_ownercheck(address.objectId, roleid))
2229  NameListToString(objname));
2230  break;
2231  case OBJECT_EVENT_TRIGGER:
2232  if (!pg_event_trigger_ownercheck(address.objectId, roleid))
2234  NameListToString(objname));
2235  break;
2236  case OBJECT_LANGUAGE:
2237  if (!pg_language_ownercheck(address.objectId, roleid))
2239  NameListToString(objname));
2240  break;
2241  case OBJECT_OPCLASS:
2242  if (!pg_opclass_ownercheck(address.objectId, roleid))
2244  NameListToString(objname));
2245  break;
2246  case OBJECT_OPFAMILY:
2247  if (!pg_opfamily_ownercheck(address.objectId, roleid))
2249  NameListToString(objname));
2250  break;
2251  case OBJECT_LARGEOBJECT:
2252  if (!lo_compat_privileges &&
2253  !pg_largeobject_ownercheck(address.objectId, roleid))
2254  ereport(ERROR,
2255  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2256  errmsg("must be owner of large object %u",
2257  address.objectId)));
2258  break;
2259  case OBJECT_CAST:
2260  {
2261  /* We can only check permissions on the source/target types */
2262  TypeName *sourcetype = (TypeName *) linitial(objname);
2263  TypeName *targettype = (TypeName *) linitial(objargs);
2264  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2265  Oid targettypeid = typenameTypeId(NULL, targettype);
2266 
2267  if (!pg_type_ownercheck(sourcetypeid, roleid)
2268  && !pg_type_ownercheck(targettypeid, roleid))
2269  ereport(ERROR,
2270  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2271  errmsg("must be owner of type %s or type %s",
2272  format_type_be(sourcetypeid),
2273  format_type_be(targettypeid))));
2274  }
2275  break;
2276  case OBJECT_PUBLICATION:
2277  if (!pg_publication_ownercheck(address.objectId, roleid))
2279  NameListToString(objname));
2280  break;
2281  case OBJECT_SUBSCRIPTION:
2282  if (!pg_subscription_ownercheck(address.objectId, roleid))
2284  NameListToString(objname));
2285  break;
2286  case OBJECT_TRANSFORM:
2287  {
2288  TypeName *typename = (TypeName *) linitial(objname);
2289  Oid typeid = typenameTypeId(NULL, typename);
2290 
2291  if (!pg_type_ownercheck(typeid, roleid))
2293  }
2294  break;
2295  case OBJECT_TABLESPACE:
2296  if (!pg_tablespace_ownercheck(address.objectId, roleid))
2298  NameListToString(objname));
2299  break;
2300  case OBJECT_TSDICTIONARY:
2301  if (!pg_ts_dict_ownercheck(address.objectId, roleid))
2303  NameListToString(objname));
2304  break;
2306  if (!pg_ts_config_ownercheck(address.objectId, roleid))
2308  NameListToString(objname));
2309  break;
2310  case OBJECT_ROLE:
2311 
2312  /*
2313  * We treat roles as being "owned" by those with CREATEROLE priv,
2314  * except that superusers are only owned by superusers.
2315  */
2316  if (superuser_arg(address.objectId))
2317  {
2318  if (!superuser_arg(roleid))
2319  ereport(ERROR,
2320  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2321  errmsg("must be superuser")));
2322  }
2323  else
2324  {
2325  if (!has_createrole_privilege(roleid))
2326  ereport(ERROR,
2327  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2328  errmsg("must have CREATEROLE privilege")));
2329  }
2330  break;
2331  case OBJECT_TSPARSER:
2332  case OBJECT_TSTEMPLATE:
2333  case OBJECT_ACCESS_METHOD:
2334  /* We treat these object types as being owned by superusers */
2335  if (!superuser_arg(roleid))
2336  ereport(ERROR,
2337  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2338  errmsg("must be superuser")));
2339  break;
2340  default:
2341  elog(ERROR, "unrecognized object type: %d",
2342  (int) objtype);
2343  }
2344 }
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:5119
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:4965
bool pg_largeobject_ownercheck(Oid lobj_oid, Oid roleid)
Definition: aclchk.c:4654
bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid)
Definition: aclchk.c:4804
bool pg_language_ownercheck(Oid lan_oid, Oid roleid)
Definition: aclchk.c:4625
bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid)
Definition: aclchk.c:4831
bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:4885
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5059
bool pg_oper_ownercheck(Oid oper_oid, Oid roleid)
Definition: aclchk.c:4573
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:4697
unsigned int Oid
Definition: postgres_ext.h:31
bool pg_type_ownercheck(Oid type_oid, Oid roleid)
Definition: aclchk.c:4547
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3436
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_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:4912
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5017
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3378
#define RelationGetRelationName(relation)
Definition: rel.h:433
bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid)
Definition: aclchk.c:4723
bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
Definition: aclchk.c:4777
#define ereport(elevel, rest)
Definition: elog.h:122
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
Definition: aclchk.c:4939
bool superuser_arg(Oid roleid)
Definition: superuser.c:57
char * NameListToString(List *names)
Definition: namespace.c:2897
bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid)
Definition: aclchk.c:4750
bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid)
Definition: aclchk.c:4991
#define NULL
Definition: c.h:226
bool pg_class_ownercheck(Oid class_oid, Oid roleid)
Definition: aclchk.c:4521
bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:4858
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define elog
Definition: elog.h:219
#define RelationGetRelid(relation)
Definition: rel.h:413
bool pg_proc_ownercheck(Oid proc_oid, Oid roleid)
Definition: aclchk.c:4599
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:274
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5085
HeapTuple get_catalog_object_by_oid ( Relation  catalog,
Oid  objectId 
)

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

2541 {
2542  HeapTuple tuple;
2543  Oid classId = RelationGetRelid(catalog);
2544  int oidCacheId = get_object_catcache_oid(classId);
2545 
2546  if (oidCacheId > 0)
2547  {
2548  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2549  if (!HeapTupleIsValid(tuple)) /* should not happen */
2550  return NULL;
2551  }
2552  else
2553  {
2554  Oid oidIndexId = get_object_oid_index(classId);
2555  SysScanDesc scan;
2556  ScanKeyData skey;
2557 
2558  Assert(OidIsValid(oidIndexId));
2559 
2560  ScanKeyInit(&skey,
2562  BTEqualStrategyNumber, F_OIDEQ,
2563  ObjectIdGetDatum(objectId));
2564 
2565  scan = systable_beginscan(catalog, oidIndexId, true,
2566  NULL, 1, &skey);
2567  tuple = systable_getnext(scan);
2568  if (!HeapTupleIsValid(tuple))
2569  {
2570  systable_endscan(scan);
2571  return NULL;
2572  }
2573  tuple = heap_copytuple(tuple);
2574 
2575  systable_endscan(scan);
2576  }
2577 
2578  return tuple;
2579 }
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:608
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#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:534
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
int get_object_catcache_oid(Oid class_id)
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:158
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define RelationGetRelid(relation)
Definition: rel.h:413
#define BTEqualStrategyNumber
Definition: stratnum.h:31
AclObjectKind get_object_aclkind ( Oid  class_id)

Definition at line 2468 of file objectaddress.c.

References ObjectPropertyType::acl_kind, and get_object_property_data().

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

2469 {
2470  const ObjectPropertyType *prop = get_object_property_data(class_id);
2471 
2472  return prop->acl_kind;
2473 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AclObjectKind acl_kind
ObjectAddress get_object_address ( ObjectType  objtype,
List objname,
List objargs,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)

Definition at line 779 of file objectaddress.c.

References Assert, 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_transform_oid(), get_ts_config_oid(), get_ts_dict_oid(), get_ts_parser_oid(), get_ts_template_oid(), InvalidOid, IsSharedRelation(), LargeObjectExists(), LargeObjectRelationId, linitial, list_head(), list_length(), LockDatabaseObject(), LockSharedObject(), LookupAggNameTypeNames(), LookupFuncNameTypeNames(), LookupOperNameTypeNames(), 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_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, 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().

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

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

1454 {
1455  ObjectAddress address;
1456  List *relname;
1457  Oid reloid;
1458  Relation relation;
1459  const char *attname;
1460  AttrNumber attnum;
1461  TupleDesc tupdesc;
1462  Oid defoid;
1463 
1464  /* Extract relation name and open relation. */
1465  if (list_length(objname) < 2)
1466  ereport(ERROR,
1467  (errcode(ERRCODE_SYNTAX_ERROR),
1468  errmsg("column name must be qualified")));
1469  attname = strVal(llast(objname));
1470  relname = list_truncate(list_copy(objname), list_length(objname) - 1);
1471  /* XXX no missing_ok support here */
1472  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1473  reloid = RelationGetRelid(relation);
1474 
1475  tupdesc = RelationGetDescr(relation);
1476 
1477  /* Look up attribute number and scan pg_attrdef to find its tuple */
1478  attnum = get_attnum(reloid, attname);
1479  defoid = InvalidOid;
1480  if (attnum != InvalidAttrNumber && tupdesc->constr != NULL)
1481  {
1482  Relation attrdef;
1483  ScanKeyData keys[2];
1484  SysScanDesc scan;
1485  HeapTuple tup;
1486 
1488  ScanKeyInit(&keys[0],
1491  F_OIDEQ,
1492  ObjectIdGetDatum(reloid));
1493  ScanKeyInit(&keys[1],
1496  F_INT2EQ,
1497  Int16GetDatum(attnum));
1498  scan = systable_beginscan(attrdef, AttrDefaultIndexId, true,
1499  NULL, 2, keys);
1500  if (HeapTupleIsValid(tup = systable_getnext(scan)))
1501  defoid = HeapTupleGetOid(tup);
1502 
1503  systable_endscan(scan);
1504  relation_close(attrdef, AccessShareLock);
1505  }
1506  if (!OidIsValid(defoid))
1507  {
1508  if (!missing_ok)
1509  ereport(ERROR,
1510  (errcode(ERRCODE_UNDEFINED_COLUMN),
1511  errmsg("default value for column \"%s\" of relation \"%s\" does not exist",
1512  attname, NameListToString(relname))));
1513 
1514  address.classId = AttrDefaultRelationId;
1515  address.objectId = InvalidOid;
1516  address.objectSubId = InvalidAttrNumber;
1517  relation_close(relation, lockmode);
1518  return address;
1519  }
1520 
1521  address.classId = AttrDefaultRelationId;
1522  address.objectId = defoid;
1523  address.objectSubId = 0;
1524 
1525  *relp = relation;
1526  return address;
1527 }
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: heapam.c:1195
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#define RelationGetDescr(relation)
Definition: rel.h:425
#define llast(l)
Definition: pg_list.h:126
#define Int16GetDatum(X)
Definition: postgres.h:459
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:2857
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:534
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:410
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#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:2897
#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:226
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:413
#define BTEqualStrategyNumber
Definition: stratnum.h:31
static ObjectAddress get_object_address_attribute ( ObjectType  objtype,
List objname,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
static

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

1403 {
1404  ObjectAddress address;
1405  List *relname;
1406  Oid reloid;
1407  Relation relation;
1408  const char *attname;
1409  AttrNumber attnum;
1410 
1411  /* Extract relation name and open relation. */
1412  if (list_length(objname) < 2)
1413  ereport(ERROR,
1414  (errcode(ERRCODE_SYNTAX_ERROR),
1415  errmsg("column name must be qualified")));
1416  attname = strVal(lfirst(list_tail(objname)));
1417  relname = list_truncate(list_copy(objname), list_length(objname) - 1);
1418  /* XXX no missing_ok support here */
1419  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1420  reloid = RelationGetRelid(relation);
1421 
1422  /* Look up attribute and construct return value. */
1423  attnum = get_attnum(reloid, attname);
1424  if (attnum == InvalidAttrNumber)
1425  {
1426  if (!missing_ok)
1427  ereport(ERROR,
1428  (errcode(ERRCODE_UNDEFINED_COLUMN),
1429  errmsg("column \"%s\" of relation \"%s\" does not exist",
1430  attname, NameListToString(relname))));
1431 
1432  address.classId = RelationRelationId;
1433  address.objectId = InvalidOid;
1434  address.objectSubId = InvalidAttrNumber;
1435  relation_close(relation, lockmode);
1436  return address;
1437  }
1438 
1439  address.classId = RelationRelationId;
1440  address.objectId = reloid;
1441  address.objectSubId = attnum;
1442 
1443  *relp = relation;
1444  return address;
1445 }
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:2857
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:2897
#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:413
static ObjectAddress get_object_address_defacl ( List objname,
List objargs,
bool  missing_ok 
)
static

Definition at line 1839 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, NULL, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum, ReleaseSysCache(), SearchSysCache1, SearchSysCache3, strVal, and username.

Referenced by get_object_address().

1840 {
1841  HeapTuple tp;
1842  Oid userid;
1843  Oid schemaid;
1844  char *username;
1845  char *schema;
1846  char objtype;
1847  char *objtype_str;
1848  ObjectAddress address;
1849 
1851 
1852  /*
1853  * First figure out the textual attributes so that they can be used for
1854  * error reporting.
1855  */
1856  username = strVal(linitial(objname));
1857  if (list_length(objname) >= 2)
1858  schema = (char *) strVal(lsecond(objname));
1859  else
1860  schema = NULL;
1861 
1862  /*
1863  * Decode defaclobjtype. Only first char is considered; the rest of the
1864  * string, if any, is blissfully ignored.
1865  */
1866  objtype = ((char *) strVal(linitial(objargs)))[0];
1867  switch (objtype)
1868  {
1869  case DEFACLOBJ_RELATION:
1870  objtype_str = "tables";
1871  break;
1872  case DEFACLOBJ_SEQUENCE:
1873  objtype_str = "sequences";
1874  break;
1875  case DEFACLOBJ_FUNCTION:
1876  objtype_str = "functions";
1877  break;
1878  case DEFACLOBJ_TYPE:
1879  objtype_str = "types";
1880  break;
1881  default:
1882  ereport(ERROR,
1883  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1884  errmsg("unrecognized default ACL object type %c", objtype),
1885  errhint("Valid object types are \"r\", \"S\", \"f\", and \"T\".")));
1886  }
1887 
1888  /*
1889  * Look up user ID. Behave as "default ACL not found" if the user doesn't
1890  * exist.
1891  */
1893  CStringGetDatum(username));
1894  if (!HeapTupleIsValid(tp))
1895  goto not_found;
1896  userid = HeapTupleGetOid(tp);
1897  ReleaseSysCache(tp);
1898 
1899  /*
1900  * If a schema name was given, look up its OID. If it doesn't exist,
1901  * behave as "default ACL not found".
1902  */
1903  if (schema)
1904  {
1905  schemaid = get_namespace_oid(schema, true);
1906  if (schemaid == InvalidOid)
1907  goto not_found;
1908  }
1909  else
1910  schemaid = InvalidOid;
1911 
1912  /* Finally, look up the pg_default_acl object */
1914  ObjectIdGetDatum(userid),
1915  ObjectIdGetDatum(schemaid),
1916  CharGetDatum(objtype));
1917  if (!HeapTupleIsValid(tp))
1918  goto not_found;
1919 
1920  address.objectId = HeapTupleGetOid(tp);
1921  ReleaseSysCache(tp);
1922 
1923  return address;
1924 
1925 not_found:
1926  if (!missing_ok)
1927  {
1928  if (schema)
1929  ereport(ERROR,
1930  (errcode(ERRCODE_UNDEFINED_OBJECT),
1931  errmsg("default ACL for user \"%s\" in schema \"%s\" on %s does not exist",
1932  username, schema, objtype_str)));
1933  else
1934  ereport(ERROR,
1935  (errcode(ERRCODE_UNDEFINED_OBJECT),
1936  errmsg("default ACL for user \"%s\" on %s does not exist",
1937  username, objtype_str)));
1938  }
1939  return address;
1940 }
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:2839
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:149
#define linitial(l)
Definition: pg_list.h:110
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
#define DEFACLOBJ_SEQUENCE
#define CStringGetDatum(X)
Definition: postgres.h:586
#define ereport(elevel, rest)
Definition: elog.h:122
#define DEFACLOBJ_TYPE
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1083
static char * username
Definition: initdb.c:129
#define InvalidOid
Definition: postgres_ext.h:36
#define DEFACLOBJ_RELATION
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
#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:424
int errmsg(const char *fmt,...)
Definition: elog.c:797
#define SearchSysCache3(cacheId, key1, key2, key3)
Definition: syscache.h:153
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
static ObjectAddress get_object_address_opcf ( ObjectType  objtype,
List objname,
bool  missing_ok 
)
static

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

1576 {
1577  Oid amoid;
1578  ObjectAddress address;
1579 
1580  /* XXX no missing_ok support here */
1581  amoid = get_index_am_oid(strVal(linitial(objname)), false);
1582  objname = list_copy_tail(objname, 1);
1583 
1584  switch (objtype)
1585  {
1586  case OBJECT_OPCLASS:
1587  address.classId = OperatorClassRelationId;
1588  address.objectId = get_opclass_oid(amoid, objname, missing_ok);
1589  address.objectSubId = 0;
1590  break;
1591  case OBJECT_OPFAMILY:
1593  address.objectId = get_opfamily_oid(amoid, objname, missing_ok);
1594  address.objectSubId = 0;
1595  break;
1596  default:
1597  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1598  /* placate compiler, which doesn't know elog won't return */
1599  address.classId = InvalidOid;
1600  address.objectId = InvalidOid;
1601  address.objectSubId = 0;
1602  }
1603 
1604  return address;
1605 }
#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 objname,
List objargs,
bool  missing_ok 
)
static

Definition at line 1613 of file objectaddress.c.

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

Referenced by get_object_address().

1615 {
1616  ObjectAddress famaddr;
1617  ObjectAddress address;
1618  ListCell *cell;
1619  List *copy;
1620  char *typenames[2];
1621  Oid typeoids[2];
1622  int membernum;
1623  int i;
1624 
1625  /*
1626  * The last element of the objname list contains the strategy or procedure
1627  * number. We need to strip that out before getting the opclass/family
1628  * address. The rest can be used directly by get_object_address_opcf().
1629  */
1630  membernum = atoi(strVal(llast(objname)));
1631  copy = list_truncate(list_copy(objname), list_length(objname) - 1);
1632 
1633  /* no missing_ok support here */
1634  famaddr = get_object_address_opcf(OBJECT_OPFAMILY, copy, false);
1635 
1636  /* find out left/right type names and OIDs */
1637  i = 0;
1638  foreach(cell, objargs)
1639  {
1640  ObjectAddress typaddr;
1641 
1642  typenames[i] = strVal(lfirst(cell));
1643  typaddr = get_object_address_type(OBJECT_TYPE, cell, missing_ok);
1644  typeoids[i] = typaddr.objectId;
1645  if (++i >= 2)
1646  break;
1647  }
1648 
1649  switch (objtype)
1650  {
1651  case OBJECT_AMOP:
1652  {
1653  HeapTuple tp;
1654 
1656  InvalidOid);
1657 
1659  ObjectIdGetDatum(famaddr.objectId),
1660  ObjectIdGetDatum(typeoids[0]),
1661  ObjectIdGetDatum(typeoids[1]),
1662  Int16GetDatum(membernum));
1663  if (!HeapTupleIsValid(tp))
1664  {
1665  if (!missing_ok)
1666  ereport(ERROR,
1667  (errcode(ERRCODE_UNDEFINED_OBJECT),
1668  errmsg("operator %d (%s, %s) of %s does not exist",
1669  membernum, typenames[0], typenames[1],
1670  getObjectDescription(&famaddr))));
1671  }
1672  else
1673  {
1674  address.objectId = HeapTupleGetOid(tp);
1675  ReleaseSysCache(tp);
1676  }
1677  }
1678  break;
1679 
1680  case OBJECT_AMPROC:
1681  {
1682  HeapTuple tp;
1683 
1685  InvalidOid);
1686 
1688  ObjectIdGetDatum(famaddr.objectId),
1689  ObjectIdGetDatum(typeoids[0]),
1690  ObjectIdGetDatum(typeoids[1]),
1691  Int16GetDatum(membernum));
1692  if (!HeapTupleIsValid(tp))
1693  {
1694  if (!missing_ok)
1695  ereport(ERROR,
1696  (errcode(ERRCODE_UNDEFINED_OBJECT),
1697  errmsg("function %d (%s, %s) of %s does not exist",
1698  membernum, typenames[0], typenames[1],
1699  getObjectDescription(&famaddr))));
1700  }
1701  else
1702  {
1703  address.objectId = HeapTupleGetOid(tp);
1704  ReleaseSysCache(tp);
1705  }
1706  }
1707  break;
1708  default:
1709  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1710  }
1711 
1712  return address;
1713 }
#define SearchSysCache4(cacheId, key1, key2, key3, key4)
Definition: syscache.h:155
#define llast(l)
Definition: pg_list.h:126
#define Int16GetDatum(X)
Definition: postgres.h:459
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
static ObjectAddress get_object_address_type(ObjectType objtype, ListCell *typecell, bool missing_ok)
char * getObjectDescription(const ObjectAddress *object)
#define AccessMethodOperatorRelationId
Definition: pg_amop.h:54
static ObjectAddress get_object_address_opcf(ObjectType objtype, List *objname, bool missing_ok)
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1083
#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 objname,
List objargs,
Relation relp,
bool  missing_ok 
)
static

Definition at line 1789 of file objectaddress.c.

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

Referenced by get_object_address().

1791 {
1792  ObjectAddress address;
1793  Relation relation;
1794  char *pubname;
1795  Publication *pub;
1796 
1798 
1800  AccessShareLock, missing_ok);
1801  if (!relation)
1802  return address;
1803 
1804  /* fetch publication name from input list */
1805  pubname = strVal(linitial(objargs));
1806 
1807  /* Now look up the pg_publication tuple */
1808  pub = GetPublicationByName(pubname, missing_ok);
1809  if (!pub)
1810  {
1811  relation_close(relation, AccessShareLock);
1812  return address;
1813  }
1814 
1815  /* Find the publication relation mapping in syscache. */
1816  address.objectId =
1819  ObjectIdGetDatum(pub->oid));
1820  if (!OidIsValid(address.objectId))
1821  {
1822  if (!missing_ok)
1823  ereport(ERROR,
1824  (errcode(ERRCODE_UNDEFINED_OBJECT),
1825  errmsg("publication relation \"%s\" in publication \"%s\" does not exist",
1826  RelationGetRelationName(relation), pubname)));
1827  relation_close(relation, AccessShareLock);
1828  return address;
1829  }
1830 
1831  *relp = relation;
1832  return address;
1833 }
#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:2857
#define OidIsValid(objectId)
Definition: c.h:534
Publication * GetPublicationByName(const char *pubname, bool missing_ok)
#define GetSysCacheOid2(cacheId, key1, key2)
Definition: syscache.h:178
#define PublicationRelRelationId
#define linitial(l)
Definition: pg_list.h:110
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:433
#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
#define RelationGetRelid(relation)
Definition: rel.h:413
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 objname,
Relation relp,
bool  missing_ok 
)
static

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

1323 {
1324  ObjectAddress address;
1325  Relation relation = NULL;
1326  int nnames;
1327  const char *depname;
1328  List *relname;
1329  Oid reloid;
1330 
1331  /* Extract name of dependent object. */
1332  depname = strVal(llast(objname));
1333 
1334  /* Separate relation name from dependent object name. */
1335  nnames = list_length(objname);
1336  if (nnames < 2)
1337  ereport(ERROR,
1338  (errcode(ERRCODE_SYNTAX_ERROR),
1339  errmsg("must specify relation and object name")));
1340 
1341  /* Extract relation name and open relation. */
1342  relname = list_truncate(list_copy(objname), nnames - 1);
1343  relation = heap_openrv_extended(makeRangeVarFromNameList(relname),
1345  missing_ok);
1346 
1347  reloid = relation ? RelationGetRelid(relation) : InvalidOid;
1348 
1349  switch (objtype)
1350  {
1351  case OBJECT_RULE:
1352  address.classId = RewriteRelationId;
1353  address.objectId = relation ?
1354  get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
1355  address.objectSubId = 0;
1356  break;
1357  case OBJECT_TRIGGER:
1358  address.classId = TriggerRelationId;
1359  address.objectId = relation ?
1360  get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
1361  address.objectSubId = 0;
1362  break;
1363  case OBJECT_TABCONSTRAINT:
1364  address.classId = ConstraintRelationId;
1365  address.objectId = relation ?
1366  get_relation_constraint_oid(reloid, depname, missing_ok) :
1367  InvalidOid;
1368  address.objectSubId = 0;
1369  break;
1370  case OBJECT_POLICY:
1371  address.classId = PolicyRelationId;
1372  address.objectId = relation ?
1373  get_relation_policy_oid(reloid, depname, missing_ok) :
1374  InvalidOid;
1375  address.objectSubId = 0;
1376  break;
1377  default:
1378  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1379  }
1380 
1381  /* Avoid relcache leak when object not found. */
1382  if (!OidIsValid(address.objectId))
1383  {
1384  if (relation != NULL)
1385  heap_close(relation, AccessShareLock);
1386 
1387  relation = NULL; /* department of accident prevention */
1388  return address;
1389  }
1390 
1391  /* Done. */
1392  *relp = relation;
1393  return address;
1394 }
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:2857
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:534
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:226
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:413
ObjectAddress get_object_address_rv ( ObjectType  objtype,
RangeVar rel,
List objname,
List objargs,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)

Definition at line 1076 of file objectaddress.c.

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

Referenced by ExecAlterObjectDependsStmt().

1079 {
1080  if (rel)
1081  {
1082  objname = lcons(makeString(rel->relname), objname);
1083  if (rel->schemaname)
1084  objname = lcons(makeString(rel->schemaname), objname);
1085  if (rel->catalogname)
1086  objname = lcons(makeString(rel->catalogname), objname);
1087  }
1088 
1089  return get_object_address(objtype, objname, objargs,
1090  relp, lockmode, missing_ok);
1091 }
Value * makeString(char *str)
Definition: value.c:53
char * schemaname
Definition: primnodes.h:66
char * relname
Definition: primnodes.h:67
ObjectAddress get_object_address(ObjectType objtype, List *objname, List *objargs, Relation *relp, LOCKMODE lockmode, bool missing_ok)
List * lcons(void *datum, List *list)
Definition: list.c:259
char * catalogname
Definition: primnodes.h:65
static ObjectAddress get_object_address_type ( ObjectType  objtype,
ListCell typecell,
bool  missing_ok 
)
static

Definition at line 1533 of file objectaddress.c.

References ObjectAddress::classId, ereport, errcode(), errmsg(), ERROR, GETSTRUCT, HeapTupleIsValid, InvalidOid, lfirst, 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().

1534 {
1535  ObjectAddress address;
1536  TypeName *typename;
1537  Type tup;
1538 
1539  typename = (TypeName *) lfirst(typecell);
1540 
1541  address.classId = TypeRelationId;
1542  address.objectId = InvalidOid;
1543  address.objectSubId = 0;
1544 
1545  tup = LookupTypeName(NULL, typename, NULL, missing_ok);
1546  if (!HeapTupleIsValid(tup))
1547  {
1548  if (!missing_ok)
1549  ereport(ERROR,
1550  (errcode(ERRCODE_UNDEFINED_OBJECT),
1551  errmsg("type \"%s\" does not exist",
1552  TypeNameToString(typename))));
1553  return address;
1554  }
1555  address.objectId = typeTypeId(tup);
1556 
1557  if (objtype == OBJECT_DOMAIN)
1558  {
1559  if (((Form_pg_type) GETSTRUCT(tup))->typtype != TYPTYPE_DOMAIN)
1560  ereport(ERROR,
1561  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1562  errmsg("\"%s\" is not a domain",
1563  TypeNameToString(typename))));
1564  }
1565 
1566  ReleaseSysCache(tup);
1567 
1568  return address;
1569 }
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:710
#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:1083
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define NULL
Definition: c.h:226
#define lfirst(lc)
Definition: pg_list.h:106
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,
List qualname,
bool  missing_ok 
)
static

Definition at line 1098 of file objectaddress.c.

References _, AccessMethodRelationId, AuthIdRelationId, ObjectAddress::classId, DatabaseRelationId, elog, ereport, errcode(), errmsg(), 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(), gettext_noop, InvalidOid, LanguageRelationId, linitial, list_length(), name, NamespaceRelationId, NULL, 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().

1100 {
1101  const char *name;
1102  ObjectAddress address;
1103 
1104  /*
1105  * The types of names handled by this function are not permitted to be
1106  * schema-qualified or catalog-qualified.
1107  */
1108  if (list_length(qualname) != 1)
1109  {
1110  const char *msg;
1111 
1112  switch (objtype)
1113  {
1114  case OBJECT_ACCESS_METHOD:
1115  msg = gettext_noop("access method name cannot be qualified");
1116  break;
1117  case OBJECT_DATABASE:
1118  msg = gettext_noop("database name cannot be qualified");
1119  break;
1120  case OBJECT_EXTENSION:
1121  msg = gettext_noop("extension name cannot be qualified");
1122  break;
1123  case OBJECT_TABLESPACE:
1124  msg = gettext_noop("tablespace name cannot be qualified");
1125  break;
1126  case OBJECT_ROLE:
1127  msg = gettext_noop("role name cannot be qualified");
1128  break;
1129  case OBJECT_SCHEMA:
1130  msg = gettext_noop("schema name cannot be qualified");
1131  break;
1132  case OBJECT_LANGUAGE:
1133  msg = gettext_noop("language name cannot be qualified");
1134  break;
1135  case OBJECT_FDW:
1136  msg = gettext_noop("foreign-data wrapper name cannot be qualified");
1137  break;
1138  case OBJECT_FOREIGN_SERVER:
1139  msg = gettext_noop("server name cannot be qualified");
1140  break;
1141  case OBJECT_EVENT_TRIGGER:
1142  msg = gettext_noop("event trigger name cannot be qualified");
1143  break;
1144  case OBJECT_PUBLICATION:
1145  msg = gettext_noop("publication name cannot be qualified");
1146  break;
1147  case OBJECT_SUBSCRIPTION:
1148  msg = gettext_noop("subscription name cannot be qualified");
1149  break;
1150  default:
1151  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1152  msg = NULL; /* placate compiler */
1153  }
1154  ereport(ERROR,
1155  (errcode(ERRCODE_SYNTAX_ERROR),
1156  errmsg("%s", _(msg))));
1157  }
1158 
1159  /* Format is valid, extract the actual name. */
1160  name = strVal(linitial(qualname));
1161 
1162  /* Translate name to OID. */
1163  switch (objtype)
1164  {
1165  case OBJECT_ACCESS_METHOD:
1166  address.classId = AccessMethodRelationId;
1167  address.objectId = get_am_oid(name, missing_ok);
1168  address.objectSubId = 0;
1169  break;
1170  case OBJECT_DATABASE:
1171  address.classId = DatabaseRelationId;
1172  address.objectId = get_database_oid(name, missing_ok);
1173  address.objectSubId = 0;
1174  break;
1175  case OBJECT_EXTENSION:
1176  address.classId = ExtensionRelationId;
1177  address.objectId = get_extension_oid(name, missing_ok);
1178  address.objectSubId = 0;
1179  break;
1180  case OBJECT_TABLESPACE:
1181  address.classId = TableSpaceRelationId;
1182  address.objectId = get_tablespace_oid(name, missing_ok);
1183  address.objectSubId = 0;
1184  break;
1185  case OBJECT_ROLE:
1186  address.classId = AuthIdRelationId;
1187  address.objectId = get_role_oid(name, missing_ok);
1188  address.objectSubId = 0;
1189  break;
1190  case OBJECT_SCHEMA:
1191  address.classId = NamespaceRelationId;
1192  address.objectId = get_namespace_oid(name, missing_ok);
1193  address.objectSubId = 0;
1194  break;
1195  case OBJECT_LANGUAGE:
1196  address.classId = LanguageRelationId;
1197  address.objectId = get_language_oid(name, missing_ok);
1198  address.objectSubId = 0;
1199  break;
1200  case OBJECT_FDW:
1202  address.objectId = get_foreign_data_wrapper_oid(name, missing_ok);
1203  address.objectSubId = 0;
1204  break;
1205  case OBJECT_FOREIGN_SERVER:
1206  address.classId = ForeignServerRelationId;
1207  address.objectId = get_foreign_server_oid(name, missing_ok);
1208  address.objectSubId = 0;
1209  break;
1210  case OBJECT_EVENT_TRIGGER:
1211  address.classId = EventTriggerRelationId;
1212  address.objectId = get_event_trigger_oid(name, missing_ok);
1213  address.objectSubId = 0;
1214  break;
1215  case OBJECT_PUBLICATION:
1216  address.classId = PublicationRelationId;
1217  address.objectId = get_publication_oid(name, missing_ok);
1218  address.objectSubId = 0;
1219  break;
1220  case OBJECT_SUBSCRIPTION:
1221  address.classId = SubscriptionRelationId;
1222  address.objectId = get_subscription_oid(name, missing_ok);
1223  address.objectSubId = 0;
1224  break;
1225  default:
1226  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1227  /* placate compiler, which doesn't know elog won't return */
1228  address.classId = InvalidOid;
1229  address.objectId = InvalidOid;
1230  address.objectSubId = 0;
1231  }
1232 
1233  return address;
1234 }
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:2839
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 gettext_noop(x)
Definition: c.h:139
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
#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:5114
#define AuthIdRelationId
Definition: pg_authid.h:42
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition: foreign.c:659
#define linitial(l)
Definition: pg_list.h:110
#define ERROR
Definition: elog.h:43
#define SubscriptionRelationId
#define AccessMethodRelationId
Definition: pg_am.h:32
#define ereport(elevel, rest)
Definition: elog.h:122
#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 NULL
Definition: c.h:226
#define EventTriggerRelationId
static int list_length(const List *l)
Definition: pg_list.h:89
#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
int errmsg(const char *fmt,...)
Definition: elog.c:797
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
#define _(x)
Definition: elog.c:84
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition: foreign.c:680
static ObjectAddress get_object_address_usermapping ( List objname,
List objargs,
bool  missing_ok 
)
static

Definition at line 1719 of file objectaddress.c.

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

Referenced by get_object_address().

1720 {
1721  ObjectAddress address;
1722  Oid userid;
1723  char *username;
1724  char *servername;
1725  ForeignServer *server;
1726  HeapTuple tp;
1727 
1729 
1730  /* fetch string names from input lists, for error messages */
1731  username = strVal(linitial(objname));
1732  servername = strVal(linitial(objargs));
1733 
1734  /* look up pg_authid OID of mapped user; InvalidOid if PUBLIC */
1735  if (strcmp(username, "public") == 0)
1736  userid = InvalidOid;
1737  else
1738  {
1740  CStringGetDatum(username));
1741  if (!HeapTupleIsValid(tp))
1742  {
1743  if (!missing_ok)
1744  ereport(ERROR,
1745  (errcode(ERRCODE_UNDEFINED_OBJECT),
1746  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1747  username, servername)));
1748  return address;
1749  }
1750  userid = HeapTupleGetOid(tp);
1751  ReleaseSysCache(tp);
1752  }
1753 
1754  /* Now look up the pg_user_mapping tuple */
1755  server = GetForeignServerByName(servername, true);
1756  if (!server)
1757  {
1758  if (!missing_ok)
1759  ereport(ERROR,
1760  (errcode(ERRCODE_UNDEFINED_OBJECT),
1761  errmsg("server \"%s\" does not exist", servername)));
1762  return address;
1763  }
1765  ObjectIdGetDatum(userid),
1766  ObjectIdGetDatum(server->serverid));
1767  if (!HeapTupleIsValid(tp))
1768  {
1769  if (!missing_ok)
1770  ereport(ERROR,
1771  (errcode(ERRCODE_UNDEFINED_OBJECT),
1772  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1773  username, servername)));
1774  return address;
1775  }
1776 
1777  address.objectId = HeapTupleGetOid(tp);
1778 
1779  ReleaseSysCache(tp);
1780 
1781  return address;
1782 }
#define strVal(v)
Definition: value.h:54
int errcode(int sqlerrcode)
Definition: elog.c:575
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:149
#define linitial(l)
Definition: pg_list.h:110
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
#define CStringGetDatum(X)
Definition: postgres.h:586
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:1083
static char * username
Definition: initdb.c:129
#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:151
AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 2460 of file objectaddress.c.

References ObjectPropertyType::attnum_acl, and get_object_property_data().

Referenced by AlterObjectOwner_internal().

2461 {
2462  const ObjectPropertyType *prop = get_object_property_data(class_id);
2463 
2464  return prop->attnum_acl;
2465 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_acl
AttrNumber get_object_attnum_name ( Oid  class_id)

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

2437 {
2438  const ObjectPropertyType *prop = get_object_property_data(class_id);
2439 
2440  return prop->attnum_name;
2441 }
AttrNumber attnum_name
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber get_object_attnum_namespace ( Oid  class_id)

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

2445 {
2446  const ObjectPropertyType *prop = get_object_property_data(class_id);
2447 
2448  return prop->attnum_namespace;
2449 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_namespace
AttrNumber get_object_attnum_owner ( Oid  class_id)

Definition at line 2452 of file objectaddress.c.

References ObjectPropertyType::attnum_owner, and get_object_property_data().

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

2453 {
2454  const ObjectPropertyType *prop = get_object_property_data(class_id);
2455 
2456  return prop->attnum_owner;
2457 }
AttrNumber attnum_owner
static const ObjectPropertyType * get_object_property_data(Oid class_id)
int get_object_catcache_name ( Oid  class_id)

Definition at line 2428 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

2429 {
2430  const ObjectPropertyType *prop = get_object_property_data(class_id);
2431 
2432  return prop->name_catcache_id;
2433 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
int get_object_catcache_oid ( Oid  class_id)

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

2421 {
2422  const ObjectPropertyType *prop = get_object_property_data(class_id);
2423 
2424  return prop->oid_catcache_id;
2425 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
bool get_object_namensp_unique ( Oid  class_id)

Definition at line 2476 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::is_nsp_name_unique.

Referenced by EventTriggerSQLDropAddObject(), and pg_identify_object().

2477 {
2478  const ObjectPropertyType *prop = get_object_property_data(class_id);
2479 
2480  return prop->is_nsp_name_unique;
2481 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
Oid get_object_namespace ( const ObjectAddress address)

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

2354 {
2355  int cache;
2356  HeapTuple tuple;
2357  bool isnull;
2358  Oid oid;
2359  const ObjectPropertyType *property;
2360 
2361  /* If not owned by a namespace, just return InvalidOid. */
2362  property = get_object_property_data(address->classId);
2363  if (property->attnum_namespace == InvalidAttrNumber)
2364  return InvalidOid;
2365 
2366  /* Currently, we can only handle object types with system caches. */
2367  cache = property->oid_catcache_id;
2368  Assert(cache != -1);
2369 
2370  /* Fetch tuple from syscache and extract namespace attribute. */
2371  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2372  if (!HeapTupleIsValid(tuple))
2373  elog(ERROR, "cache lookup failed for cache %d oid %u",
2374  cache, address->objectId);
2375  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2376  tuple,
2377  property->attnum_namespace,
2378  &isnull));
2379  Assert(!isnull);
2380  ReleaseSysCache(tuple);
2381 
2382  return oid;
2383 }
#define DatumGetObjectId(X)
Definition: postgres.h:508
unsigned int Oid
Definition: postgres_ext.h:31
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:149
#define ObjectIdGetDatum(X)
Definition: postgres.h:515
#define ERROR
Definition: elog.h:43
static const ObjectPropertyType * get_object_property_data(Oid class_id)
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1083
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1245
#define InvalidOid
Definition: postgres_ext.h:36
#define HeapTupleIsValid(tuple)
Definition: htup.h:77
#define Assert(condition)
Definition: c.h:671
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 2412 of file objectaddress.c.

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by get_catalog_object_by_oid().

2413 {
2414  const ObjectPropertyType *prop = get_object_property_data(class_id);
2415 
2416  return prop->oid_index_oid;
2417 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
static const ObjectPropertyType * get_object_property_data ( Oid  class_id)
static

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

2506 {
2507  static const ObjectPropertyType *prop_last = NULL;
2508  int index;
2509 
2510  /*
2511  * A shortcut to speed up multiple consecutive lookups of a particular
2512  * object class.
2513  */
2514  if (prop_last && prop_last->class_oid == class_id)
2515  return prop_last;
2516 
2517  for (index = 0; index < lengthof(ObjectProperty); index++)
2518  {
2519  if (ObjectProperty[index].class_oid == class_id)
2520  {
2521  prop_last = &ObjectProperty[index];
2522  return &ObjectProperty[index];
2523  }
2524  }
2525 
2526  ereport(ERROR,
2527  (errmsg_internal("unrecognized class ID: %u", class_id)));
2528 
2529  return NULL; /* keep MSC compiler happy */
2530 }
#define lengthof(array)
Definition: c.h:558
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:226
static ObjectAddress get_relation_by_qualified_name ( ObjectType  objtype,
List objname,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)
static

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

1243 {
1244  Relation relation;
1245  ObjectAddress address;
1246 
1247  address.classId = RelationRelationId;
1248  address.objectId = InvalidOid;
1249  address.objectSubId = 0;
1250 
1252  lockmode, missing_ok);
1253  if (!relation)
1254  return address;
1255 
1256  switch (objtype)
1257  {
1258  case OBJECT_INDEX:
1259  if (relation->rd_rel->relkind != RELKIND_INDEX)
1260  ereport(ERROR,
1261  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1262  errmsg("\"%s\" is not an index",
1263  RelationGetRelationName(relation))));
1264  break;
1265  case OBJECT_SEQUENCE:
1266  if (relation->rd_rel->relkind != RELKIND_SEQUENCE)
1267  ereport(ERROR,
1268  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1269  errmsg("\"%s\" is not a sequence",
1270  RelationGetRelationName(relation))));
1271  break;
1272  case OBJECT_TABLE:
1273  if (relation->rd_rel->relkind != RELKIND_RELATION &&
1274  relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1275  ereport(ERROR,
1276  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1277  errmsg("\"%s\" is not a table",
1278  RelationGetRelationName(relation))));
1279  break;
1280  case OBJECT_VIEW:
1281  if (relation->rd_rel->relkind != RELKIND_VIEW)
1282  ereport(ERROR,
1283  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1284  errmsg("\"%s\" is not a view",
1285  RelationGetRelationName(relation))));
1286  break;
1287  case OBJECT_MATVIEW:
1288  if (relation->rd_rel->relkind != RELKIND_MATVIEW)
1289  ereport(ERROR,
1290  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1291  errmsg("\"%s\" is not a materialized view",
1292  RelationGetRelationName(relation))));
1293  break;
1294  case OBJECT_FOREIGN_TABLE:
1295  if (relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE)
1296  ereport(ERROR,
1297  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1298  errmsg("\"%s\" is not a foreign table",
1299  RelationGetRelationName(relation))));
1300  break;
1301  default:
1302  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1303  break;
1304  }
1305 
1306  /* Done. */
1307  address.objectId = RelationGetRelid(relation);
1308  *relp = relation;
1309 
1310  return address;
1311 }
#define RelationRelationId
Definition: pg_class.h:29
#define RELKIND_MATVIEW
Definition: pg_class.h:167
int errcode(int sqlerrcode)
Definition: elog.c:575
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:2857
Form_pg_class rd_rel
Definition: rel.h:113
#define ERROR
Definition: elog.h:43
#define RelationGetRelationName(relation)
Definition: rel.h:433
#define RELKIND_FOREIGN_TABLE
Definition: pg_class.h:166
#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:413
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 3893 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().

3894 {
3895  Relation constrRel;
3896  HeapTuple constrTup;
3897  Form_pg_constraint constrForm;
3898 
3900  constrTup = get_catalog_object_by_oid(constrRel, constroid);
3901  if (!HeapTupleIsValid(constrTup))
3902  elog(ERROR, "cache lookup failed for constraint %u", constroid);
3903 
3904  constrForm = (Form_pg_constraint) GETSTRUCT(constrTup);
3905 
3906  if (OidIsValid(constrForm->conrelid))
3907  appendStringInfoString(buffer, "table constraint");
3908  else if (OidIsValid(constrForm->contypid))
3909  appendStringInfoString(buffer, "domain constraint");
3910  else
3911  elog(ERROR, "invalid constraint %u", HeapTupleGetOid(constrTup));
3912 
3913  heap_close(constrRel, AccessShareLock);
3914 }
#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:534
#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 2587 of file objectaddress.c.

References _, AccessMethodOperatorOidIndexId, AccessMethodOperatorRelationId, AccessMethodProcedureOidIndexId, AccessMethodProcedureRelationId, AccessShareLock, AMOID, appendStringInfo(), AttrDefaultOidIndexId, AttrDefaultRelationId, BTEqualStrategyNumber, 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().

2588 {
2589  StringInfoData buffer;
2590 
2591  initStringInfo(&buffer);
2592 
2593  switch (getObjectClass(object))
2594  {
2595  case OCLASS_CLASS:
2596  getRelationDescription(&buffer, object->objectId);
2597  if (object->objectSubId != 0)
2598  appendStringInfo(&buffer, _(" column %s"),
2600  object->objectSubId));
2601  break;
2602 
2603  case OCLASS_PROC:
2604  appendStringInfo(&buffer, _("function %s"),
2605  format_procedure(object->objectId));
2606  break;
2607 
2608  case OCLASS_TYPE:
2609  appendStringInfo(&buffer, _("type %s"),
2610  format_type_be(object->objectId));
2611  break;
2612 
2613  case OCLASS_CAST:
2614  {
2615  Relation castDesc;
2616  ScanKeyData skey[1];
2617  SysScanDesc rcscan;
2618  HeapTuple tup;
2619  Form_pg_cast castForm;
2620 
2622 
2623  ScanKeyInit(&skey[0],
2625  BTEqualStrategyNumber, F_OIDEQ,
2626  ObjectIdGetDatum(object->objectId));
2627 
2628  rcscan = systable_beginscan(castDesc, CastOidIndexId, true,
2629  NULL, 1, skey);
2630 
2631  tup = systable_getnext(rcscan);
2632 
2633  if (!HeapTupleIsValid(tup))
2634  elog(ERROR, "could not find tuple for cast %u",
2635  object->objectId);
2636 
2637  castForm = (Form_pg_cast) GETSTRUCT(tup);
2638 
2639  appendStringInfo(&buffer, _("cast from %s to %s"),
2640  format_type_be(castForm->castsource),
2641  format_type_be(castForm->casttarget));
2642 
2643  systable_endscan(rcscan);
2644  heap_close(castDesc, AccessShareLock);
2645  break;
2646  }
2647 
2648  case OCLASS_COLLATION:
2649  {
2650  HeapTuple collTup;
2651  Form_pg_collation coll;
2652 
2653  collTup = SearchSysCache1(COLLOID,
2654  ObjectIdGetDatum(object->objectId));
2655  if (!HeapTupleIsValid(collTup))
2656  elog(ERROR, "cache lookup failed for collation %u",
2657  object->objectId);
2658  coll = (Form_pg_collation) GETSTRUCT(collTup);
2659  appendStringInfo(&buffer, _("collation %s"),
2660  NameStr(coll->collname));
2661  ReleaseSysCache(collTup);
2662  break;
2663  }
2664 
2665  case OCLASS_CONSTRAINT:
2666  {
2667  HeapTuple conTup;
2668  Form_pg_constraint con;
2669 
2670  conTup = SearchSysCache1(CONSTROID,
2671  ObjectIdGetDatum(object->objectId));
2672  if (!HeapTupleIsValid(conTup))
2673  elog(ERROR, "cache lookup failed for constraint %u",
2674  object->objectId);
2675  con = (Form_pg_constraint) GETSTRUCT(conTup);
2676 
2677  if (OidIsValid(con->conrelid))
2678  {
2679  StringInfoData rel;
2680 
2681  initStringInfo(&rel);
2682  getRelationDescription(&rel, con->conrelid);
2683  appendStringInfo(&buffer, _("constraint %s on %s"),
2684  NameStr(con->conname), rel.data);
2685  pfree(rel.data);
2686  }
2687  else
2688  {
2689  appendStringInfo(&buffer, _("constraint %s"),
2690  NameStr(con->conname));
2691  }
2692 
2693  ReleaseSysCache(conTup);
2694  break;
2695  }
2696 
2697  case OCLASS_CONVERSION:
2698  {
2699  HeapTuple conTup;
2700 
2701  conTup = SearchSysCache1(CONVOID,
2702  ObjectIdGetDatum(object->objectId));
2703  if (!HeapTupleIsValid(conTup))
2704  elog(ERROR, "cache lookup failed for conversion %u",
2705  object->objectId);
2706  appendStringInfo(&buffer, _("conversion %s"),
2707  NameStr(((Form_pg_conversion) GETSTRUCT(conTup))->conname));
2708  ReleaseSysCache(conTup);
2709  break;
2710  }
2711 
2712  case OCLASS_DEFAULT:
2713  {
2714  Relation attrdefDesc;
2715  ScanKeyData skey[1];
2716  SysScanDesc adscan;
2717  HeapTuple tup;
2718  Form_pg_attrdef attrdef;
2719  ObjectAddress colobject;
2720 
2722 
2723  ScanKeyInit(&skey[0],
2725  BTEqualStrategyNumber, F_OIDEQ,
2726  ObjectIdGetDatum(object->objectId));
2727 
2728  adscan = systable_beginscan(attrdefDesc, AttrDefaultOidIndexId,
2729  true, NULL, 1, skey);
2730 
2731  tup = systable_getnext(adscan);
2732 
2733  if (!HeapTupleIsValid(tup))
2734  elog(ERROR, "could not find tuple for attrdef %u",
2735  object->objectId);
2736 
2737  attrdef = (Form_pg_attrdef) GETSTRUCT(tup);
2738 
2739  colobject.classId = RelationRelationId;
2740  colobject.objectId = attrdef->adrelid;
2741  colobject.objectSubId = attrdef->adnum;
2742 
2743  appendStringInfo(&buffer, _("default for %s"),
2744  getObjectDescription(&colobject));
2745 
2746  systable_endscan(adscan);
2747  heap_close(attrdefDesc, AccessShareLock);
2748  break;
2749  }
2750 
2751  case OCLASS_LANGUAGE:
2752  appendStringInfo(&buffer, _("language %s"),
2753  get_language_name(object->objectId, false));
2754  break;
2755 
2756  case OCLASS_LARGEOBJECT:
2757  appendStringInfo(&buffer, _("large object %u"),
2758  object->objectId);
2759  break;
2760 
2761  case OCLASS_OPERATOR:
2762  appendStringInfo(&buffer, _("operator %s"),
2763  format_operator(object->objectId));
2764  break;
2765 
2766  case OCLASS_OPCLASS:
2767  {
2768  HeapTuple opcTup;
2769  Form_pg_opclass opcForm;
2770  HeapTuple amTup;
2771  Form_pg_am amForm;
2772  char *nspname;
2773 
2774  opcTup = SearchSysCache1(CLAOID,
2775  ObjectIdGetDatum(object->objectId));
2776  if (!HeapTupleIsValid(opcTup))
2777  elog(ERROR, "cache lookup failed for opclass %u",
2778  object->objectId);
2779  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
2780 
2781  amTup = SearchSysCache1(AMOID,
2782  ObjectIdGetDatum(opcForm->opcmethod));
2783  if (!HeapTupleIsValid(amTup))
2784  elog(ERROR, "cache lookup failed for access method %u",
2785  opcForm->opcmethod);
2786  amForm = (Form_pg_am) GETSTRUCT(amTup);
2787 
2788  /* Qualify the name if not visible in search path */
2789  if (OpclassIsVisible(object->objectId))
2790  nspname = NULL;
2791  else
2792  nspname = get_namespace_name(opcForm->opcnamespace);
2793 
2794  appendStringInfo(&buffer, _("operator class %s for access method %s"),
2796  NameStr(opcForm->opcname)),
2797  NameStr(amForm->amname));
2798 
2799  ReleaseSysCache(amTup);
2800  ReleaseSysCache(opcTup);
2801  break;
2802  }
2803 
2804  case OCLASS_OPFAMILY:
2805  getOpFamilyDescription(&buffer, object->objectId);
2806  break;
2807 
2808  case OCLASS_AMOP:
2809  {
2810  Relation amopDesc;
2811  HeapTuple tup;
2812  ScanKeyData skey[1];
2813  SysScanDesc amscan;
2814  Form_pg_amop amopForm;
2815  StringInfoData opfam;
2816 
2818  AccessShareLock);
2819 
2820  ScanKeyInit(&skey[0],
2822  BTEqualStrategyNumber, F_OIDEQ,
2823  ObjectIdGetDatum(object->objectId));
2824 
2825  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
2826  NULL, 1, skey);
2827 
2828  tup = systable_getnext(amscan);
2829 
2830  if (!HeapTupleIsValid(tup))
2831  elog(ERROR, "could not find tuple for amop entry %u",
2832  object->objectId);
2833 
2834  amopForm = (Form_pg_amop) GETSTRUCT(tup);
2835 
2836  initStringInfo(&opfam);
2837  getOpFamilyDescription(&opfam, amopForm->amopfamily);
2838 
2839  /*------
2840  translator: %d is the operator strategy (a number), the
2841  first two %s's are data type names, the third %s is the
2842  description of the operator family, and the last %s is the
2843  textual form of the operator with arguments. */
2844  appendStringInfo(&buffer, _("operator %d (%s, %s) of %s: %s"),
2845  amopForm->amopstrategy,
2846  format_type_be(amopForm->amoplefttype),
2847  format_type_be(amopForm->amoprighttype),
2848  opfam.data,
2849  format_operator(amopForm->amopopr));
2850 
2851  pfree(opfam.data);
2852 
2853  systable_endscan(amscan);
2854  heap_close(amopDesc, AccessShareLock);
2855  break;
2856  }
2857 
2858  case OCLASS_AMPROC:
2859  {
2860  Relation amprocDesc;
2861  ScanKeyData skey[1];
2862  SysScanDesc amscan;
2863  HeapTuple tup;
2864  Form_pg_amproc amprocForm;
2865  StringInfoData opfam;
2866 
2868  AccessShareLock);
2869 
2870  ScanKeyInit(&skey[0],
2872  BTEqualStrategyNumber, F_OIDEQ,
2873  ObjectIdGetDatum(object->objectId));
2874 
2875  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
2876  NULL, 1, skey);
2877 
2878  tup = systable_getnext(amscan);
2879 
2880  if (!HeapTupleIsValid(tup))
2881  elog(ERROR, "could not find tuple for amproc entry %u",
2882  object->objectId);
2883 
2884  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
2885 
2886  initStringInfo(&opfam);
2887  getOpFamilyDescription(&opfam, amprocForm->amprocfamily);
2888 
2889  /*------
2890  translator: %d is the function number, the first two %s's
2891  are data type names, the third %s is the description of the
2892  operator family, and the last %s is the textual form of the
2893  function with arguments. */
2894  appendStringInfo(&buffer, _("function %d (%s, %s) of %s: %s"),
2895  amprocForm->amprocnum,
2896  format_type_be(amprocForm->amproclefttype),
2897  format_type_be(amprocForm->amprocrighttype),
2898  opfam.data,
2899  format_procedure(amprocForm->amproc));
2900 
2901  pfree(opfam.data);
2902 
2903  systable_endscan(amscan);
2904  heap_close(amprocDesc, AccessShareLock);
2905  break;
2906  }
2907 
2908  case OCLASS_REWRITE:
2909  {
2910  Relation ruleDesc;
2911  ScanKeyData skey[1];
2912  SysScanDesc rcscan;
2913  HeapTuple tup;
2915 
2917 
2918  ScanKeyInit(&skey[0],
2920  BTEqualStrategyNumber, F_OIDEQ,
2921  ObjectIdGetDatum(object->objectId));
2922 
2923  rcscan = systable_beginscan(ruleDesc, RewriteOidIndexId, true,
2924  NULL, 1, skey);
2925 
2926  tup = systable_getnext(rcscan);
2927 
2928  if (!HeapTupleIsValid(tup))
2929  elog(ERROR, "could not find tuple for rule %u",
2930  object->objectId);
2931 
2932  rule = (Form_pg_rewrite) GETSTRUCT(tup);
2933 
2934  appendStringInfo(&buffer, _("rule %s on "),
2935  NameStr(rule->rulename));
2936  getRelationDescription(&buffer, rule->ev_class);
2937 
2938  systable_endscan(rcscan);
2939  heap_close(ruleDesc, AccessShareLock);
2940  break;
2941  }
2942 
2943  case OCLASS_TRANSFORM:
2944  {
2945  HeapTuple trfTup;
2946  Form_pg_transform trfForm;
2947 
2948  trfTup = SearchSysCache1(TRFOID,
2949  ObjectIdGetDatum(object->objectId));
2950  if (!HeapTupleIsValid(trfTup))
2951  elog(ERROR, "could not find tuple for transform %u",
2952  object->objectId);
2953 
2954  trfForm = (Form_pg_transform) GETSTRUCT(trfTup);
2955 
2956  appendStringInfo(&buffer, _("transform for %s language %s"),
2957  format_type_be(trfForm->trftype),
2958  get_language_name(trfForm->trflang, false));
2959 
2960  ReleaseSysCache(trfTup);
2961  break;
2962  }
2963 
2964  case OCLASS_TRIGGER:
2965  {
2966  Relation trigDesc;
2967  ScanKeyData skey[1];
2968  SysScanDesc tgscan;
2969  HeapTuple tup;
2970  Form_pg_trigger trig;
2971 
2973 
2974  ScanKeyInit(&skey[0],
2976  BTEqualStrategyNumber, F_OIDEQ,
2977  ObjectIdGetDatum(object->objectId));
2978 
2979  tgscan = systable_beginscan(trigDesc, TriggerOidIndexId, true,
2980  NULL, 1, skey);
2981 
2982  tup = systable_getnext(tgscan);
2983 
2984  if (!HeapTupleIsValid(tup))
2985  elog(ERROR, "could not find tuple for trigger %u",
2986  object->objectId);
2987 
2988  trig = (Form_pg_trigger) GETSTRUCT(tup);
2989 
2990  appendStringInfo(&buffer, _("trigger %s on "),
2991  NameStr(trig->tgname));
2992  getRelationDescription(&buffer, trig->tgrelid);
2993 
2994  systable_endscan(tgscan);
2995  heap_close(trigDesc, AccessShareLock);
2996  break;
2997  }
2998 
2999  case OCLASS_SCHEMA:
3000  {
3001  char *nspname;
3002 
3003  nspname = get_namespace_name(object->objectId);
3004  if (!nspname)
3005  elog(ERROR, "cache lookup failed for namespace %u",
3006  object->objectId);
3007  appendStringInfo(&buffer, _("schema %s"), nspname);
3008  break;
3009  }
3010 
3011  case OCLASS_TSPARSER:
3012  {
3013  HeapTuple tup;
3014 
3016  ObjectIdGetDatum(object->objectId));
3017  if (!HeapTupleIsValid(tup))
3018  elog(ERROR, "cache lookup failed for text search parser %u",
3019  object->objectId);
3020  appendStringInfo(&buffer, _("text search parser %s"),
3021  NameStr(((Form_pg_ts_parser) GETSTRUCT(tup))->prsname));
3022  ReleaseSysCache(tup);
3023  break;
3024  }
3025 
3026  case OCLASS_TSDICT:
3027  {
3028  HeapTuple tup;
3029 
3030  tup = SearchSysCache1(TSDICTOID,
3031  ObjectIdGetDatum(object->objectId));
3032  if (!HeapTupleIsValid(tup))
3033  elog(ERROR, "cache lookup failed for text search dictionary %u",
3034  object->objectId);
3035  appendStringInfo(&buffer, _("text search dictionary %s"),
3036  NameStr(((Form_pg_ts_dict) GETSTRUCT(tup))->dictname));
3037  ReleaseSysCache(tup);
3038  break;
3039  }
3040 
3041  case OCLASS_TSTEMPLATE:
3042  {
3043  HeapTuple tup;
3044 
3046  ObjectIdGetDatum(object->objectId));
3047  if (!HeapTupleIsValid(tup))
3048  elog(ERROR, "cache lookup failed for text search template %u",
3049  object->objectId);
3050  appendStringInfo(&buffer, _("text search template %s"),
3051  NameStr(((Form_pg_ts_template) GETSTRUCT(tup))->tmplname));
3052  ReleaseSysCache(tup);
3053  break;
3054  }
3055 
3056  case OCLASS_TSCONFIG:
3057  {
3058  HeapTuple tup;
3059 
3061  ObjectIdGetDatum(object->objectId));
3062  if (!HeapTupleIsValid(tup))
3063  elog(ERROR, "cache lookup failed for text search configuration %u",
3064  object->objectId);
3065  appendStringInfo(&buffer, _("text search configuration %s"),
3066  NameStr(((Form_pg_ts_config) GETSTRUCT(tup))->cfgname));
3067  ReleaseSysCache(tup);
3068  break;
3069  }
3070 
3071  case OCLASS_ROLE:
3072  {
3073  appendStringInfo(&buffer, _("role %s"),
3074  GetUserNameFromId(object->objectId, false));
3075  break;
3076  }
3077 
3078  case OCLASS_DATABASE:
3079  {
3080  char *datname;
3081 
3082  datname = get_database_name(object->objectId);
3083  if (!datname)
3084  elog(ERROR, "cache lookup failed for database %u",
3085  object->objectId);
3086  appendStringInfo(&buffer, _("database %s"), datname);
3087  break;
3088  }
3089 
3090  case OCLASS_TBLSPACE:
3091  {
3092  char *tblspace;
3093 
3094  tblspace = get_tablespace_name(object->objectId);
3095  if (!tblspace)
3096  elog(ERROR, "cache lookup failed for tablespace %u",
3097  object->objectId);
3098  appendStringInfo(&buffer, _("tablespace %s"), tblspace);
3099  break;
3100  }
3101 
3102  case OCLASS_FDW:
3103  {
3104  ForeignDataWrapper *fdw;
3105 
3106  fdw = GetForeignDataWrapper(object->objectId);
3107  appendStringInfo(&buffer, _("foreign-data wrapper %s"), fdw->fdwname);
3108  break;
3109  }
3110 
3111  case OCLASS_FOREIGN_SERVER:
3112  {
3113  ForeignServer *srv;
3114 
3115  srv = GetForeignServer(object->objectId);
3116  appendStringInfo(&buffer, _("server %s"), srv->servername);
3117  break;
3118  }
3119 
3120  case OCLASS_USER_MAPPING:
3121  {
3122  HeapTuple tup;
3123  Oid useid;
3124  char *usename;
3125  Form_pg_user_mapping umform;
3126  ForeignServer *srv;
3127 
3129  ObjectIdGetDatum(object->objectId));
3130  if (!HeapTupleIsValid(tup))
3131  elog(ERROR, "cache lookup failed for user mapping %u",
3132  object->objectId);
3133  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
3134  useid = umform->umuser;
3135  srv = GetForeignServer(umform->umserver);
3136 
3137  ReleaseSysCache(tup);
3138 
3139  if (OidIsValid(useid))
3140  usename = GetUserNameFromId(useid, false);
3141  else
3142  usename = "public";
3143 
3144  appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
3145  srv->servername);
3146  break;
3147  }
3148 
3149  case OCLASS_DEFACL:
3150  {
3151  Relation defaclrel;
3152  ScanKeyData skey[1];
3153  SysScanDesc rcscan;
3154  HeapTuple tup;
3155  Form_pg_default_acl defacl;
3156 
3158 
3159  ScanKeyInit(&skey[0],
3161  BTEqualStrategyNumber, F_OIDEQ,
3162  ObjectIdGetDatum(object->objectId));
3163 
3164  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
3165  true, NULL, 1, skey);
3166 
3167  tup = systable_getnext(rcscan);
3168 
3169  if (!HeapTupleIsValid(tup))
3170  elog(ERROR, "could not find tuple for default ACL %u",
3171  object->objectId);
3172 
3173  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
3174 
3175  switch (defacl->defaclobjtype)
3176  {
3177  case DEFACLOBJ_RELATION:
3178  appendStringInfo(&buffer,
3179  _("default privileges on new relations belonging to role %s"),
3180  GetUserNameFromId(defacl->defaclrole, false));
3181  break;
3182  case DEFACLOBJ_SEQUENCE:
3183  appendStringInfo(&buffer,
3184  _("default privileges on new sequences belonging to role %s"),
3185  GetUserNameFromId(defacl->defaclrole, false));
3186  break;
3187  case DEFACLOBJ_FUNCTION:
3188  appendStringInfo(&buffer,
3189  _("default privileges on new functions belonging to role %s"),
3190  GetUserNameFromId(defacl->defaclrole, false));
3191  break;
3192  case DEFACLOBJ_TYPE:
3193  appendStringInfo(&buffer,
3194  _("default privileges on new types belonging to role %s"),
3195  GetUserNameFromId(defacl->defaclrole, false));
3196  break;
3197  default:
3198  /* shouldn't get here */
3199  appendStringInfo(&buffer,
3200  _("default privileges belonging to role %s"),
3201  GetUserNameFromId(defacl->defaclrole, false));
3202  break;
3203  }
3204 
3205  if (OidIsValid(defacl->defaclnamespace))
3206  {
3207  appendStringInfo(&buffer,
3208  _(" in schema %s"),
3209  get_namespace_name(defacl->defaclnamespace));
3210  }
3211 
3212  systable_endscan(rcscan);
3213  heap_close(defaclrel, AccessShareLock);
3214  break;
3215  }
3216 
3217  case OCLASS_EXTENSION:
3218  {
3219  char *extname;
3220 
3221  extname = get_extension_name(object->objectId);
3222  if (!extname)
3223  elog(ERROR, "cache lookup failed for extension %u",
3224  object->objectId);
3225  appendStringInfo(&buffer, _("extension %s"), extname);
3226  break;
3227  }
3228 
3229  case OCLASS_EVENT_TRIGGER:
3230  {
3231  HeapTuple tup;
3232 
3234  ObjectIdGetDatum(object->objectId));
3235  if (!HeapTupleIsValid(tup))
3236  elog(ERROR, "cache lookup failed for event trigger %u",
3237  object->objectId);
3238  appendStringInfo(&buffer, _("event trigger %s"),
3239  NameStr(((Form_pg_event_trigger) GETSTRUCT(tup))->evtname));
3240  ReleaseSysCache(tup);
3241  break;
3242  }
3243 
3244  case OCLASS_POLICY:
3245  {
3246  Relation policy_rel;
3247  ScanKeyData skey[1];
3248  SysScanDesc sscan;
3249  HeapTuple tuple;
3250  Form_pg_policy form_policy;
3251 
3253 
3254  ScanKeyInit(&skey[0],
3256  BTEqualStrategyNumber, F_OIDEQ,
3257  ObjectIdGetDatum(object->objectId));
3258 
3259  sscan = systable_beginscan(policy_rel, PolicyOidIndexId,
3260  true, NULL, 1, skey);
3261 
3262  tuple = systable_getnext(sscan);
3263 
3264  if (!HeapTupleIsValid(tuple))
3265  elog(ERROR, "cache lookup failed for policy %u",
3266  object->objectId);
3267 
3268  form_policy = (Form_pg_policy) GETSTRUCT(tuple);
3269 
3270  appendStringInfo(&buffer, _("policy %s on "),
3271  NameStr(form_policy->polname));
3272  getRelationDescription(&buffer, form_policy->polrelid);
3273 
3274  systable_endscan(sscan);
3275  heap_close(policy_rel, AccessShareLock);
3276  break;
3277  }
3278 
3279  case OCLASS_AM:
3280  {
3281  HeapTuple tup;
3282 
3283  tup = SearchSysCache1(AMOID,
3284  ObjectIdGetDatum(object->objectId));
3285  if (!HeapTupleIsValid(tup))
3286  elog(ERROR, "cache lookup failed for access method %u",
3287  object->objectId);
3288  appendStringInfo(&buffer, _("access method %s"),
3289  NameStr(((Form_pg_am) GETSTRUCT(tup))->amname));
3290  ReleaseSysCache(tup);
3291  break;
3292  }
3293 
3294  case OCLASS_PUBLICATION:
3295  {
3296  appendStringInfo(&buffer, _("publication %s"),
3297  get_publication_name(object->objectId));
3298  break;
3299  }
3300 
3302  {
3303  HeapTuple tup;
3304  char *pubname;
3305  Form_pg_publication_rel prform;
3306 
3308  ObjectIdGetDatum(object->objectId));
3309  if (!HeapTupleIsValid(tup))
3310  elog(ERROR, "cache lookup failed for publication table %u",
3311  object->objectId);
3312 
3313  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
3314  pubname = get_publication_name(prform->prpubid);
3315 
3316  appendStringInfo(&buffer, _("publication table %s in publication %s"),
3317  get_rel_name(prform->prrelid), pubname);
3318  ReleaseSysCache(tup);
3319  break;
3320  }
3321 
3322  case OCLASS_SUBSCRIPTION:
3323  {
3324  appendStringInfo(&buffer, _("subscription %s"),
3325  get_subscription_name(object->objectId));
3326  break;
3327  }
3328 
3329  default:
3330  appendStringInfo(&buffer, "unrecognized object %u %u %d",
3331  object->classId,
3332  object->objectId,
3333  object->objectSubId);
3334  break;
3335  }
3336 
3337  return buffer.data;
3338 }
#define RewriteOidIndexId
Definition: indexing.h:214
#define TriggerOidIndexId
Definition: indexing.h:244
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:493
#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:320
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:300
#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:2312
#define OidIsValid(objectId)
Definition: c.h:534
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:322
#define DefaultAclRelationId
#define SearchSysCache1(cacheId, key1)
Definition: syscache.h:149
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:410
ForeignDataWrapper * GetForeignDataWrapper(Oid fdwid)
Definition: foreign.c:35
void pfree(void *pointer)
Definition: mcxt.c:992
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:515
#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:10054
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:1083
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:226
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:690
#define DEFACLOBJ_FUNCTION
#define TriggerRelationId
Definition: pg_trigger.h:34
#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:47
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:495
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 3344 of file objectaddress.c.

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

3345 {
3346  ObjectAddress address;
3347 
3348  address.classId = classid;
3349  address.objectId = objid;
3350  address.objectSubId = 0;
3351 
3352  return getObjectDescription(&address);
3353 }
char * getObjectDescription(const ObjectAddress *object)
char* getObjectIdentityParts ( const ObjectAddress object,
List **  objname,
List **  objargs 
)

Definition at line 3960 of file objectaddress.c.

References _, AccessMethodOperatorOidIndexId, AccessMethodOperatorRelationId, AccessMethodProcedureOidIndexId, AccessMethodProcedureRelationId, AccessShareLock, AMOID, appendStringInfo(), appendStringInfoString(), Assert, AttrDefaultOidIndexId, AttrDefaultRelationId, BTEqualStrategyNumber, 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_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, 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().

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