PostgreSQL Source Code  git master
objectaddress.c File Reference
#include "postgres.h"
#include "access/genam.h"
#include "access/htup_details.h"
#include "access/relation.h"
#include "access/sysattr.h"
#include "access/table.h"
#include "catalog/catalog.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_collation.h"
#include "catalog/pg_constraint.h"
#include "catalog/pg_conversion.h"
#include "catalog/pg_database.h"
#include "catalog/pg_default_acl.h"
#include "catalog/pg_enum.h"
#include "catalog/pg_event_trigger.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_operator.h"
#include "catalog/pg_opfamily.h"
#include "catalog/pg_parameter_acl.h"
#include "catalog/pg_policy.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_publication.h"
#include "catalog/pg_publication_namespace.h"
#include "catalog/pg_publication_rel.h"
#include "catalog/pg_rewrite.h"
#include "catalog/pg_statistic_ext.h"
#include "catalog/pg_subscription.h"
#include "catalog/pg_tablespace.h"
#include "catalog/pg_transform.h"
#include "catalog/pg_trigger.h"
#include "catalog/pg_ts_config.h"
#include "catalog/pg_ts_dict.h"
#include "catalog/pg_ts_parser.h"
#include "catalog/pg_ts_template.h"
#include "catalog/pg_type.h"
#include "catalog/pg_user_mapping.h"
#include "commands/dbcommands.h"
#include "commands/defrem.h"
#include "commands/event_trigger.h"
#include "commands/extension.h"
#include "commands/policy.h"
#include "commands/proclang.h"
#include "commands/tablespace.h"
#include "commands/trigger.h"
#include "foreign/foreign.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "parser/parse_func.h"
#include "parser/parse_oper.h"
#include "parser/parse_type.h"
#include "rewrite/rewriteSupport.h"
#include "storage/large_object.h"
#include "storage/lmgr.h"
#include "storage/sinval.h"
#include "utils/acl.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 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, String *strval, bool missing_ok)
 
static ObjectAddress get_relation_by_qualified_name (ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static ObjectAddress get_object_address_relobject (ObjectType objtype, List *object, Relation *relp, bool missing_ok)
 
static ObjectAddress get_object_address_attribute (ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static ObjectAddress get_object_address_attrdef (ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static ObjectAddress get_object_address_type (ObjectType objtype, TypeName *typename, bool missing_ok)
 
static ObjectAddress get_object_address_opcf (ObjectType objtype, List *object, bool missing_ok)
 
static ObjectAddress get_object_address_opf_member (ObjectType objtype, List *object, bool missing_ok)
 
static ObjectAddress get_object_address_usermapping (List *object, bool missing_ok)
 
static ObjectAddress get_object_address_publication_rel (List *object, Relation *relp, bool missing_ok)
 
static ObjectAddress get_object_address_publication_schema (List *object, bool missing_ok)
 
static ObjectAddress get_object_address_defacl (List *object, bool missing_ok)
 
static const ObjectPropertyTypeget_object_property_data (Oid class_id)
 
static void getRelationDescription (StringInfo buffer, Oid relid, bool missing_ok)
 
static void getOpFamilyDescription (StringInfo buffer, Oid opfid, bool missing_ok)
 
static void getRelationTypeDescription (StringInfo buffer, Oid relid, int32 objectSubId, bool missing_ok)
 
static void getProcedureTypeDescription (StringInfo buffer, Oid procid, bool missing_ok)
 
static void getConstraintTypeDescription (StringInfo buffer, Oid constroid, bool missing_ok)
 
static void getOpFamilyIdentity (StringInfo buffer, Oid opfid, List **object, bool missing_ok)
 
static void getRelationIdentity (StringInfo buffer, Oid relid, List **object, bool missing_ok)
 
ObjectAddress get_object_address (ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
ObjectAddress get_object_address_rv (ObjectType objtype, RangeVar *rel, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static Listtextarray_to_strvaluelist (ArrayType *arr)
 
Datum pg_get_object_address (PG_FUNCTION_ARGS)
 
void check_object_ownership (Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
 
Oid get_object_namespace (const ObjectAddress *address)
 
int read_objtype_from_string (const char *objtype)
 
const char * get_object_class_descr (Oid class_id)
 
Oid get_object_oid_index (Oid class_id)
 
int get_object_catcache_oid (Oid class_id)
 
int get_object_catcache_name (Oid class_id)
 
AttrNumber get_object_attnum_oid (Oid class_id)
 
AttrNumber get_object_attnum_name (Oid class_id)
 
AttrNumber get_object_attnum_namespace (Oid class_id)
 
AttrNumber get_object_attnum_owner (Oid class_id)
 
AttrNumber get_object_attnum_acl (Oid class_id)
 
ObjectType get_object_type (Oid class_id, Oid object_id)
 
bool get_object_namensp_unique (Oid class_id)
 
bool is_objectclass_supported (Oid class_id)
 
HeapTuple get_catalog_object_by_oid (Relation catalog, AttrNumber oidcol, Oid objectId)
 
static bool getPublicationSchemaInfo (const ObjectAddress *object, bool missing_ok, char **pubname, char **nspname)
 
char * getObjectDescription (const ObjectAddress *object, bool missing_ok)
 
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, bool missing_ok)
 
char * getObjectIdentity (const ObjectAddress *object, bool missing_ok)
 
char * getObjectIdentityParts (const ObjectAddress *object, List **objname, List **objargs, bool missing_ok)
 
ArrayTypestrlist_to_textarray (List *list)
 
ObjectType get_relkind_objtype (char relkind)
 

Variables

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

Function Documentation

◆ check_object_ownership()

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

Definition at line 2405 of file objectaddress.c.

2407 {
2408  switch (objtype)
2409  {
2410  case OBJECT_INDEX:
2411  case OBJECT_SEQUENCE:
2412  case OBJECT_TABLE:
2413  case OBJECT_VIEW:
2414  case OBJECT_MATVIEW:
2415  case OBJECT_FOREIGN_TABLE:
2416  case OBJECT_COLUMN:
2417  case OBJECT_RULE:
2418  case OBJECT_TRIGGER:
2419  case OBJECT_POLICY:
2420  case OBJECT_TABCONSTRAINT:
2421  if (!pg_class_ownercheck(RelationGetRelid(relation), roleid))
2423  RelationGetRelationName(relation));
2424  break;
2425  case OBJECT_DATABASE:
2426  if (!pg_database_ownercheck(address.objectId, roleid))
2428  strVal(object));
2429  break;
2430  case OBJECT_TYPE:
2431  case OBJECT_DOMAIN:
2432  case OBJECT_ATTRIBUTE:
2433  if (!pg_type_ownercheck(address.objectId, roleid))
2435  break;
2436  case OBJECT_DOMCONSTRAINT:
2437  {
2438  HeapTuple tuple;
2439  Oid contypid;
2440 
2441  tuple = SearchSysCache1(CONSTROID,
2442  ObjectIdGetDatum(address.objectId));
2443  if (!HeapTupleIsValid(tuple))
2444  elog(ERROR, "constraint with OID %u does not exist",
2445  address.objectId);
2446 
2447  contypid = ((Form_pg_constraint) GETSTRUCT(tuple))->contypid;
2448 
2449  ReleaseSysCache(tuple);
2450 
2451  /*
2452  * Fallback to type ownership check in this case as this is
2453  * what domain constraints rely on.
2454  */
2455  if (!pg_type_ownercheck(contypid, roleid))
2457  }
2458  break;
2459  case OBJECT_AGGREGATE:
2460  case OBJECT_FUNCTION:
2461  case OBJECT_PROCEDURE:
2462  case OBJECT_ROUTINE:
2463  if (!pg_proc_ownercheck(address.objectId, roleid))
2465  NameListToString((castNode(ObjectWithArgs, object))->objname));
2466  break;
2467  case OBJECT_OPERATOR:
2468  if (!pg_oper_ownercheck(address.objectId, roleid))
2470  NameListToString((castNode(ObjectWithArgs, object))->objname));
2471  break;
2472  case OBJECT_SCHEMA:
2473  if (!pg_namespace_ownercheck(address.objectId, roleid))
2475  strVal(object));
2476  break;
2477  case OBJECT_COLLATION:
2478  if (!pg_collation_ownercheck(address.objectId, roleid))
2480  NameListToString(castNode(List, object)));
2481  break;
2482  case OBJECT_CONVERSION:
2483  if (!pg_conversion_ownercheck(address.objectId, roleid))
2485  NameListToString(castNode(List, object)));
2486  break;
2487  case OBJECT_EXTENSION:
2488  if (!pg_extension_ownercheck(address.objectId, roleid))
2490  strVal(object));
2491  break;
2492  case OBJECT_FDW:
2493  if (!pg_foreign_data_wrapper_ownercheck(address.objectId, roleid))
2495  strVal(object));
2496  break;
2497  case OBJECT_FOREIGN_SERVER:
2498  if (!pg_foreign_server_ownercheck(address.objectId, roleid))
2500  strVal(object));
2501  break;
2502  case OBJECT_EVENT_TRIGGER:
2503  if (!pg_event_trigger_ownercheck(address.objectId, roleid))
2505  strVal(object));
2506  break;
2507  case OBJECT_LANGUAGE:
2508  if (!pg_language_ownercheck(address.objectId, roleid))
2510  strVal(object));
2511  break;
2512  case OBJECT_OPCLASS:
2513  if (!pg_opclass_ownercheck(address.objectId, roleid))
2515  NameListToString(castNode(List, object)));
2516  break;
2517  case OBJECT_OPFAMILY:
2518  if (!pg_opfamily_ownercheck(address.objectId, roleid))
2520  NameListToString(castNode(List, object)));
2521  break;
2522  case OBJECT_LARGEOBJECT:
2523  if (!lo_compat_privileges &&
2524  !pg_largeobject_ownercheck(address.objectId, roleid))
2525  ereport(ERROR,
2526  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2527  errmsg("must be owner of large object %u",
2528  address.objectId)));
2529  break;
2530  case OBJECT_CAST:
2531  {
2532  /* We can only check permissions on the source/target types */
2533  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2534  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2535  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2536  Oid targettypeid = typenameTypeId(NULL, targettype);
2537 
2538  if (!pg_type_ownercheck(sourcetypeid, roleid)
2539  && !pg_type_ownercheck(targettypeid, roleid))
2540  ereport(ERROR,
2541  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2542  errmsg("must be owner of type %s or type %s",
2543  format_type_be(sourcetypeid),
2544  format_type_be(targettypeid))));
2545  }
2546  break;
2547  case OBJECT_PUBLICATION:
2548  if (!pg_publication_ownercheck(address.objectId, roleid))
2550  strVal(object));
2551  break;
2552  case OBJECT_SUBSCRIPTION:
2553  if (!pg_subscription_ownercheck(address.objectId, roleid))
2555  strVal(object));
2556  break;
2557  case OBJECT_TRANSFORM:
2558  {
2559  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2560  Oid typeid = typenameTypeId(NULL, typename);
2561 
2562  if (!pg_type_ownercheck(typeid, roleid))
2564  }
2565  break;
2566  case OBJECT_TABLESPACE:
2567  if (!pg_tablespace_ownercheck(address.objectId, roleid))
2569  strVal(object));
2570  break;
2571  case OBJECT_TSDICTIONARY:
2572  if (!pg_ts_dict_ownercheck(address.objectId, roleid))
2574  NameListToString(castNode(List, object)));
2575  break;
2577  if (!pg_ts_config_ownercheck(address.objectId, roleid))
2579  NameListToString(castNode(List, object)));
2580  break;
2581  case OBJECT_ROLE:
2582 
2583  /*
2584  * We treat roles as being "owned" by those with CREATEROLE priv,
2585  * except that superusers are only owned by superusers.
2586  */
2587  if (superuser_arg(address.objectId))
2588  {
2589  if (!superuser_arg(roleid))
2590  ereport(ERROR,
2591  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2592  errmsg("must be superuser")));
2593  }
2594  else
2595  {
2596  if (!has_createrole_privilege(roleid))
2597  ereport(ERROR,
2598  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2599  errmsg("must have CREATEROLE privilege")));
2600  }
2601  break;
2602  case OBJECT_TSPARSER:
2603  case OBJECT_TSTEMPLATE:
2604  case OBJECT_ACCESS_METHOD:
2605  case OBJECT_PARAMETER_ACL:
2606  /* We treat these object types as being owned by superusers */
2607  if (!superuser_arg(roleid))
2608  ereport(ERROR,
2609  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2610  errmsg("must be superuser")));
2611  break;
2612  case OBJECT_STATISTIC_EXT:
2613  if (!pg_statistics_object_ownercheck(address.objectId, roleid))
2615  NameListToString(castNode(List, object)));
2616  break;
2617  default:
2618  elog(ERROR, "unrecognized object type: %d",
2619  (int) objtype);
2620  }
2621 }
@ ACLCHECK_NOT_OWNER
Definition: acl.h:184
bool pg_language_ownercheck(Oid lan_oid, Oid roleid)
Definition: aclchk.c:5275
bool pg_namespace_ownercheck(Oid nsp_oid, Oid roleid)
Definition: aclchk.c:5347
bool pg_foreign_data_wrapper_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5508
bool pg_ts_dict_ownercheck(Oid dict_oid, Oid roleid)
Definition: aclchk.c:5454
bool pg_ts_config_ownercheck(Oid cfg_oid, Oid roleid)
Definition: aclchk.c:5481
bool pg_opclass_ownercheck(Oid opc_oid, Oid roleid)
Definition: aclchk.c:5400
bool pg_subscription_ownercheck(Oid sub_oid, Oid roleid)
Definition: aclchk.c:5735
bool pg_proc_ownercheck(Oid proc_oid, Oid roleid)
Definition: aclchk.c:5249
bool pg_largeobject_ownercheck(Oid lobj_oid, Oid roleid)
Definition: aclchk.c:5304
bool pg_tablespace_ownercheck(Oid spc_oid, Oid roleid)
Definition: aclchk.c:5373
bool pg_collation_ownercheck(Oid coll_oid, Oid roleid)
Definition: aclchk.c:5615
bool pg_extension_ownercheck(Oid ext_oid, Oid roleid)
Definition: aclchk.c:5667
bool pg_type_ownercheck(Oid type_oid, Oid roleid)
Definition: aclchk.c:5197
bool pg_foreign_server_ownercheck(Oid srv_oid, Oid roleid)
Definition: aclchk.c:5535
bool pg_database_ownercheck(Oid db_oid, Oid roleid)
Definition: aclchk.c:5589
bool pg_class_ownercheck(Oid class_oid, Oid roleid)
Definition: aclchk.c:5171
bool pg_oper_ownercheck(Oid oper_oid, Oid roleid)
Definition: aclchk.c:5223
bool pg_opfamily_ownercheck(Oid opf_oid, Oid roleid)
Definition: aclchk.c:5427
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:5562
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3512
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3831
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:5796
bool pg_statistics_object_ownercheck(Oid stat_oid, Oid roleid)
Definition: aclchk.c:5761
bool pg_conversion_ownercheck(Oid conv_oid, Oid roleid)
Definition: aclchk.c:5641
bool pg_publication_ownercheck(Oid pub_oid, Oid roleid)
Definition: aclchk.c:5709
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ERROR
Definition: elog.h:33
#define elog(elevel,...)
Definition: elog.h:218
#define ereport(elevel,...)
Definition: elog.h:143
char * format_type_be(Oid type_oid)
Definition: format_type.c:343
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:649
bool lo_compat_privileges
Definition: inv_api.c:58
char * NameListToString(List *names)
Definition: namespace.c:3148
#define castNode(_type_, nodeptr)
Definition: nodes.h:642
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:291
@ OBJECT_EVENT_TRIGGER
Definition: parsenodes.h:2148
@ OBJECT_FDW
Definition: parsenodes.h:2150
@ OBJECT_TSPARSER
Definition: parsenodes.h:2181
@ OBJECT_COLLATION
Definition: parsenodes.h:2141
@ OBJECT_ACCESS_METHOD
Definition: parsenodes.h:2134
@ OBJECT_OPCLASS
Definition: parsenodes.h:2158
@ OBJECT_AGGREGATE
Definition: parsenodes.h:2135
@ OBJECT_MATVIEW
Definition: parsenodes.h:2157
@ OBJECT_SCHEMA
Definition: parsenodes.h:2170
@ OBJECT_POLICY
Definition: parsenodes.h:2162
@ OBJECT_OPERATOR
Definition: parsenodes.h:2159
@ OBJECT_FOREIGN_TABLE
Definition: parsenodes.h:2152
@ OBJECT_TSCONFIGURATION
Definition: parsenodes.h:2179
@ OBJECT_OPFAMILY
Definition: parsenodes.h:2160
@ OBJECT_DOMAIN
Definition: parsenodes.h:2146
@ OBJECT_COLUMN
Definition: parsenodes.h:2140
@ OBJECT_TABLESPACE
Definition: parsenodes.h:2176
@ OBJECT_ROLE
Definition: parsenodes.h:2167
@ OBJECT_ROUTINE
Definition: parsenodes.h:2168
@ OBJECT_LARGEOBJECT
Definition: parsenodes.h:2156
@ OBJECT_PROCEDURE
Definition: parsenodes.h:2163
@ OBJECT_EXTENSION
Definition: parsenodes.h:2149
@ OBJECT_INDEX
Definition: parsenodes.h:2154
@ OBJECT_DATABASE
Definition: parsenodes.h:2143
@ OBJECT_SEQUENCE
Definition: parsenodes.h:2171
@ OBJECT_TSTEMPLATE
Definition: parsenodes.h:2182
@ OBJECT_LANGUAGE
Definition: parsenodes.h:2155
@ OBJECT_FOREIGN_SERVER
Definition: parsenodes.h:2151
@ OBJECT_TSDICTIONARY
Definition: parsenodes.h:2180
@ OBJECT_ATTRIBUTE
Definition: parsenodes.h:2138
@ OBJECT_PUBLICATION
Definition: parsenodes.h:2164
@ OBJECT_RULE
Definition: parsenodes.h:2169
@ OBJECT_CONVERSION
Definition: parsenodes.h:2142
@ OBJECT_TABLE
Definition: parsenodes.h:2175
@ OBJECT_VIEW
Definition: parsenodes.h:2185
@ OBJECT_PARAMETER_ACL
Definition: parsenodes.h:2161
@ OBJECT_TYPE
Definition: parsenodes.h:2183
@ OBJECT_FUNCTION
Definition: parsenodes.h:2153
@ OBJECT_TABCONSTRAINT
Definition: parsenodes.h:2174
@ OBJECT_DOMCONSTRAINT
Definition: parsenodes.h:2147
@ OBJECT_SUBSCRIPTION
Definition: parsenodes.h:2172
@ OBJECT_STATISTIC_EXT
Definition: parsenodes.h:2173
@ OBJECT_CAST
Definition: parsenodes.h:2139
@ OBJECT_TRIGGER
Definition: parsenodes.h:2178
@ OBJECT_TRANSFORM
Definition: parsenodes.h:2177
FormData_pg_constraint * Form_pg_constraint
#define linitial_node(type, l)
Definition: pg_list.h:177
#define lsecond_node(type, l)
Definition: pg_list.h:182
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
unsigned int Oid
Definition: postgres_ext.h:31
#define RelationGetRelid(relation)
Definition: rel.h:489
#define RelationGetRelationName(relation)
Definition: rel.h:523
Definition: pg_list.h:51
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1221
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1173
@ CONSTROID
Definition: syscache.h:53
#define strVal(v)
Definition: value.h:72

References aclcheck_error(), aclcheck_error_type(), ACLCHECK_NOT_OWNER, castNode, CONSTROID, elog, ereport, errcode(), errmsg(), ERROR, format_type_be(), GETSTRUCT, has_createrole_privilege(), HeapTupleIsValid, linitial_node, lo_compat_privileges, lsecond_node, NameListToString(), OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_ATTRIBUTE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_PARAMETER_ACL, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_VIEW, ObjectAddress::objectId, ObjectIdGetDatum, pg_class_ownercheck(), pg_collation_ownercheck(), pg_conversion_ownercheck(), pg_database_ownercheck(), pg_event_trigger_ownercheck(), pg_extension_ownercheck(), pg_foreign_data_wrapper_ownercheck(), pg_foreign_server_ownercheck(), pg_language_ownercheck(), pg_largeobject_ownercheck(), pg_namespace_ownercheck(), pg_opclass_ownercheck(), pg_oper_ownercheck(), pg_opfamily_ownercheck(), pg_proc_ownercheck(), pg_publication_ownercheck(), pg_statistics_object_ownercheck(), pg_subscription_ownercheck(), pg_tablespace_ownercheck(), pg_ts_config_ownercheck(), pg_ts_dict_ownercheck(), pg_type_ownercheck(), RelationGetRelationName, RelationGetRelid, ReleaseSysCache(), SearchSysCache1(), strVal, superuser_arg(), and typenameTypeId().

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

◆ get_catalog_object_by_oid()

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

Definition at line 2850 of file objectaddress.c.

2851 {
2852  HeapTuple tuple;
2853  Oid classId = RelationGetRelid(catalog);
2854  int oidCacheId = get_object_catcache_oid(classId);
2855 
2856  if (oidCacheId > 0)
2857  {
2858  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2859  if (!HeapTupleIsValid(tuple)) /* should not happen */
2860  return NULL;
2861  }
2862  else
2863  {
2864  Oid oidIndexId = get_object_oid_index(classId);
2865  SysScanDesc scan;
2866  ScanKeyData skey;
2867 
2868  Assert(OidIsValid(oidIndexId));
2869 
2870  ScanKeyInit(&skey,
2871  oidcol,
2872  BTEqualStrategyNumber, F_OIDEQ,
2873  ObjectIdGetDatum(objectId));
2874 
2875  scan = systable_beginscan(catalog, oidIndexId, true,
2876  NULL, 1, &skey);
2877  tuple = systable_getnext(scan);
2878  if (!HeapTupleIsValid(tuple))
2879  {
2880  systable_endscan(scan);
2881  return NULL;
2882  }
2883  tuple = heap_copytuple(tuple);
2884 
2885  systable_endscan(scan);
2886  }
2887 
2888  return tuple;
2889 }
#define OidIsValid(objectId)
Definition: c.h:710
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:598
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:505
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:386
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:680
Assert(fmt[strlen(fmt) - 1] !='\n')
int get_object_catcache_oid(Oid class_id)
Oid get_object_oid_index(Oid class_id)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:179

References Assert(), BTEqualStrategyNumber, get_object_catcache_oid(), get_object_oid_index(), heap_copytuple(), HeapTupleIsValid, ObjectIdGetDatum, OidIsValid, RelationGetRelid, ScanKeyInit(), SearchSysCacheCopy1, systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by AlterObjectOwner_internal(), EventTriggerSQLDropAddObject(), getConstraintTypeDescription(), getObjectIdentityParts(), pg_event_trigger_ddl_commands(), and pg_identify_object().

◆ get_object_address()

ObjectAddress get_object_address ( ObjectType  objtype,
Node object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)

Definition at line 941 of file objectaddress.c.

943 {
944  ObjectAddress address;
945  ObjectAddress old_address = {InvalidOid, InvalidOid, 0};
946  Relation relation = NULL;
947  uint64 inval_count;
948 
949  /* Some kind of lock must be taken. */
950  Assert(lockmode != NoLock);
951 
952  for (;;)
953  {
954  /*
955  * Remember this value, so that, after looking up the object name and
956  * locking it, we can check whether any invalidation messages have
957  * been processed that might require a do-over.
958  */
959  inval_count = SharedInvalidMessageCounter;
960 
961  /* Look up object address. */
962  switch (objtype)
963  {
964  case OBJECT_INDEX:
965  case OBJECT_SEQUENCE:
966  case OBJECT_TABLE:
967  case OBJECT_VIEW:
968  case OBJECT_MATVIEW:
970  address =
971  get_relation_by_qualified_name(objtype, castNode(List, object),
972  &relation, lockmode,
973  missing_ok);
974  break;
975  case OBJECT_COLUMN:
976  address =
977  get_object_address_attribute(objtype, castNode(List, object),
978  &relation, lockmode,
979  missing_ok);
980  break;
981  case OBJECT_DEFAULT:
982  address =
983  get_object_address_attrdef(objtype, castNode(List, object),
984  &relation, lockmode,
985  missing_ok);
986  break;
987  case OBJECT_RULE:
988  case OBJECT_TRIGGER:
990  case OBJECT_POLICY:
991  address = get_object_address_relobject(objtype, castNode(List, object),
992  &relation, missing_ok);
993  break;
995  {
996  List *objlist;
997  ObjectAddress domaddr;
998  char *constrname;
999 
1000  objlist = castNode(List, object);
1002  linitial_node(TypeName, objlist),
1003  missing_ok);
1004  constrname = strVal(lsecond(objlist));
1005 
1006  address.classId = ConstraintRelationId;
1007  address.objectId = get_domain_constraint_oid(domaddr.objectId,
1008  constrname, missing_ok);
1009  address.objectSubId = 0;
1010  }
1011  break;
1012  case OBJECT_DATABASE:
1013  case OBJECT_EXTENSION:
1014  case OBJECT_TABLESPACE:
1015  case OBJECT_ROLE:
1016  case OBJECT_SCHEMA:
1017  case OBJECT_LANGUAGE:
1018  case OBJECT_FDW:
1019  case OBJECT_FOREIGN_SERVER:
1020  case OBJECT_EVENT_TRIGGER:
1021  case OBJECT_PARAMETER_ACL:
1022  case OBJECT_ACCESS_METHOD:
1023  case OBJECT_PUBLICATION:
1024  case OBJECT_SUBSCRIPTION:
1025  address = get_object_address_unqualified(objtype,
1026  castNode(String, object), missing_ok);
1027  break;
1028  case OBJECT_TYPE:
1029  case OBJECT_DOMAIN:
1030  address = get_object_address_type(objtype, castNode(TypeName, object), missing_ok);
1031  break;
1032  case OBJECT_AGGREGATE:
1033  case OBJECT_FUNCTION:
1034  case OBJECT_PROCEDURE:
1035  case OBJECT_ROUTINE:
1036  address.classId = ProcedureRelationId;
1037  address.objectId = LookupFuncWithArgs(objtype, castNode(ObjectWithArgs, object), missing_ok);
1038  address.objectSubId = 0;
1039  break;
1040  case OBJECT_OPERATOR:
1041  address.classId = OperatorRelationId;
1042  address.objectId = LookupOperWithArgs(castNode(ObjectWithArgs, object), missing_ok);
1043  address.objectSubId = 0;
1044  break;
1045  case OBJECT_COLLATION:
1046  address.classId = CollationRelationId;
1047  address.objectId = get_collation_oid(castNode(List, object), missing_ok);
1048  address.objectSubId = 0;
1049  break;
1050  case OBJECT_CONVERSION:
1051  address.classId = ConversionRelationId;
1052  address.objectId = get_conversion_oid(castNode(List, object), missing_ok);
1053  address.objectSubId = 0;
1054  break;
1055  case OBJECT_OPCLASS:
1056  case OBJECT_OPFAMILY:
1057  address = get_object_address_opcf(objtype, castNode(List, object), missing_ok);
1058  break;
1059  case OBJECT_AMOP:
1060  case OBJECT_AMPROC:
1061  address = get_object_address_opf_member(objtype, castNode(List, object), missing_ok);
1062  break;
1063  case OBJECT_LARGEOBJECT:
1064  address.classId = LargeObjectRelationId;
1065  address.objectId = oidparse(object);
1066  address.objectSubId = 0;
1067  if (!LargeObjectExists(address.objectId))
1068  {
1069  if (!missing_ok)
1070  ereport(ERROR,
1071  (errcode(ERRCODE_UNDEFINED_OBJECT),
1072  errmsg("large object %u does not exist",
1073  address.objectId)));
1074  }
1075  break;
1076  case OBJECT_CAST:
1077  {
1078  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
1079  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
1080  Oid sourcetypeid;
1081  Oid targettypeid;
1082 
1083  sourcetypeid = LookupTypeNameOid(NULL, sourcetype, missing_ok);
1084  targettypeid = LookupTypeNameOid(NULL, targettype, missing_ok);
1085  address.classId = CastRelationId;
1086  address.objectId =
1087  get_cast_oid(sourcetypeid, targettypeid, missing_ok);
1088  address.objectSubId = 0;
1089  }
1090  break;
1091  case OBJECT_TRANSFORM:
1092  {
1093  TypeName *typename = linitial_node(TypeName, castNode(List, object));
1094  char *langname = strVal(lsecond(castNode(List, object)));
1095  Oid type_id = LookupTypeNameOid(NULL, typename, missing_ok);
1096  Oid lang_id = get_language_oid(langname, missing_ok);
1097 
1098  address.classId = TransformRelationId;
1099  address.objectId =
1100  get_transform_oid(type_id, lang_id, missing_ok);
1101  address.objectSubId = 0;
1102  }
1103  break;
1104  case OBJECT_TSPARSER:
1105  address.classId = TSParserRelationId;
1106  address.objectId = get_ts_parser_oid(castNode(List, object), missing_ok);
1107  address.objectSubId = 0;
1108  break;
1109  case OBJECT_TSDICTIONARY:
1110  address.classId = TSDictionaryRelationId;
1111  address.objectId = get_ts_dict_oid(castNode(List, object), missing_ok);
1112  address.objectSubId = 0;
1113  break;
1114  case OBJECT_TSTEMPLATE:
1115  address.classId = TSTemplateRelationId;
1116  address.objectId = get_ts_template_oid(castNode(List, object), missing_ok);
1117  address.objectSubId = 0;
1118  break;
1120  address.classId = TSConfigRelationId;
1121  address.objectId = get_ts_config_oid(castNode(List, object), missing_ok);
1122  address.objectSubId = 0;
1123  break;
1124  case OBJECT_USER_MAPPING:
1125  address = get_object_address_usermapping(castNode(List, object),
1126  missing_ok);
1127  break;
1130  missing_ok);
1131  break;
1134  &relation,
1135  missing_ok);
1136  break;
1137  case OBJECT_DEFACL:
1138  address = get_object_address_defacl(castNode(List, object),
1139  missing_ok);
1140  break;
1141  case OBJECT_STATISTIC_EXT:
1142  address.classId = StatisticExtRelationId;
1143  address.objectId = get_statistics_object_oid(castNode(List, object),
1144  missing_ok);
1145  address.objectSubId = 0;
1146  break;
1147  default:
1148  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1149  /* placate compiler, in case it thinks elog might return */
1150  address.classId = InvalidOid;
1151  address.objectId = InvalidOid;
1152  address.objectSubId = 0;
1153  }
1154 
1155  /*
1156  * If we could not find the supplied object, return without locking.
1157  */
1158  if (!OidIsValid(address.objectId))
1159  {
1160  Assert(missing_ok);
1161  return address;
1162  }
1163 
1164  /*
1165  * If we're retrying, see if we got the same answer as last time. If
1166  * so, we're done; if not, we locked the wrong thing, so give up our
1167  * lock.
1168  */
1169  if (OidIsValid(old_address.classId))
1170  {
1171  if (old_address.classId == address.classId
1172  && old_address.objectId == address.objectId
1173  && old_address.objectSubId == address.objectSubId)
1174  break;
1175  if (old_address.classId != RelationRelationId)
1176  {
1177  if (IsSharedRelation(old_address.classId))
1178  UnlockSharedObject(old_address.classId,
1179  old_address.objectId,
1180  0, lockmode);
1181  else
1182  UnlockDatabaseObject(old_address.classId,
1183  old_address.objectId,
1184  0, lockmode);
1185  }
1186  }
1187 
1188  /*
1189  * If we're dealing with a relation or attribute, then the relation is
1190  * already locked. Otherwise, we lock it now.
1191  */
1192  if (address.classId != RelationRelationId)
1193  {
1194  if (IsSharedRelation(address.classId))
1195  LockSharedObject(address.classId, address.objectId, 0,
1196  lockmode);
1197  else
1198  LockDatabaseObject(address.classId, address.objectId, 0,
1199  lockmode);
1200  }
1201 
1202  /*
1203  * At this point, we've resolved the name to an OID and locked the
1204  * corresponding database object. However, it's possible that by the
1205  * time we acquire the lock on the object, concurrent DDL has modified
1206  * the database in such a way that the name we originally looked up no
1207  * longer resolves to that OID.
1208  *
1209  * We can be certain that this isn't an issue if (a) no shared
1210  * invalidation messages have been processed or (b) we've locked a
1211  * relation somewhere along the line. All the relation name lookups
1212  * in this module ultimately use RangeVarGetRelid() to acquire a
1213  * relation lock, and that function protects against the same kinds of
1214  * races we're worried about here. Even when operating on a
1215  * constraint, rule, or trigger, we still acquire AccessShareLock on
1216  * the relation, which is enough to freeze out any concurrent DDL.
1217  *
1218  * In all other cases, however, it's possible that the name we looked
1219  * up no longer refers to the object we locked, so we retry the lookup
1220  * and see whether we get the same answer.
1221  */
1222  if (inval_count == SharedInvalidMessageCounter || relation != NULL)
1223  break;
1224  old_address = address;
1225  }
1226 
1227  /* Return the object address and the relation. */
1228  *relp = relation;
1229  return address;
1230 }
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:245
Oid get_transform_oid(Oid type_id, Oid lang_id, bool missing_ok)
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1046
void LockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1005
void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1067
void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1026
#define NoLock
Definition: lockdefs.h:34
Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok)
Definition: lsyscache.c:1032
Oid get_conversion_oid(List *name, bool missing_ok)
Definition: namespace.c:3701
Oid get_statistics_object_oid(List *names, bool missing_ok)
Definition: namespace.c:2224
Oid get_collation_oid(List *name, bool missing_ok)
Definition: namespace.c:3647
Oid get_ts_dict_oid(List *names, bool missing_ok)
Definition: namespace.c:2472
Oid get_ts_parser_oid(List *names, bool missing_ok)
Definition: namespace.c:2346
Oid get_ts_config_oid(List *names, bool missing_ok)
Definition: namespace.c:2725
Oid get_ts_template_oid(List *names, bool missing_ok)
Definition: namespace.c:2599
static ObjectAddress get_object_address_publication_schema(List *object, bool missing_ok)
static ObjectAddress get_object_address_relobject(ObjectType objtype, List *object, Relation *relp, bool missing_ok)
static ObjectAddress get_object_address_defacl(List *object, bool missing_ok)
static ObjectAddress get_object_address_unqualified(ObjectType objtype, String *strval, bool missing_ok)
static ObjectAddress get_object_address_publication_rel(List *object, Relation *relp, bool missing_ok)
static ObjectAddress get_object_address_opf_member(ObjectType objtype, List *object, bool missing_ok)
static ObjectAddress get_object_address_type(ObjectType objtype, TypeName *typename, bool missing_ok)
static ObjectAddress get_object_address_usermapping(List *object, bool missing_ok)
static ObjectAddress get_object_address_opcf(ObjectType objtype, List *object, bool missing_ok)
static ObjectAddress get_object_address_attribute(ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
static ObjectAddress get_relation_by_qualified_name(ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
static ObjectAddress get_object_address_attrdef(ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
Oid oidparse(Node *node)
Definition: oid.c:314
Oid LookupFuncWithArgs(ObjectType objtype, ObjectWithArgs *func, bool missing_ok)
Definition: parse_func.c:2207
Oid LookupOperWithArgs(ObjectWithArgs *oper, bool noError)
Definition: parse_oper.c:145
Oid LookupTypeNameOid(ParseState *pstate, const TypeName *typeName, bool missing_ok)
Definition: parse_type.c:232
@ OBJECT_USER_MAPPING
Definition: parsenodes.h:2184
@ OBJECT_DEFACL
Definition: parsenodes.h:2145
@ OBJECT_PUBLICATION_NAMESPACE
Definition: parsenodes.h:2165
@ OBJECT_DEFAULT
Definition: parsenodes.h:2144
@ OBJECT_AMOP
Definition: parsenodes.h:2136
@ OBJECT_PUBLICATION_REL
Definition: parsenodes.h:2166
@ OBJECT_AMPROC
Definition: parsenodes.h:2137
Oid get_domain_constraint_oid(Oid typid, const char *conname, bool missing_ok)
bool LargeObjectExists(Oid loid)
#define lsecond(l)
Definition: pg_list.h:179
#define InvalidOid
Definition: postgres_ext.h:36
Oid get_language_oid(const char *langname, bool missing_ok)
Definition: proclang.c:228
uint64 SharedInvalidMessageCounter
Definition: sinval.c:26
Definition: value.h:58

References Assert(), castNode, ObjectAddress::classId, elog, ereport, errcode(), errmsg(), ERROR, get_cast_oid(), get_collation_oid(), get_conversion_oid(), get_domain_constraint_oid(), get_language_oid(), get_object_address_attrdef(), get_object_address_attribute(), get_object_address_defacl(), get_object_address_opcf(), get_object_address_opf_member(), get_object_address_publication_rel(), get_object_address_publication_schema(), get_object_address_relobject(), get_object_address_type(), get_object_address_unqualified(), get_object_address_usermapping(), get_relation_by_qualified_name(), get_statistics_object_oid(), get_transform_oid(), get_ts_config_oid(), get_ts_dict_oid(), get_ts_parser_oid(), get_ts_template_oid(), InvalidOid, IsSharedRelation(), LargeObjectExists(), linitial_node, LockDatabaseObject(), LockSharedObject(), LookupFuncWithArgs(), LookupOperWithArgs(), LookupTypeNameOid(), lsecond, lsecond_node, NoLock, OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_AMOP, OBJECT_AMPROC, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DEFACL, OBJECT_DEFAULT, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_PARAMETER_ACL, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_PUBLICATION_NAMESPACE, OBJECT_PUBLICATION_REL, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_USER_MAPPING, OBJECT_VIEW, ObjectAddress::objectId, ObjectAddress::objectSubId, OidIsValid, oidparse(), SharedInvalidMessageCounter, strVal, UnlockDatabaseObject(), and UnlockSharedObject().

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

◆ get_object_address_attrdef()

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

Definition at line 1565 of file objectaddress.c.

1568 {
1569  ObjectAddress address;
1570  List *relname;
1571  Oid reloid;
1572  Relation relation;
1573  const char *attname;
1575  TupleDesc tupdesc;
1576  Oid defoid;
1577 
1578  /* Extract relation name and open relation. */
1579  if (list_length(object) < 2)
1580  ereport(ERROR,
1581  (errcode(ERRCODE_SYNTAX_ERROR),
1582  errmsg("column name must be qualified")));
1583  attname = strVal(llast(object));
1584  relname = list_truncate(list_copy(object), list_length(object) - 1);
1585  /* XXX no missing_ok support here */
1586  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1587  reloid = RelationGetRelid(relation);
1588 
1589  tupdesc = RelationGetDescr(relation);
1590 
1591  /* Look up attribute number and fetch the pg_attrdef OID */
1592  attnum = get_attnum(reloid, attname);
1593  defoid = InvalidOid;
1594  if (attnum != InvalidAttrNumber && tupdesc->constr != NULL)
1595  defoid = GetAttrDefaultOid(reloid, attnum);
1596  if (!OidIsValid(defoid))
1597  {
1598  if (!missing_ok)
1599  ereport(ERROR,
1600  (errcode(ERRCODE_UNDEFINED_COLUMN),
1601  errmsg("default value for column \"%s\" of relation \"%s\" does not exist",
1603 
1604  address.classId = AttrDefaultRelationId;
1605  address.objectId = InvalidOid;
1606  address.objectSubId = InvalidAttrNumber;
1607  relation_close(relation, lockmode);
1608  return address;
1609  }
1610 
1611  address.classId = AttrDefaultRelationId;
1612  address.objectId = defoid;
1613  address.objectSubId = 0;
1614 
1615  *relp = relation;
1616  return address;
1617 }
int16 AttrNumber
Definition: attnum.h:21
#define InvalidAttrNumber
Definition: attnum.h:23
List * list_truncate(List *list, int new_size)
Definition: list.c:610
List * list_copy(const List *oldlist)
Definition: list.c:1532
AttrNumber get_attnum(Oid relid, const char *attname)
Definition: lsyscache.c:856
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3108
Oid GetAttrDefaultOid(Oid relid, AttrNumber attnum)
Definition: pg_attrdef.c:342
NameData attname
Definition: pg_attribute.h:41
int16 attnum
Definition: pg_attribute.h:83
NameData relname
Definition: pg_class.h:38
#define llast(l)
Definition: pg_list.h:194
static int list_length(const List *l)
Definition: pg_list.h:149
#define RelationGetDescr(relation)
Definition: rel.h:515
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:138
TupleConstr * constr
Definition: tupdesc.h:85

References attname, attnum, ObjectAddress::classId, TupleDescData::constr, ereport, errcode(), errmsg(), ERROR, get_attnum(), GetAttrDefaultOid(), InvalidAttrNumber, InvalidOid, list_copy(), list_length(), list_truncate(), llast, makeRangeVarFromNameList(), NameListToString(), ObjectAddress::objectId, ObjectAddress::objectSubId, OidIsValid, relation_close(), relation_openrv(), RelationGetDescr, RelationGetRelid, relname, and strVal.

Referenced by get_object_address().

◆ get_object_address_attribute()

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

Definition at line 1514 of file objectaddress.c.

1517 {
1518  ObjectAddress address;
1519  List *relname;
1520  Oid reloid;
1521  Relation relation;
1522  const char *attname;
1524 
1525  /* Extract relation name and open relation. */
1526  if (list_length(object) < 2)
1527  ereport(ERROR,
1528  (errcode(ERRCODE_SYNTAX_ERROR),
1529  errmsg("column name must be qualified")));
1530  attname = strVal(llast(object));
1531  relname = list_truncate(list_copy(object), list_length(object) - 1);
1532  /* XXX no missing_ok support here */
1533  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1534  reloid = RelationGetRelid(relation);
1535 
1536  /* Look up attribute and construct return value. */
1537  attnum = get_attnum(reloid, attname);
1538  if (attnum == InvalidAttrNumber)
1539  {
1540  if (!missing_ok)
1541  ereport(ERROR,
1542  (errcode(ERRCODE_UNDEFINED_COLUMN),
1543  errmsg("column \"%s\" of relation \"%s\" does not exist",
1545 
1546  address.classId = RelationRelationId;
1547  address.objectId = InvalidOid;
1548  address.objectSubId = InvalidAttrNumber;
1549  relation_close(relation, lockmode);
1550  return address;
1551  }
1552 
1553  address.classId = RelationRelationId;
1554  address.objectId = reloid;
1555  address.objectSubId = attnum;
1556 
1557  *relp = relation;
1558  return address;
1559 }

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

Referenced by get_object_address().

◆ get_object_address_defacl()

static ObjectAddress get_object_address_defacl ( List object,
bool  missing_ok 
)
static

Definition at line 1978 of file objectaddress.c.

1979 {
1980  HeapTuple tp;
1981  Oid userid;
1982  Oid schemaid;
1983  char *username;
1984  char *schema;
1985  char objtype;
1986  char *objtype_str;
1987  ObjectAddress address;
1988 
1989  ObjectAddressSet(address, DefaultAclRelationId, InvalidOid);
1990 
1991  /*
1992  * First figure out the textual attributes so that they can be used for
1993  * error reporting.
1994  */
1995  username = strVal(lsecond(object));
1996  if (list_length(object) >= 3)
1997  schema = (char *) strVal(lthird(object));
1998  else
1999  schema = NULL;
2000 
2001  /*
2002  * Decode defaclobjtype. Only first char is considered; the rest of the
2003  * string, if any, is blissfully ignored.
2004  */
2005  objtype = ((char *) strVal(linitial(object)))[0];
2006  switch (objtype)
2007  {
2008  case DEFACLOBJ_RELATION:
2009  objtype_str = "tables";
2010  break;
2011  case DEFACLOBJ_SEQUENCE:
2012  objtype_str = "sequences";
2013  break;
2014  case DEFACLOBJ_FUNCTION:
2015  objtype_str = "functions";
2016  break;
2017  case DEFACLOBJ_TYPE:
2018  objtype_str = "types";
2019  break;
2020  case DEFACLOBJ_NAMESPACE:
2021  objtype_str = "schemas";
2022  break;
2023  default:
2024  ereport(ERROR,
2025  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2026  errmsg("unrecognized default ACL object type \"%c\"", objtype),
2027  errhint("Valid object types are \"%c\", \"%c\", \"%c\", \"%c\", \"%c\".",
2028  DEFACLOBJ_RELATION,
2029  DEFACLOBJ_SEQUENCE,
2030  DEFACLOBJ_FUNCTION,
2031  DEFACLOBJ_TYPE,
2032  DEFACLOBJ_NAMESPACE)));
2033  }
2034 
2035  /*
2036  * Look up user ID. Behave as "default ACL not found" if the user doesn't
2037  * exist.
2038  */
2041  if (!HeapTupleIsValid(tp))
2042  goto not_found;
2043  userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
2044  ReleaseSysCache(tp);
2045 
2046  /*
2047  * If a schema name was given, look up its OID. If it doesn't exist,
2048  * behave as "default ACL not found".
2049  */
2050  if (schema)
2051  {
2052  schemaid = get_namespace_oid(schema, true);
2053  if (schemaid == InvalidOid)
2054  goto not_found;
2055  }
2056  else
2057  schemaid = InvalidOid;
2058 
2059  /* Finally, look up the pg_default_acl object */
2061  ObjectIdGetDatum(userid),
2062  ObjectIdGetDatum(schemaid),
2063  CharGetDatum(objtype));
2064  if (!HeapTupleIsValid(tp))
2065  goto not_found;
2066 
2067  address.objectId = ((Form_pg_default_acl) GETSTRUCT(tp))->oid;
2068  ReleaseSysCache(tp);
2069 
2070  return address;
2071 
2072 not_found:
2073  if (!missing_ok)
2074  {
2075  if (schema)
2076  ereport(ERROR,
2077  (errcode(ERRCODE_UNDEFINED_OBJECT),
2078  errmsg("default ACL for user \"%s\" in schema \"%s\" on %s does not exist",
2079  username, schema, objtype_str)));
2080  else
2081  ereport(ERROR,
2082  (errcode(ERRCODE_UNDEFINED_OBJECT),
2083  errmsg("default ACL for user \"%s\" on %s does not exist",
2084  username, objtype_str)));
2085  }
2086  return address;
2087 }
int errhint(const char *fmt,...)
Definition: elog.c:1151
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3089
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
FormData_pg_authid * Form_pg_authid
Definition: pg_authid.h:56
FormData_pg_default_acl * Form_pg_default_acl
#define lthird(l)
Definition: pg_list.h:184
#define linitial(l)
Definition: pg_list.h:174
const char * username
Definition: pgbench.c:309
#define CStringGetDatum(X)
Definition: postgres.h:622
#define CharGetDatum(X)
Definition: postgres.h:460
HeapTuple SearchSysCache3(int cacheId, Datum key1, Datum key2, Datum key3)
Definition: syscache.c:1195
@ AUTHNAME
Definition: syscache.h:44
@ DEFACLROLENSPOBJ
Definition: syscache.h:56

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

Referenced by get_object_address().

◆ get_object_address_opcf()

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

Definition at line 1662 of file objectaddress.c.

1663 {
1664  Oid amoid;
1665  ObjectAddress address;
1666 
1667  /* XXX no missing_ok support here */
1668  amoid = get_index_am_oid(strVal(linitial(object)), false);
1669  object = list_copy_tail(object, 1);
1670 
1671  switch (objtype)
1672  {
1673  case OBJECT_OPCLASS:
1674  address.classId = OperatorClassRelationId;
1675  address.objectId = get_opclass_oid(amoid, object, missing_ok);
1676  address.objectSubId = 0;
1677  break;
1678  case OBJECT_OPFAMILY:
1679  address.classId = OperatorFamilyRelationId;
1680  address.objectId = get_opfamily_oid(amoid, object, missing_ok);
1681  address.objectSubId = 0;
1682  break;
1683  default:
1684  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1685  /* placate compiler, which doesn't know elog won't return */
1686  address.classId = InvalidOid;
1687  address.objectId = InvalidOid;
1688  address.objectSubId = 0;
1689  }
1690 
1691  return address;
1692 }
Oid get_index_am_oid(const char *amname, bool missing_ok)
Definition: amcmds.c:163
List * list_copy_tail(const List *oldlist, int nskip)
Definition: list.c:1551
Oid get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
Definition: opclasscmds.c:220
Oid get_opfamily_oid(Oid amID, List *opfamilyname, bool missing_ok)
Definition: opclasscmds.c:139

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

Referenced by get_object_address(), and get_object_address_opf_member().

◆ get_object_address_opf_member()

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

Definition at line 1700 of file objectaddress.c.

1702 {
1703  ObjectAddress famaddr;
1704  ObjectAddress address;
1705  ListCell *cell;
1706  List *copy;
1707  TypeName *typenames[2];
1708  Oid typeoids[2];
1709  int membernum;
1710  int i;
1711 
1712  /*
1713  * The last element of the object list contains the strategy or procedure
1714  * number. We need to strip that out before getting the opclass/family
1715  * address. The rest can be used directly by get_object_address_opcf().
1716  */
1717  membernum = atoi(strVal(llast(linitial(object))));
1718  copy = list_truncate(list_copy(linitial(object)), list_length(linitial(object)) - 1);
1719 
1720  /* no missing_ok support here */
1721  famaddr = get_object_address_opcf(OBJECT_OPFAMILY, copy, false);
1722 
1723  /* find out left/right type names and OIDs */
1724  typenames[0] = typenames[1] = NULL;
1725  typeoids[0] = typeoids[1] = InvalidOid;
1726  i = 0;
1727  foreach(cell, lsecond(object))
1728  {
1729  ObjectAddress typaddr;
1730 
1731  typenames[i] = lfirst_node(TypeName, cell);
1732  typaddr = get_object_address_type(OBJECT_TYPE, typenames[i], missing_ok);
1733  typeoids[i] = typaddr.objectId;
1734  if (++i >= 2)
1735  break;
1736  }
1737 
1738  switch (objtype)
1739  {
1740  case OBJECT_AMOP:
1741  {
1742  HeapTuple tp;
1743 
1744  ObjectAddressSet(address, AccessMethodOperatorRelationId,
1745  InvalidOid);
1746 
1748  ObjectIdGetDatum(famaddr.objectId),
1749  ObjectIdGetDatum(typeoids[0]),
1750  ObjectIdGetDatum(typeoids[1]),
1751  Int16GetDatum(membernum));
1752  if (!HeapTupleIsValid(tp))
1753  {
1754  if (!missing_ok)
1755  ereport(ERROR,
1756  (errcode(ERRCODE_UNDEFINED_OBJECT),
1757  errmsg("operator %d (%s, %s) of %s does not exist",
1758  membernum,
1759  TypeNameToString(typenames[0]),
1760  TypeNameToString(typenames[1]),
1761  getObjectDescription(&famaddr, false))));
1762  }
1763  else
1764  {
1765  address.objectId = ((Form_pg_amop) GETSTRUCT(tp))->oid;
1766  ReleaseSysCache(tp);
1767  }
1768  }
1769  break;
1770 
1771  case OBJECT_AMPROC:
1772  {
1773  HeapTuple tp;
1774 
1775  ObjectAddressSet(address, AccessMethodProcedureRelationId,
1776  InvalidOid);
1777 
1779  ObjectIdGetDatum(famaddr.objectId),
1780  ObjectIdGetDatum(typeoids[0]),
1781  ObjectIdGetDatum(typeoids[1]),
1782  Int16GetDatum(membernum));
1783  if (!HeapTupleIsValid(tp))
1784  {
1785  if (!missing_ok)
1786  ereport(ERROR,
1787  (errcode(ERRCODE_UNDEFINED_OBJECT),
1788  errmsg("function %d (%s, %s) of %s does not exist",
1789  membernum,
1790  TypeNameToString(typenames[0]),
1791  TypeNameToString(typenames[1]),
1792  getObjectDescription(&famaddr, false))));
1793  }
1794  else
1795  {
1796  address.objectId = ((Form_pg_amproc) GETSTRUCT(tp))->oid;
1797  ReleaseSysCache(tp);
1798  }
1799  }
1800  break;
1801  default:
1802  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1803  }
1804 
1805  return address;
1806 }
int i
Definition: isn.c:73
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
char * TypeNameToString(const TypeName *typeName)
Definition: parse_type.c:480
FormData_pg_amop * Form_pg_amop
Definition: pg_amop.h:88
FormData_pg_amproc * Form_pg_amproc
Definition: pg_amproc.h:68
#define lfirst_node(type, lc)
Definition: pg_list.h:172
#define Int16GetDatum(X)
Definition: postgres.h:495
HeapTuple SearchSysCache4(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
Definition: syscache.c:1206
@ AMPROCNUM
Definition: syscache.h:39
@ AMOPSTRATEGY
Definition: syscache.h:38

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

Referenced by get_object_address().

◆ get_object_address_publication_rel()

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

Definition at line 1883 of file objectaddress.c.

1885 {
1886  ObjectAddress address;
1887  Relation relation;
1888  List *relname;
1889  char *pubname;
1890  Publication *pub;
1891 
1892  ObjectAddressSet(address, PublicationRelRelationId, InvalidOid);
1893 
1894  relname = linitial(object);
1896  AccessShareLock, missing_ok);
1897  if (!relation)
1898  return address;
1899 
1900  /* fetch publication name from input list */
1901  pubname = strVal(lsecond(object));
1902 
1903  /* Now look up the pg_publication tuple */
1904  pub = GetPublicationByName(pubname, missing_ok);
1905  if (!pub)
1906  {
1907  relation_close(relation, AccessShareLock);
1908  return address;
1909  }
1910 
1911  /* Find the publication relation mapping in syscache. */
1912  address.objectId =
1913  GetSysCacheOid2(PUBLICATIONRELMAP, Anum_pg_publication_rel_oid,
1915  ObjectIdGetDatum(pub->oid));
1916  if (!OidIsValid(address.objectId))
1917  {
1918  if (!missing_ok)
1919  ereport(ERROR,
1920  (errcode(ERRCODE_UNDEFINED_OBJECT),
1921  errmsg("publication relation \"%s\" in publication \"%s\" does not exist",
1922  RelationGetRelationName(relation), pubname)));
1923  relation_close(relation, AccessShareLock);
1924  return address;
1925  }
1926 
1927  *relp = relation;
1928  return address;
1929 }
#define AccessShareLock
Definition: lockdefs.h:36
Publication * GetPublicationByName(const char *pubname, bool missing_ok)
Relation relation_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: relation.c:173
@ PUBLICATIONRELMAP
Definition: syscache.h:85
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition: syscache.h:199

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

Referenced by get_object_address().

◆ get_object_address_publication_schema()

static ObjectAddress get_object_address_publication_schema ( List object,
bool  missing_ok 
)
static

Definition at line 1936 of file objectaddress.c.

1937 {
1938  ObjectAddress address;
1939  Publication *pub;
1940  char *pubname;
1941  char *schemaname;
1942  Oid schemaid;
1943 
1944  ObjectAddressSet(address, PublicationNamespaceRelationId, InvalidOid);
1945 
1946  /* Fetch schema name and publication name from input list */
1947  schemaname = strVal(linitial(object));
1948  pubname = strVal(lsecond(object));
1949 
1950  schemaid = get_namespace_oid(schemaname, missing_ok);
1951  if (!OidIsValid(schemaid))
1952  return address;
1953 
1954  /* Now look up the pg_publication tuple */
1955  pub = GetPublicationByName(pubname, missing_ok);
1956  if (!pub)
1957  return address;
1958 
1959  /* Find the publication schema mapping in syscache */
1960  address.objectId =
1962  Anum_pg_publication_namespace_oid,
1963  ObjectIdGetDatum(schemaid),
1964  ObjectIdGetDatum(pub->oid));
1965  if (!OidIsValid(address.objectId) && !missing_ok)
1966  ereport(ERROR,
1967  (errcode(ERRCODE_UNDEFINED_OBJECT),
1968  errmsg("publication schema \"%s\" in publication \"%s\" does not exist",
1969  schemaname, pubname)));
1970 
1971  return address;
1972 }
@ PUBLICATIONNAMESPACEMAP
Definition: syscache.h:82

References ereport, errcode(), errmsg(), ERROR, get_namespace_oid(), GetPublicationByName(), GetSysCacheOid2, InvalidOid, linitial, lsecond, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum, Publication::oid, OidIsValid, PUBLICATIONNAMESPACEMAP, and strVal.

Referenced by get_object_address().

◆ get_object_address_relobject()

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

Definition at line 1435 of file objectaddress.c.

1437 {
1438  ObjectAddress address;
1439  Relation relation = NULL;
1440  int nnames;
1441  const char *depname;
1442  List *relname;
1443  Oid reloid;
1444 
1445  /* Extract name of dependent object. */
1446  depname = strVal(llast(object));
1447 
1448  /* Separate relation name from dependent object name. */
1449  nnames = list_length(object);
1450  if (nnames < 2)
1451  ereport(ERROR,
1452  (errcode(ERRCODE_SYNTAX_ERROR),
1453  errmsg("must specify relation and object name")));
1454 
1455  /* Extract relation name and open relation. */
1456  relname = list_truncate(list_copy(object), nnames - 1);
1459  missing_ok);
1460 
1461  reloid = relation ? RelationGetRelid(relation) : InvalidOid;
1462 
1463  switch (objtype)
1464  {
1465  case OBJECT_RULE:
1466  address.classId = RewriteRelationId;
1467  address.objectId = relation ?
1468  get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
1469  address.objectSubId = 0;
1470  break;
1471  case OBJECT_TRIGGER:
1472  address.classId = TriggerRelationId;
1473  address.objectId = relation ?
1474  get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
1475  address.objectSubId = 0;
1476  break;
1477  case OBJECT_TABCONSTRAINT:
1478  address.classId = ConstraintRelationId;
1479  address.objectId = relation ?
1480  get_relation_constraint_oid(reloid, depname, missing_ok) :
1481  InvalidOid;
1482  address.objectSubId = 0;
1483  break;
1484  case OBJECT_POLICY:
1485  address.classId = PolicyRelationId;
1486  address.objectId = relation ?
1487  get_relation_policy_oid(reloid, depname, missing_ok) :
1488  InvalidOid;
1489  address.objectSubId = 0;
1490  break;
1491  default:
1492  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1493  }
1494 
1495  /* Avoid relcache leak when object not found. */
1496  if (!OidIsValid(address.objectId))
1497  {
1498  if (relation != NULL)
1499  table_close(relation, AccessShareLock);
1500 
1501  relation = NULL; /* department of accident prevention */
1502  return address;
1503  }
1504 
1505  /* Done. */
1506  *relp = relation;
1507  return address;
1508 }
Oid get_relation_constraint_oid(Oid relid, const char *conname, bool missing_ok)
Oid get_relation_policy_oid(Oid relid, const char *policy_name, bool missing_ok)
Definition: policy.c:1210
Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok)
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
Relation table_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: table.c:132
Oid get_trigger_oid(Oid relid, const char *trigname, bool missing_ok)
Definition: trigger.c:1415

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

Referenced by get_object_address().

◆ get_object_address_rv()

ObjectAddress get_object_address_rv ( ObjectType  objtype,
RangeVar rel,
List object,
Relation relp,
LOCKMODE  lockmode,
bool  missing_ok 
)

Definition at line 1240 of file objectaddress.c.

1243 {
1244  if (rel)
1245  {
1246  object = lcons(makeString(rel->relname), object);
1247  if (rel->schemaname)
1248  object = lcons(makeString(rel->schemaname), object);
1249  if (rel->catalogname)
1250  object = lcons(makeString(rel->catalogname), object);
1251  }
1252 
1253  return get_object_address(objtype, (Node *) object,
1254  relp, lockmode, missing_ok);
1255 }
List * lcons(void *datum, List *list)
Definition: list.c:474
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
Definition: nodes.h:574
char * relname
Definition: primnodes.h:68
char * catalogname
Definition: primnodes.h:66
char * schemaname
Definition: primnodes.h:67
String * makeString(char *str)
Definition: value.c:63

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

Referenced by ExecAlterObjectDependsStmt().

◆ get_object_address_type()

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

Definition at line 1623 of file objectaddress.c.

1624 {
1625  ObjectAddress address;
1626  Type tup;
1627 
1628  address.classId = TypeRelationId;
1629  address.objectId = InvalidOid;
1630  address.objectSubId = 0;
1631 
1632  tup = LookupTypeName(NULL, typename, NULL, missing_ok);
1633  if (!HeapTupleIsValid(tup))
1634  {
1635  if (!missing_ok)
1636  ereport(ERROR,
1637  (errcode(ERRCODE_UNDEFINED_OBJECT),
1638  errmsg("type \"%s\" does not exist",
1639  TypeNameToString(typename))));
1640  return address;
1641  }
1642  address.objectId = typeTypeId(tup);
1643 
1644  if (objtype == OBJECT_DOMAIN)
1645  {
1646  if (((Form_pg_type) GETSTRUCT(tup))->typtype != TYPTYPE_DOMAIN)
1647  ereport(ERROR,
1648  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1649  errmsg("\"%s\" is not a domain",
1650  TypeNameToString(typename))));
1651  }
1652 
1653  ReleaseSysCache(tup);
1654 
1655  return address;
1656 }
Type LookupTypeName(ParseState *pstate, const TypeName *typeName, int32 *typmod_p, bool missing_ok)
Definition: parse_type.c:38
Oid typeTypeId(Type tp)
Definition: parse_type.c:592
FormData_pg_type * Form_pg_type
Definition: pg_type.h:261

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

Referenced by get_object_address(), and get_object_address_opf_member().

◆ get_object_address_unqualified()

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

Definition at line 1262 of file objectaddress.c.

1264 {
1265  const char *name;
1266  ObjectAddress address;
1267 
1268  name = strVal(strval);
1269 
1270  /* Translate name to OID. */
1271  switch (objtype)
1272  {
1273  case OBJECT_ACCESS_METHOD:
1274  address.classId = AccessMethodRelationId;
1275  address.objectId = get_am_oid(name, missing_ok);
1276  address.objectSubId = 0;
1277  break;
1278  case OBJECT_DATABASE:
1279  address.classId = DatabaseRelationId;
1280  address.objectId = get_database_oid(name, missing_ok);
1281  address.objectSubId = 0;
1282  break;
1283  case OBJECT_EXTENSION:
1284  address.classId = ExtensionRelationId;
1285  address.objectId = get_extension_oid(name, missing_ok);
1286  address.objectSubId = 0;
1287  break;
1288  case OBJECT_TABLESPACE:
1289  address.classId = TableSpaceRelationId;
1290  address.objectId = get_tablespace_oid(name, missing_ok);
1291  address.objectSubId = 0;
1292  break;
1293  case OBJECT_ROLE:
1294  address.classId = AuthIdRelationId;
1295  address.objectId = get_role_oid(name, missing_ok);
1296  address.objectSubId = 0;
1297  break;
1298  case OBJECT_SCHEMA:
1299  address.classId = NamespaceRelationId;
1300  address.objectId = get_namespace_oid(name, missing_ok);
1301  address.objectSubId = 0;
1302  break;
1303  case OBJECT_LANGUAGE:
1304  address.classId = LanguageRelationId;
1305  address.objectId = get_language_oid(name, missing_ok);
1306  address.objectSubId = 0;
1307  break;
1308  case OBJECT_FDW:
1309  address.classId = ForeignDataWrapperRelationId;
1310  address.objectId = get_foreign_data_wrapper_oid(name, missing_ok);
1311  address.objectSubId = 0;
1312  break;
1313  case OBJECT_FOREIGN_SERVER:
1314  address.classId = ForeignServerRelationId;
1315  address.objectId = get_foreign_server_oid(name, missing_ok);
1316  address.objectSubId = 0;
1317  break;
1318  case OBJECT_EVENT_TRIGGER:
1319  address.classId = EventTriggerRelationId;
1320  address.objectId = get_event_trigger_oid(name, missing_ok);
1321  address.objectSubId = 0;
1322  break;
1323  case OBJECT_PARAMETER_ACL:
1324  address.classId = ParameterAclRelationId;
1325  address.objectId = ParameterAclLookup(name, missing_ok);
1326  address.objectSubId = 0;
1327  break;
1328  case OBJECT_PUBLICATION:
1329  address.classId = PublicationRelationId;
1330  address.objectId = get_publication_oid(name, missing_ok);
1331  address.objectSubId = 0;
1332  break;
1333  case OBJECT_SUBSCRIPTION:
1334  address.classId = SubscriptionRelationId;
1335  address.objectId = get_subscription_oid(name, missing_ok);
1336  address.objectSubId = 0;
1337  break;
1338  default:
1339  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1340  /* placate compiler, which doesn't know elog won't return */
1341  address.classId = InvalidOid;
1342  address.objectId = InvalidOid;
1343  address.objectSubId = 0;
1344  }
1345 
1346  return address;
1347 }
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5177
Oid get_am_oid(const char *amname, bool missing_ok)
Definition: amcmds.c:183
Oid get_tablespace_oid(const char *tablespacename, bool missing_ok)
Definition: tablespace.c:1474
Oid get_database_oid(const char *dbname, bool missing_ok)
Definition: dbcommands.c:2947
const char * name
Definition: encode.c:561
Oid get_event_trigger_oid(const char *trigname, bool missing_ok)
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:140
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition: foreign.c:682
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition: foreign.c:659
Oid ParameterAclLookup(const char *parameter, bool missing_ok)
Oid get_publication_oid(const char *pubname, bool missing_ok)
Oid get_subscription_oid(const char *subname, bool missing_ok)

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

Referenced by get_object_address().

◆ get_object_address_usermapping()

static ObjectAddress get_object_address_usermapping ( List object,
bool  missing_ok 
)
static

Definition at line 1812 of file objectaddress.c.

1813 {
1814  ObjectAddress address;
1815  Oid userid;
1816  char *username;
1817  char *servername;
1818  ForeignServer *server;
1819  HeapTuple tp;
1820 
1821  ObjectAddressSet(address, UserMappingRelationId, InvalidOid);
1822 
1823  /* fetch string names from input lists, for error messages */
1824  username = strVal(linitial(object));
1825  servername = strVal(lsecond(object));
1826 
1827  /* look up pg_authid OID of mapped user; InvalidOid if PUBLIC */
1828  if (strcmp(username, "public") == 0)
1829  userid = InvalidOid;
1830  else
1831  {
1834  if (!HeapTupleIsValid(tp))
1835  {
1836  if (!missing_ok)
1837  ereport(ERROR,
1838  (errcode(ERRCODE_UNDEFINED_OBJECT),
1839  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1840  username, servername)));
1841  return address;
1842  }
1843  userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
1844  ReleaseSysCache(tp);
1845  }
1846 
1847  /* Now look up the pg_user_mapping tuple */
1848  server = GetForeignServerByName(servername, true);
1849  if (!server)
1850  {
1851  if (!missing_ok)
1852  ereport(ERROR,
1853  (errcode(ERRCODE_UNDEFINED_OBJECT),
1854  errmsg("server \"%s\" does not exist", servername)));
1855  return address;
1856  }
1857  tp = SearchSysCache2(USERMAPPINGUSERSERVER,
1858  ObjectIdGetDatum(userid),
1859  ObjectIdGetDatum(server->serverid));
1860  if (!HeapTupleIsValid(tp))
1861  {
1862  if (!missing_ok)
1863  ereport(ERROR,
1864  (errcode(ERRCODE_UNDEFINED_OBJECT),
1865  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1866  username, servername)));
1867  return address;
1868  }
1869 
1870  address.objectId = ((Form_pg_user_mapping) GETSTRUCT(tp))->oid;
1871 
1872  ReleaseSysCache(tp);
1873 
1874  return address;
1875 }
ForeignServer * GetForeignServerByName(const char *srvname, bool missing_ok)
Definition: foreign.c:181
FormData_pg_user_mapping * Form_pg_user_mapping
Oid serverid
Definition: foreign.h:36
HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)
Definition: syscache.c:1184

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

Referenced by get_object_address().

◆ get_object_attnum_acl()

AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 2753 of file objectaddress.c.

2754 {
2755  const ObjectPropertyType *prop = get_object_property_data(class_id);
2756 
2757  return prop->attnum_acl;
2758 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_acl

References ObjectPropertyType::attnum_acl, and get_object_property_data().

Referenced by AlterObjectOwner_internal().

◆ get_object_attnum_name()

AttrNumber get_object_attnum_name ( Oid  class_id)

◆ get_object_attnum_namespace()

◆ get_object_attnum_oid()

AttrNumber get_object_attnum_oid ( Oid  class_id)

◆ get_object_attnum_owner()

AttrNumber get_object_attnum_owner ( Oid  class_id)

Definition at line 2745 of file objectaddress.c.

2746 {
2747  const ObjectPropertyType *prop = get_object_property_data(class_id);
2748 
2749  return prop->attnum_owner;
2750 }
AttrNumber attnum_owner

References ObjectPropertyType::attnum_owner, and get_object_property_data().

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

◆ get_object_catcache_name()

int get_object_catcache_name ( Oid  class_id)

Definition at line 2713 of file objectaddress.c.

2714 {
2715  const ObjectPropertyType *prop = get_object_property_data(class_id);
2716 
2717  return prop->name_catcache_id;
2718 }

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

◆ get_object_catcache_oid()

int get_object_catcache_oid ( Oid  class_id)

◆ get_object_class_descr()

const char* get_object_class_descr ( Oid  class_id)

Definition at line 2689 of file objectaddress.c.

2690 {
2691  const ObjectPropertyType *prop = get_object_property_data(class_id);
2692 
2693  return prop->class_descr;
2694 }
const char * class_descr

References ObjectPropertyType::class_descr, and get_object_property_data().

Referenced by DropObjectById().

◆ get_object_namensp_unique()

bool get_object_namensp_unique ( Oid  class_id)

Definition at line 2786 of file objectaddress.c.

2787 {
2788  const ObjectPropertyType *prop = get_object_property_data(class_id);
2789 
2790  return prop->is_nsp_name_unique;
2791 }

References get_object_property_data(), and ObjectPropertyType::is_nsp_name_unique.

Referenced by EventTriggerSQLDropAddObject(), and pg_identify_object().

◆ get_object_namespace()

Oid get_object_namespace ( const ObjectAddress address)

Definition at line 2630 of file objectaddress.c.

2631 {
2632  int cache;
2633  HeapTuple tuple;
2634  bool isnull;
2635  Oid oid;
2636  const ObjectPropertyType *property;
2637 
2638  /* If not owned by a namespace, just return InvalidOid. */
2639  property = get_object_property_data(address->classId);
2640  if (property->attnum_namespace == InvalidAttrNumber)
2641  return InvalidOid;
2642 
2643  /* Currently, we can only handle object types with system caches. */
2644  cache = property->oid_catcache_id;
2645  Assert(cache != -1);
2646 
2647  /* Fetch tuple from syscache and extract namespace attribute. */
2648  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2649  if (!HeapTupleIsValid(tuple))
2650  elog(ERROR, "cache lookup failed for cache %d oid %u",
2651  cache, address->objectId);
2652  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2653  tuple,
2654  property->attnum_namespace,
2655  &isnull));
2656  Assert(!isnull);
2657  ReleaseSysCache(tuple);
2658 
2659  return oid;
2660 }
#define DatumGetObjectId(X)
Definition: postgres.h:544
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1434

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

◆ get_object_oid_index()

Oid get_object_oid_index ( Oid  class_id)

Definition at line 2697 of file objectaddress.c.

2698 {
2699  const ObjectPropertyType *prop = get_object_property_data(class_id);
2700 
2701  return prop->oid_index_oid;
2702 }

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by DropObjectById(), and get_catalog_object_by_oid().

◆ get_object_property_data()

static const ObjectPropertyType * get_object_property_data ( Oid  class_id)
static

Definition at line 2815 of file objectaddress.c.

2816 {
2817  static const ObjectPropertyType *prop_last = NULL;
2818  int index;
2819 
2820  /*
2821  * A shortcut to speed up multiple consecutive lookups of a particular
2822  * object class.
2823  */
2824  if (prop_last && prop_last->class_oid == class_id)
2825  return prop_last;
2826 
2827  for (index = 0; index < lengthof(ObjectProperty); index++)
2828  {
2829  if (ObjectProperty[index].class_oid == class_id)
2830  {
2831  prop_last = &ObjectProperty[index];
2832  return &ObjectProperty[index];
2833  }
2834  }
2835 
2836  ereport(ERROR,
2837  (errmsg_internal("unrecognized class ID: %u", class_id)));
2838 
2839  return NULL; /* keep MSC compiler happy */
2840 }
#define lengthof(array)
Definition: c.h:734
int errmsg_internal(const char *fmt,...)
Definition: elog.c:991
static const ObjectPropertyType ObjectProperty[]
Definition: type.h:90

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

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

◆ get_object_type()

ObjectType get_object_type ( Oid  class_id,
Oid  object_id 
)

Definition at line 2768 of file objectaddress.c.

2769 {
2770  const ObjectPropertyType *prop = get_object_property_data(class_id);
2771 
2772  if (prop->objtype == OBJECT_TABLE)
2773  {
2774  /*
2775  * If the property data says it's a table, dig a little deeper to get
2776  * the real relation kind, so that callers can produce more precise
2777  * error messages.
2778  */
2779  return get_relkind_objtype(get_rel_relkind(object_id));
2780  }
2781  else
2782  return prop->objtype;
2783 }
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1984
ObjectType get_relkind_objtype(char relkind)

References get_object_property_data(), get_rel_relkind(), get_relkind_objtype(), OBJECT_TABLE, and ObjectPropertyType::objtype.

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

◆ get_relation_by_qualified_name()

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

Definition at line 1353 of file objectaddress.c.

1356 {
1357  Relation relation;
1358  ObjectAddress address;
1359 
1360  address.classId = RelationRelationId;
1361  address.objectId = InvalidOid;
1362  address.objectSubId = 0;
1363 
1365  lockmode, missing_ok);
1366  if (!relation)
1367  return address;
1368 
1369  switch (objtype)
1370  {
1371  case OBJECT_INDEX:
1372  if (relation->rd_rel->relkind != RELKIND_INDEX &&
1373  relation->rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
1374  ereport(ERROR,
1375  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1376  errmsg("\"%s\" is not an index",
1377  RelationGetRelationName(relation))));
1378  break;
1379  case OBJECT_SEQUENCE:
1380  if (relation->rd_rel->relkind != RELKIND_SEQUENCE)
1381  ereport(ERROR,
1382  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1383  errmsg("\"%s\" is not a sequence",
1384  RelationGetRelationName(relation))));
1385  break;
1386  case OBJECT_TABLE:
1387  if (relation->rd_rel->relkind != RELKIND_RELATION &&
1388  relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1389  ereport(ERROR,
1390  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1391  errmsg("\"%s\" is not a table",
1392  RelationGetRelationName(relation))));
1393  break;
1394  case OBJECT_VIEW:
1395  if (relation->rd_rel->relkind != RELKIND_VIEW)
1396  ereport(ERROR,
1397  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1398  errmsg("\"%s\" is not a view",
1399  RelationGetRelationName(relation))));
1400  break;
1401  case OBJECT_MATVIEW:
1402  if (relation->rd_rel->relkind != RELKIND_MATVIEW)
1403  ereport(ERROR,
1404  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1405  errmsg("\"%s\" is not a materialized view",
1406  RelationGetRelationName(relation))));
1407  break;
1408  case OBJECT_FOREIGN_TABLE:
1409  if (relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE)
1410  ereport(ERROR,
1411  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1412  errmsg("\"%s\" is not a foreign table",
1413  RelationGetRelationName(relation))));
1414  break;
1415  default:
1416  elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1417  break;
1418  }
1419 
1420  /* Done. */
1421  address.objectId = RelationGetRelid(relation);
1422  *relp = relation;
1423 
1424  return address;
1425 }
Form_pg_class rd_rel
Definition: rel.h:109

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

Referenced by get_object_address().

◆ get_relkind_objtype()

ObjectType get_relkind_objtype ( char  relkind)

Definition at line 6072 of file objectaddress.c.

6073 {
6074  switch (relkind)
6075  {
6076  case RELKIND_RELATION:
6077  case RELKIND_PARTITIONED_TABLE:
6078  return OBJECT_TABLE;
6079  case RELKIND_INDEX:
6080  case RELKIND_PARTITIONED_INDEX:
6081  return OBJECT_INDEX;
6082  case RELKIND_SEQUENCE:
6083  return OBJECT_SEQUENCE;
6084  case RELKIND_VIEW:
6085  return OBJECT_VIEW;
6086  case RELKIND_MATVIEW:
6087  return OBJECT_MATVIEW;
6088  case RELKIND_FOREIGN_TABLE:
6089  return OBJECT_FOREIGN_TABLE;
6090  case RELKIND_TOASTVALUE:
6091  return OBJECT_TABLE;
6092  default:
6093  /* Per above, don't raise an error */
6094  return OBJECT_TABLE;
6095  }
6096 }

References OBJECT_FOREIGN_TABLE, OBJECT_INDEX, OBJECT_MATVIEW, OBJECT_SEQUENCE, OBJECT_TABLE, and OBJECT_VIEW.

Referenced by AlterTableMoveAll(), ATExecChangeOwner(), ATSimplePermissions(), checkFkeyPermissions(), CreateStatistics(), CreateTriggerFiringOn(), currtid_internal(), DefineQueryRewrite(), EnableDisableRule(), ExecCheckRTPerms(), get_object_type(), get_rel_from_relname(), heap_force_common(), LockViewRecurse_walker(), LogicalRepSyncTableStart(), MergeAttributes(), pg_prewarm(), pgrowlocks(), PublicationAddTables(), RangeVarCallbackForAlterRelation(), RangeVarCallbackForDropRelation(), RangeVarCallbackForLockTable(), RangeVarCallbackForPolicy(), RangeVarCallbackForRenameRule(), RangeVarCallbackForRenameTrigger(), RangeVarCallbackOwnsRelation(), RangeVarCallbackOwnsTable(), RangeVarGetAndCheckCreationNamespace(), renameatt_check(), TargetPrivilegesCheck(), transformTableLikeClause(), and truncate_check_perms().

◆ getConstraintTypeDescription()

static void getConstraintTypeDescription ( StringInfo  buffer,
Oid  constroid,
bool  missing_ok 
)
static

Definition at line 4679 of file objectaddress.c.

4680 {
4681  Relation constrRel;
4682  HeapTuple constrTup;
4683  Form_pg_constraint constrForm;
4684 
4685  constrRel = table_open(ConstraintRelationId, AccessShareLock);
4686  constrTup = get_catalog_object_by_oid(constrRel, Anum_pg_constraint_oid,
4687  constroid);
4688  if (!HeapTupleIsValid(constrTup))
4689  {
4690  if (!missing_ok)
4691  elog(ERROR, "cache lookup failed for constraint %u", constroid);
4692 
4693  table_close(constrRel, AccessShareLock);
4694 
4695  /* fallback to "constraint" for an undefined object */
4696  appendStringInfoString(buffer, "constraint");
4697  return;
4698  }
4699 
4700  constrForm = (Form_pg_constraint) GETSTRUCT(constrTup);
4701 
4702  if (OidIsValid(constrForm->conrelid))
4703  appendStringInfoString(buffer, "table constraint");
4704  else if (OidIsValid(constrForm->contypid))
4705  appendStringInfoString(buffer, "domain constraint");
4706  else
4707  elog(ERROR, "invalid constraint %u", constrForm->oid);
4708 
4709  table_close(constrRel, AccessShareLock);
4710 }
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

References AccessShareLock, appendStringInfoString(), elog, ERROR, get_catalog_object_by_oid(), GETSTRUCT, HeapTupleIsValid, OidIsValid, table_close(), and table_open().

Referenced by getObjectTypeDescription().

◆ getObjectDescription()

char* getObjectDescription ( const ObjectAddress object,
bool  missing_ok 
)

Definition at line 2947 of file objectaddress.c.

2948 {
2949  StringInfoData buffer;
2950 
2951  initStringInfo(&buffer);
2952 
2953  switch (getObjectClass(object))
2954  {
2955  case OCLASS_CLASS:
2956  if (object->objectSubId == 0)
2957  getRelationDescription(&buffer, object->objectId, missing_ok);
2958  else
2959  {
2960  /* column, not whole relation */
2961  StringInfoData rel;
2962  char *attname = get_attname(object->objectId,
2963  object->objectSubId,
2964  missing_ok);
2965 
2966  if (!attname)
2967  break;
2968 
2969  initStringInfo(&rel);
2970  getRelationDescription(&rel, object->objectId, missing_ok);
2971  /* translator: second %s is, e.g., "table %s" */
2972  appendStringInfo(&buffer, _("column %s of %s"),
2973  attname, rel.data);
2974  pfree(rel.data);
2975  }
2976  break;
2977 
2978  case OCLASS_PROC:
2979  {
2981  char *proname = format_procedure_extended(object->objectId,
2982  flags);
2983 
2984  if (proname == NULL)
2985  break;
2986 
2987  appendStringInfo(&buffer, _("function %s"), proname);
2988  break;
2989  }
2990 
2991  case OCLASS_TYPE:
2992  {
2994  char *typname = format_type_extended(object->objectId, -1,
2995  flags);
2996 
2997  if (typname == NULL)
2998  break;
2999 
3000  appendStringInfo(&buffer, _("type %s"), typname);
3001  break;
3002  }
3003 
3004  case OCLASS_CAST:
3005  {
3006  Relation castDesc;
3007  ScanKeyData skey[1];
3008  SysScanDesc rcscan;
3009  HeapTuple tup;
3010  Form_pg_cast castForm;
3011 
3012  castDesc = table_open(CastRelationId, AccessShareLock);
3013 
3014  ScanKeyInit(&skey[0],
3015  Anum_pg_cast_oid,
3016  BTEqualStrategyNumber, F_OIDEQ,
3017  ObjectIdGetDatum(object->objectId));
3018 
3019  rcscan = systable_beginscan(castDesc, CastOidIndexId, true,
3020  NULL, 1, skey);
3021 
3022  tup = systable_getnext(rcscan);
3023 
3024  if (!HeapTupleIsValid(tup))
3025  {
3026  if (!missing_ok)
3027  elog(ERROR, "could not find tuple for cast %u",
3028  object->objectId);
3029 
3030  systable_endscan(rcscan);
3031  table_close(castDesc, AccessShareLock);
3032  break;
3033  }
3034 
3035  castForm = (Form_pg_cast) GETSTRUCT(tup);
3036 
3037  appendStringInfo(&buffer, _("cast from %s to %s"),
3038  format_type_be(castForm->castsource),
3039  format_type_be(castForm->casttarget));
3040 
3041  systable_endscan(rcscan);
3042  table_close(castDesc, AccessShareLock);
3043  break;
3044  }
3045 
3046  case OCLASS_COLLATION:
3047  {
3048  HeapTuple collTup;
3049  Form_pg_collation coll;
3050  char *nspname;
3051 
3052  collTup = SearchSysCache1(COLLOID,
3053  ObjectIdGetDatum(object->objectId));
3054  if (!HeapTupleIsValid(collTup))
3055  {
3056  if (!missing_ok)
3057  elog(ERROR, "cache lookup failed for collation %u",
3058  object->objectId);
3059  break;
3060  }
3061 
3062  coll = (Form_pg_collation) GETSTRUCT(collTup);
3063 
3064  /* Qualify the name if not visible in search path */
3065  if (CollationIsVisible(object->objectId))
3066  nspname = NULL;
3067  else
3068  nspname = get_namespace_name(coll->collnamespace);
3069 
3070  appendStringInfo(&buffer, _("collation %s"),
3072  NameStr(coll->collname)));
3073  ReleaseSysCache(collTup);
3074  break;
3075  }
3076 
3077  case OCLASS_CONSTRAINT:
3078  {
3079  HeapTuple conTup;
3080  Form_pg_constraint con;
3081 
3082  conTup = SearchSysCache1(CONSTROID,
3083  ObjectIdGetDatum(object->objectId));
3084  if (!HeapTupleIsValid(conTup))
3085  {
3086  if (!missing_ok)
3087  elog(ERROR, "cache lookup failed for constraint %u",
3088  object->objectId);
3089  break;
3090  }
3091 
3092  con = (Form_pg_constraint) GETSTRUCT(conTup);
3093 
3094  if (OidIsValid(con->conrelid))
3095  {
3096  StringInfoData rel;
3097 
3098  initStringInfo(&rel);
3099  getRelationDescription(&rel, con->conrelid, false);
3100  /* translator: second %s is, e.g., "table %s" */
3101  appendStringInfo(&buffer, _("constraint %s on %s"),
3102  NameStr(con->conname), rel.data);
3103  pfree(rel.data);
3104  }
3105  else
3106  {
3107  appendStringInfo(&buffer, _("constraint %s"),
3108  NameStr(con->conname));
3109  }
3110 
3111  ReleaseSysCache(conTup);
3112  break;
3113  }
3114 
3115  case OCLASS_CONVERSION:
3116  {
3117  HeapTuple conTup;
3118  Form_pg_conversion conv;
3119  char *nspname;
3120 
3121  conTup = SearchSysCache1(CONVOID,
3122  ObjectIdGetDatum(object->objectId));
3123  if (!HeapTupleIsValid(conTup))
3124  {
3125  if (!missing_ok)
3126  elog(ERROR, "cache lookup failed for conversion %u",
3127  object->objectId);
3128  break;
3129  }
3130 
3131  conv = (Form_pg_conversion) GETSTRUCT(conTup);
3132 
3133  /* Qualify the name if not visible in search path */
3134  if (ConversionIsVisible(object->objectId))
3135  nspname = NULL;
3136  else
3137  nspname = get_namespace_name(conv->connamespace);
3138 
3139  appendStringInfo(&buffer, _("conversion %s"),
3141  NameStr(conv->conname)));
3142  ReleaseSysCache(conTup);
3143  break;
3144  }
3145 
3146  case OCLASS_DEFAULT:
3147  {
3148  ObjectAddress colobject;
3149 
3150  colobject = GetAttrDefaultColumnAddress(object->objectId);
3151 
3152  if (!OidIsValid(colobject.objectId))
3153  {
3154  if (!missing_ok)
3155  elog(ERROR, "could not find tuple for attrdef %u",
3156  object->objectId);
3157  break;
3158  }
3159 
3160  /* translator: %s is typically "column %s of table %s" */
3161  appendStringInfo(&buffer, _("default value for %s"),
3162  getObjectDescription(&colobject, false));
3163  break;
3164  }
3165 
3166  case OCLASS_LANGUAGE:
3167  {
3168  char *langname = get_language_name(object->objectId,
3169  missing_ok);
3170 
3171  if (langname)
3172  appendStringInfo(&buffer, _("language %s"),
3173  get_language_name(object->objectId, false));
3174  break;
3175  }
3176 
3177  case OCLASS_LARGEOBJECT:
3178  if (!LargeObjectExists(object->objectId))
3179  break;
3180  appendStringInfo(&buffer, _("large object %u"),
3181  object->objectId);
3182  break;
3183 
3184  case OCLASS_OPERATOR:
3185  {
3187  char *oprname = format_operator_extended(object->objectId,
3188  flags);
3189 
3190  if (oprname == NULL)
3191  break;
3192 
3193  appendStringInfo(&buffer, _("operator %s"), oprname);
3194  break;
3195  }
3196 
3197  case OCLASS_OPCLASS:
3198  {
3199  HeapTuple opcTup;
3200  Form_pg_opclass opcForm;
3201  HeapTuple amTup;
3202  Form_pg_am amForm;
3203  char *nspname;
3204 
3205  opcTup = SearchSysCache1(CLAOID,
3206  ObjectIdGetDatum(object->objectId));
3207  if (!HeapTupleIsValid(opcTup))
3208  {
3209  if (!missing_ok)
3210  elog(ERROR, "cache lookup failed for opclass %u",
3211  object->objectId);
3212  break;
3213  }
3214 
3215  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
3216 
3217  amTup = SearchSysCache1(AMOID,
3218  ObjectIdGetDatum(opcForm->opcmethod));
3219  if (!HeapTupleIsValid(amTup))
3220  elog(ERROR, "cache lookup failed for access method %u",
3221  opcForm->opcmethod);
3222  amForm = (Form_pg_am) GETSTRUCT(amTup);
3223 
3224  /* Qualify the name if not visible in search path */
3225  if (OpclassIsVisible(object->objectId))
3226  nspname = NULL;
3227  else
3228  nspname = get_namespace_name(opcForm->opcnamespace);
3229 
3230  appendStringInfo(&buffer, _("operator class %s for access method %s"),
3232  NameStr(opcForm->opcname)),
3233  NameStr(amForm->amname));
3234 
3235  ReleaseSysCache(amTup);
3236  ReleaseSysCache(opcTup);
3237  break;
3238  }
3239 
3240  case OCLASS_OPFAMILY:
3241  getOpFamilyDescription(&buffer, object->objectId, missing_ok);
3242  break;
3243 
3244  case OCLASS_AM:
3245  {
3246  HeapTuple tup;
3247 
3248  tup = SearchSysCache1(AMOID,
3249  ObjectIdGetDatum(object->objectId));
3250  if (!HeapTupleIsValid(tup))
3251  {
3252  if (!missing_ok)
3253  elog(ERROR, "cache lookup failed for access method %u",
3254  object->objectId);
3255  break;
3256  }
3257 
3258  appendStringInfo(&buffer, _("access method %s"),
3259  NameStr(((Form_pg_am) GETSTRUCT(tup))->amname));
3260  ReleaseSysCache(tup);
3261  break;
3262  }
3263 
3264  case OCLASS_AMOP:
3265  {
3266  Relation amopDesc;
3267  HeapTuple tup;
3268  ScanKeyData skey[1];
3269  SysScanDesc amscan;
3270  Form_pg_amop amopForm;
3271  StringInfoData opfam;
3272 
3273  amopDesc = table_open(AccessMethodOperatorRelationId,
3274  AccessShareLock);
3275 
3276  ScanKeyInit(&skey[0],
3277  Anum_pg_amop_oid,
3278  BTEqualStrategyNumber, F_OIDEQ,
3279  ObjectIdGetDatum(object->objectId));
3280 
3281  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
3282  NULL, 1, skey);
3283 
3284  tup = systable_getnext(amscan);
3285 
3286  if (!HeapTupleIsValid(tup))
3287  {
3288  if (!missing_ok)
3289  elog(ERROR, "could not find tuple for amop entry %u",
3290  object->objectId);
3291 
3292  systable_endscan(amscan);
3293  table_close(amopDesc, AccessShareLock);
3294  break;
3295  }
3296 
3297  amopForm = (Form_pg_amop) GETSTRUCT(tup);
3298 
3299  initStringInfo(&opfam);
3300  getOpFamilyDescription(&opfam, amopForm->amopfamily, false);
3301 
3302  /*------
3303  translator: %d is the operator strategy (a number), the
3304  first two %s's are data type names, the third %s is the
3305  description of the operator family, and the last %s is the
3306  textual form of the operator with arguments. */
3307  appendStringInfo(&buffer, _("operator %d (%s, %s) of %s: %s"),
3308  amopForm->amopstrategy,
3309  format_type_be(amopForm->amoplefttype),
3310  format_type_be(amopForm->amoprighttype),
3311  opfam.data,
3312  format_operator(amopForm->amopopr));
3313 
3314  pfree(opfam.data);
3315 
3316  systable_endscan(amscan);
3317  table_close(amopDesc, AccessShareLock);
3318  break;
3319  }
3320 
3321  case OCLASS_AMPROC:
3322  {
3323  Relation amprocDesc;
3324  ScanKeyData skey[1];
3325  SysScanDesc amscan;
3326  HeapTuple tup;
3327  Form_pg_amproc amprocForm;
3328  StringInfoData opfam;
3329 
3330  amprocDesc = table_open(AccessMethodProcedureRelationId,
3331  AccessShareLock);
3332 
3333  ScanKeyInit(&skey[0],
3334  Anum_pg_amproc_oid,
3335  BTEqualStrategyNumber, F_OIDEQ,
3336  ObjectIdGetDatum(object->objectId));
3337 
3338  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
3339  NULL, 1, skey);
3340 
3341  tup = systable_getnext(amscan);
3342 
3343  if (!HeapTupleIsValid(tup))
3344  {
3345  if (!missing_ok)
3346  elog(ERROR, "could not find tuple for amproc entry %u",
3347  object->objectId);
3348 
3349  systable_endscan(amscan);
3350  table_close(amprocDesc, AccessShareLock);
3351  break;
3352  }
3353 
3354  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
3355 
3356  initStringInfo(&opfam);
3357  getOpFamilyDescription(&opfam, amprocForm->amprocfamily, false);
3358 
3359  /*------
3360  translator: %d is the function number, the first two %s's
3361  are data type names, the third %s is the description of the
3362  operator family, and the last %s is the textual form of the
3363  function with arguments. */
3364  appendStringInfo(&buffer, _("function %d (%s, %s) of %s: %s"),
3365  amprocForm->amprocnum,
3366  format_type_be(amprocForm->amproclefttype),
3367  format_type_be(amprocForm->amprocrighttype),
3368  opfam.data,
3369  format_procedure(amprocForm->amproc));
3370 
3371  pfree(opfam.data);
3372 
3373  systable_endscan(amscan);
3374  table_close(amprocDesc, AccessShareLock);
3375  break;
3376  }
3377 
3378  case OCLASS_REWRITE:
3379  {
3380  Relation ruleDesc;
3381  ScanKeyData skey[1];
3382  SysScanDesc rcscan;
3383  HeapTuple tup;
3385  StringInfoData rel;
3386 
3387  ruleDesc = table_open(RewriteRelationId, AccessShareLock);
3388 
3389  ScanKeyInit(&skey[0],
3390  Anum_pg_rewrite_oid,
3391  BTEqualStrategyNumber, F_OIDEQ,
3392  ObjectIdGetDatum(object->objectId));
3393 
3394  rcscan = systable_beginscan(ruleDesc, RewriteOidIndexId, true,
3395  NULL, 1, skey);
3396 
3397  tup = systable_getnext(rcscan);
3398 
3399  if (!HeapTupleIsValid(tup))
3400  {
3401  if (!missing_ok)
3402  elog(ERROR, "could not find tuple for rule %u",
3403  object->objectId);
3404 
3405  systable_endscan(rcscan);
3406  table_close(ruleDesc, AccessShareLock);
3407  break;
3408  }
3409 
3410  rule = (Form_pg_rewrite) GETSTRUCT(tup);
3411 
3412  initStringInfo(&rel);
3413  getRelationDescription(&rel, rule->ev_class, false);
3414 
3415  /* translator: second %s is, e.g., "table %s" */
3416  appendStringInfo(&buffer, _("rule %s on %s"),
3417  NameStr(rule->rulename), rel.data);
3418  pfree(rel.data);
3419  systable_endscan(rcscan);
3420  table_close(ruleDesc, AccessShareLock);
3421  break;
3422  }
3423 
3424  case OCLASS_TRIGGER:
3425  {
3426  Relation trigDesc;
3427  ScanKeyData skey[1];
3428  SysScanDesc tgscan;
3429  HeapTuple tup;
3430  Form_pg_trigger trig;
3431  StringInfoData rel;
3432 
3433  trigDesc = table_open(TriggerRelationId, AccessShareLock);
3434 
3435  ScanKeyInit(&skey[0],
3436  Anum_pg_trigger_oid,
3437  BTEqualStrategyNumber, F_OIDEQ,
3438  ObjectIdGetDatum(object->objectId));
3439 
3440  tgscan = systable_beginscan(trigDesc, TriggerOidIndexId, true,
3441  NULL, 1, skey);
3442 
3443  tup = systable_getnext(tgscan);
3444 
3445  if (!HeapTupleIsValid(tup))
3446  {
3447  if (!missing_ok)
3448  elog(ERROR, "could not find tuple for trigger %u",
3449  object->objectId);
3450 
3451  systable_endscan(tgscan);
3452  table_close(trigDesc, AccessShareLock);
3453  break;
3454  }
3455 
3456  trig = (Form_pg_trigger) GETSTRUCT(tup);
3457 
3458  initStringInfo(&rel);
3459  getRelationDescription(&rel, trig->tgrelid, false);
3460 
3461  /* translator: second %s is, e.g., "table %s" */
3462  appendStringInfo(&buffer, _("trigger %s on %s"),
3463  NameStr(trig->tgname), rel.data);
3464  pfree(rel.data);
3465  systable_endscan(tgscan);
3466  table_close(trigDesc, AccessShareLock);
3467  break;
3468  }
3469 
3470  case OCLASS_SCHEMA:
3471  {
3472  char *nspname;
3473 
3474  nspname = get_namespace_name(object->objectId);
3475  if (!nspname)
3476  {
3477  if (!missing_ok)
3478  elog(ERROR, "cache lookup failed for namespace %u",
3479  object->objectId);
3480  break;
3481  }
3482  appendStringInfo(&buffer, _("schema %s"), nspname);
3483  break;
3484  }
3485 
3486  case OCLASS_STATISTIC_EXT:
3487  {
3488  HeapTuple stxTup;
3489  Form_pg_statistic_ext stxForm;
3490  char *nspname;
3491 
3492  stxTup = SearchSysCache1(STATEXTOID,
3493  ObjectIdGetDatum(object->objectId));
3494  if (!HeapTupleIsValid(stxTup))
3495  {
3496  if (!missing_ok)
3497  elog(ERROR, "could not find tuple for statistics object %u",
3498  object->objectId);
3499  break;
3500  }
3501 
3502  stxForm = (Form_pg_statistic_ext) GETSTRUCT(stxTup);
3503 
3504  /* Qualify the name if not visible in search path */
3505  if (StatisticsObjIsVisible(object->objectId))
3506  nspname = NULL;
3507  else
3508  nspname = get_namespace_name(stxForm->stxnamespace);
3509 
3510  appendStringInfo(&buffer, _("statistics object %s"),
3512  NameStr(stxForm->stxname)));
3513 
3514  ReleaseSysCache(stxTup);
3515  break;
3516  }
3517 
3518  case OCLASS_TSPARSER:
3519  {
3520  HeapTuple tup;
3521  Form_pg_ts_parser prsForm;
3522  char *nspname;
3523 
3525  ObjectIdGetDatum(object->objectId));
3526  if (!HeapTupleIsValid(tup))
3527  {
3528  if (!missing_ok)
3529  elog(ERROR, "cache lookup failed for text search parser %u",
3530  object->objectId);
3531  break;
3532  }
3533  prsForm = (Form_pg_ts_parser) GETSTRUCT(tup);
3534 
3535  /* Qualify the name if not visible in search path */
3536  if (TSParserIsVisible(object->objectId))
3537  nspname = NULL;
3538  else
3539  nspname = get_namespace_name(prsForm->prsnamespace);
3540 
3541  appendStringInfo(&buffer, _("text search parser %s"),
3543  NameStr(prsForm->prsname)));
3544  ReleaseSysCache(tup);
3545  break;
3546  }
3547 
3548  case OCLASS_TSDICT:
3549  {
3550  HeapTuple tup;
3551  Form_pg_ts_dict dictForm;
3552  char *nspname;
3553 
3554  tup = SearchSysCache1(TSDICTOID,
3555  ObjectIdGetDatum(object->objectId));
3556  if (!HeapTupleIsValid(tup))
3557  {
3558  if (!missing_ok)
3559  elog(ERROR, "cache lookup failed for text search dictionary %u",
3560  object->objectId);
3561  break;
3562  }
3563 
3564  dictForm = (Form_pg_ts_dict) GETSTRUCT(tup);
3565 
3566  /* Qualify the name if not visible in search path */
3567  if (TSDictionaryIsVisible(object->objectId))
3568  nspname = NULL;
3569  else
3570  nspname = get_namespace_name(dictForm->dictnamespace);
3571 
3572  appendStringInfo(&buffer, _("text search dictionary %s"),
3574  NameStr(dictForm->dictname)));
3575  ReleaseSysCache(tup);
3576  break;
3577  }
3578 
3579  case OCLASS_TSTEMPLATE:
3580  {
3581  HeapTuple tup;
3582  Form_pg_ts_template tmplForm;
3583  char *nspname;
3584 
3586  ObjectIdGetDatum(object->objectId));
3587  if (!HeapTupleIsValid(tup))
3588  {
3589  if (!missing_ok)
3590  elog(ERROR, "cache lookup failed for text search template %u",
3591  object->objectId);
3592  break;
3593  }
3594 
3595  tmplForm = (Form_pg_ts_template) GETSTRUCT(tup);
3596 
3597  /* Qualify the name if not visible in search path */
3598  if (TSTemplateIsVisible(object->objectId))
3599  nspname = NULL;
3600  else
3601  nspname = get_namespace_name(tmplForm->tmplnamespace);
3602 
3603  appendStringInfo(&buffer, _("text search template %s"),
3605  NameStr(tmplForm->tmplname)));
3606  ReleaseSysCache(tup);
3607  break;
3608  }
3609 
3610  case OCLASS_TSCONFIG:
3611  {
3612  HeapTuple tup;
3613  Form_pg_ts_config cfgForm;
3614  char *nspname;
3615 
3617  ObjectIdGetDatum(object->objectId));
3618  if (!HeapTupleIsValid(tup))
3619  {
3620  if (!missing_ok)
3621  elog(ERROR, "cache lookup failed for text search configuration %u",
3622  object->objectId);
3623  break;
3624  }
3625 
3626  cfgForm = (Form_pg_ts_config) GETSTRUCT(tup);
3627 
3628  /* Qualify the name if not visible in search path */
3629  if (TSConfigIsVisible(object->objectId))
3630  nspname = NULL;
3631  else
3632  nspname = get_namespace_name(cfgForm->cfgnamespace);
3633 
3634  appendStringInfo(&buffer, _("text search configuration %s"),
3636  NameStr(cfgForm->cfgname)));
3637  ReleaseSysCache(tup);
3638  break;
3639  }
3640 
3641  case OCLASS_ROLE:
3642  {
3643  char *username = GetUserNameFromId(object->objectId,
3644  missing_ok);
3645 
3646  if (username)
3647  appendStringInfo(&buffer, _("role %s"), username);
3648  break;
3649  }
3650 
3651  case OCLASS_DATABASE:
3652  {
3653  char *datname;
3654 
3655  datname = get_database_name(object->objectId);
3656  if (!datname)
3657  {
3658  if (!missing_ok)
3659  elog(ERROR, "cache lookup failed for database %u",
3660  object->objectId);
3661  break;
3662  }
3663  appendStringInfo(&buffer, _("database %s"), datname);
3664  break;
3665  }
3666 
3667  case OCLASS_TBLSPACE:
3668  {
3669  char *tblspace;
3670 
3671  tblspace = get_tablespace_name(object->objectId);
3672  if (!tblspace)
3673  {
3674  if (!missing_ok)
3675  elog(ERROR, "cache lookup failed for tablespace %u",
3676  object->objectId);
3677  break;
3678  }
3679  appendStringInfo(&buffer, _("tablespace %s"), tblspace);
3680  break;
3681  }
3682 
3683  case OCLASS_FDW:
3684  {
3685  ForeignDataWrapper *fdw;
3686 
3688  missing_ok);
3689  if (fdw)
3690  appendStringInfo(&buffer, _("foreign-data wrapper %s"), fdw->fdwname);
3691  break;
3692  }
3693 
3694  case OCLASS_FOREIGN_SERVER:
3695  {
3696  ForeignServer *srv;
3697 
3698  srv = GetForeignServerExtended(object->objectId, missing_ok);
3699  if (srv)
3700  appendStringInfo(&buffer, _("server %s"), srv->servername);
3701  break;
3702  }
3703 
3704  case OCLASS_USER_MAPPING:
3705  {
3706  HeapTuple tup;
3707  Oid useid;
3708  char *usename;
3709  Form_pg_user_mapping umform;
3710  ForeignServer *srv;
3711 
3713  ObjectIdGetDatum(object->objectId));
3714  if (!HeapTupleIsValid(tup))
3715  {
3716  if (!missing_ok)
3717  elog(ERROR, "cache lookup failed for user mapping %u",
3718  object->objectId);
3719  break;
3720  }
3721 
3722  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
3723  useid = umform->umuser;
3724  srv = GetForeignServer(umform->umserver);
3725 
3726  ReleaseSysCache(tup);
3727 
3728  if (OidIsValid(useid))
3729  usename = GetUserNameFromId(useid, false);
3730  else
3731  usename = "public";
3732 
3733  appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
3734  srv->servername);
3735  break;
3736  }
3737 
3738  case OCLASS_DEFACL:
3739  {
3740  Relation defaclrel;
3741  ScanKeyData skey[1];
3742  SysScanDesc rcscan;
3743  HeapTuple tup;
3744  Form_pg_default_acl defacl;
3745  char *rolename;
3746  char *nspname;
3747 
3748  defaclrel = table_open(DefaultAclRelationId, AccessShareLock);
3749 
3750  ScanKeyInit(&skey[0],
3751  Anum_pg_default_acl_oid,
3752  BTEqualStrategyNumber, F_OIDEQ,
3753  ObjectIdGetDatum(object->objectId));
3754 
3755  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
3756  true, NULL, 1, skey);
3757 
3758  tup = systable_getnext(rcscan);
3759 
3760  if (!HeapTupleIsValid(tup))
3761  {
3762  if (!missing_ok)
3763  elog(ERROR, "could not find tuple for default ACL %u",
3764  object->objectId);
3765 
3766  systable_endscan(rcscan);
3767  table_close(defaclrel, AccessShareLock);
3768  break;
3769  }
3770 
3771  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
3772 
3773  rolename = GetUserNameFromId(defacl->defaclrole, false);
3774 
3775  if (OidIsValid(defacl->defaclnamespace))
3776  nspname = get_namespace_name(defacl->defaclnamespace);
3777  else
3778  nspname = NULL;
3779 
3780  switch (defacl->defaclobjtype)
3781  {
3782  case DEFACLOBJ_RELATION:
3783  if (nspname)
3784  appendStringInfo(&buffer,
3785  _("default privileges on new relations belonging to role %s in schema %s"),
3786  rolename, nspname);
3787  else
3788  appendStringInfo(&buffer,
3789  _("default privileges on new relations belonging to role %s"),
3790  rolename);
3791  break;
3792  case DEFACLOBJ_SEQUENCE:
3793  if (nspname)
3794  appendStringInfo(&buffer,
3795  _("default privileges on new sequences belonging to role %s in schema %s"),
3796  rolename, nspname);
3797  else
3798  appendStringInfo(&buffer,
3799  _("default privileges on new sequences belonging to role %s"),
3800  rolename);
3801  break;
3802  case DEFACLOBJ_FUNCTION:
3803  if (nspname)
3804  appendStringInfo(&buffer,
3805  _("default privileges on new functions belonging to role %s in schema %s"),
3806  rolename, nspname);
3807  else
3808  appendStringInfo(&buffer,
3809  _("default privileges on new functions belonging to role %s"),
3810  rolename);
3811  break;
3812  case DEFACLOBJ_TYPE:
3813  if (nspname)
3814  appendStringInfo(&buffer,
3815  _("default privileges on new types belonging to role %s in schema %s"),
3816  rolename, nspname);
3817  else
3818  appendStringInfo(&buffer,
3819  _("default privileges on new types belonging to role %s"),
3820  rolename);
3821  break;
3822  case DEFACLOBJ_NAMESPACE:
3823  Assert(!nspname);
3824  appendStringInfo(&buffer,
3825  _("default privileges on new schemas belonging to role %s"),
3826  rolename);
3827  break;
3828  default:
3829  /* shouldn't get here */
3830  if (nspname)
3831  appendStringInfo(&buffer,
3832  _("default privileges belonging to role %s in schema %s"),
3833  rolename, nspname);
3834  else
3835  appendStringInfo(&buffer,
3836  _("default privileges belonging to role %s"),
3837  rolename);
3838  break;
3839  }
3840 
3841  systable_endscan(rcscan);
3842  table_close(defaclrel, AccessShareLock);
3843  break;
3844  }
3845 
3846  case OCLASS_EXTENSION:
3847  {
3848  char *extname;
3849 
3850  extname = get_extension_name(object->objectId);
3851  if (!extname)
3852  {
3853  if (!missing_ok)
3854  elog(ERROR, "cache lookup failed for extension %u",
3855  object->objectId);
3856  break;
3857  }
3858  appendStringInfo(&buffer, _("extension %s"), extname);
3859  break;
3860  }
3861 
3862  case OCLASS_EVENT_TRIGGER:
3863  {
3864  HeapTuple tup;
3865 
3867  ObjectIdGetDatum(object->objectId));
3868  if (!HeapTupleIsValid(tup))
3869  {
3870  if (!missing_ok)
3871  elog(ERROR, "cache lookup failed for event trigger %u",
3872  object->objectId);
3873  break;
3874  }
3875  appendStringInfo(&buffer, _("event trigger %s"),
3876  NameStr(((Form_pg_event_trigger) GETSTRUCT(tup))->evtname));
3877  ReleaseSysCache(tup);
3878  break;
3879  }
3880 
3881  case OCLASS_PARAMETER_ACL:
3882  {
3883  HeapTuple tup;
3884  Datum nameDatum;
3885  bool isNull;
3886  char *parname;
3887 
3889  ObjectIdGetDatum(object->objectId));
3890  if (!HeapTupleIsValid(tup))
3891  {
3892  if (!missing_ok)
3893  elog(ERROR, "cache lookup failed for parameter ACL %u",
3894  object->objectId);
3895  break;
3896  }
3897  nameDatum = SysCacheGetAttr(PARAMETERACLOID, tup,
3898  Anum_pg_parameter_acl_parname,
3899  &isNull);
3900  Assert(!isNull);
3901  parname = TextDatumGetCString(nameDatum);
3902  appendStringInfo(&buffer, _("parameter %s"), parname);
3903  ReleaseSysCache(tup);
3904  break;
3905  }
3906 
3907  case OCLASS_POLICY:
3908  {
3909  Relation policy_rel;
3910  ScanKeyData skey[1];
3911  SysScanDesc sscan;
3912  HeapTuple tuple;
3913  Form_pg_policy form_policy;
3914  StringInfoData rel;
3915 
3916  policy_rel = table_open(PolicyRelationId, AccessShareLock);
3917 
3918  ScanKeyInit(&skey[0],
3919  Anum_pg_policy_oid,
3920  BTEqualStrategyNumber, F_OIDEQ,
3921  ObjectIdGetDatum(object->objectId));
3922 
3923  sscan = systable_beginscan(policy_rel, PolicyOidIndexId,
3924  true, NULL, 1, skey);
3925 
3926  tuple = systable_getnext(sscan);
3927 
3928  if (!HeapTupleIsValid(tuple))
3929  {
3930  if (!missing_ok)
3931  elog(ERROR, "could not find tuple for policy %u",
3932  object->objectId);
3933 
3934  systable_endscan(sscan);
3935  table_close(policy_rel, AccessShareLock);
3936  break;
3937  }
3938 
3939  form_policy = (Form_pg_policy) GETSTRUCT(tuple);
3940 
3941  initStringInfo(&rel);
3942  getRelationDescription(&rel, form_policy->polrelid, false);
3943 
3944  /* translator: second %s is, e.g., "table %s" */
3945  appendStringInfo(&buffer, _("policy %s on %s"),
3946  NameStr(form_policy->polname), rel.data);
3947  pfree(rel.data);
3948  systable_endscan(sscan);
3949  table_close(policy_rel, AccessShareLock);
3950  break;
3951  }
3952 
3953  case OCLASS_PUBLICATION:
3954  {
3955  char *pubname = get_publication_name(object->objectId,
3956  missing_ok);
3957 
3958  if (pubname)
3959  appendStringInfo(&buffer, _("publication %s"), pubname);
3960  break;
3961  }
3962 
3964  {
3965  char *pubname;
3966  char *nspname;
3967 
3968  if (!getPublicationSchemaInfo(object, missing_ok,
3969  &pubname, &nspname))
3970  break;
3971 
3972  appendStringInfo(&buffer, _("publication of schema %s in publication %s"),
3973  nspname, pubname);
3974  pfree(pubname);
3975  pfree(nspname);
3976  break;
3977  }
3978 
3980  {
3981  HeapTuple tup;
3982  char *pubname;
3983  Form_pg_publication_rel prform;
3984  StringInfoData rel;
3985 
3987  ObjectIdGetDatum(object->objectId));
3988  if (!HeapTupleIsValid(tup))
3989  {
3990  if (!missing_ok)
3991  elog(ERROR, "cache lookup failed for publication table %u",
3992  object->objectId);
3993  break;
3994  }
3995 
3996  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
3997  pubname = get_publication_name(prform->prpubid, false);
3998 
3999  initStringInfo(&rel);
4000  getRelationDescription(&rel, prform->prrelid, false);
4001 
4002  /* translator: first %s is, e.g., "table %s" */
4003  appendStringInfo(&buffer, _("publication of %s in publication %s"),
4004  rel.data, pubname);
4005  pfree(rel.data);
4006  ReleaseSysCache(tup);
4007  break;
4008  }
4009 
4010  case OCLASS_SUBSCRIPTION:
4011  {
4012  char *subname = get_subscription_name(object->objectId,
4013  missing_ok);
4014 
4015  if (subname)
4016  appendStringInfo(&buffer, _("subscription %s"), subname);
4017  break;
4018  }
4019 
4020  case OCLASS_TRANSFORM:
4021  {
4022  HeapTuple trfTup;
4023  Form_pg_transform trfForm;
4024 
4025  trfTup = SearchSysCache1(TRFOID,
4026  ObjectIdGetDatum(object->objectId));
4027  if (!HeapTupleIsValid(trfTup))
4028  {
4029  if (!missing_ok)
4030  elog(ERROR, "could not find tuple for transform %u",
4031  object->objectId);
4032  break;
4033  }
4034 
4035  trfForm = (Form_pg_transform) GETSTRUCT(trfTup);
4036 
4037  appendStringInfo(&buffer, _("transform for %s language %s"),
4038  format_type_be(trfForm->trftype),
4039  get_language_name(trfForm->trflang, false));
4040 
4041  ReleaseSysCache(trfTup);
4042  break;
4043  }
4044 
4045  /*
4046  * There's intentionally no default: case here; we want the
4047  * compiler to warn if a new OCLASS hasn't been handled above.
4048  */
4049  }
4050 
4051  /* an empty buffer is equivalent to no object found */
4052  if (buffer.len == 0)
4053  return NULL;
4054 
4055  return buffer.data;
4056 }
char * get_tablespace_name(Oid spc_oid)
Definition: tablespace.c:1520
#define TextDatumGetCString(d)
Definition: builtins.h:86
#define FORMAT_TYPE_INVALID_AS_NULL
Definition: builtins.h:115
#define NameStr(name)
Definition: c.h:681
uint16 bits16
Definition: c.h:449
char * get_database_name(Oid dbid)
Definition: dbcommands.c:2994
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2757
@ OCLASS_OPERATOR
Definition: dependency.h:100
@ OCLASS_PARAMETER_ACL
Definition: dependency.h:123
@ OCLASS_LARGEOBJECT
Definition: dependency.h:99
@ OCLASS_FDW
Definition: dependency.h:117
@ OCLASS_OPFAMILY
Definition: dependency.h:102
@ OCLASS_DEFACL
Definition: dependency.h:120
@ OCLASS_TSPARSER
Definition: dependency.h:110
@ OCLASS_TRIGGER
Definition: dependency.h:107
@ OCLASS_DEFAULT
Definition: dependency.h:97
@ OCLASS_TSTEMPLATE
Definition: dependency.h:112
@ OCLASS_AMPROC
Definition: dependency.h:105
@ OCLASS_TBLSPACE
Definition: dependency.h:116
@ OCLASS_TSCONFIG
Definition: dependency.h:113
@ OCLASS_TYPE
Definition: dependency.h:92
@ OCLASS_LANGUAGE
Definition: dependency.h:98
@ OCLASS_CAST
Definition: dependency.h:93
@ OCLASS_SUBSCRIPTION
Definition: dependency.h:128
@ OCLASS_PUBLICATION_NAMESPACE
Definition: dependency.h:126
@ OCLASS_EXTENSION
Definition: dependency.h:121
@ OCLASS_COLLATION
Definition: dependency.h:94
@ OCLASS_FOREIGN_SERVER
Definition: dependency.h:118
@ OCLASS_REWRITE
Definition: dependency.h:106
@ OCLASS_STATISTIC_EXT
Definition: dependency.h:109
@ OCLASS_PROC
Definition: dependency.h:91
@ OCLASS_OPCLASS
Definition: dependency.h:101
@ OCLASS_CONVERSION
Definition: dependency.h:96
@ OCLASS_DATABASE
Definition: dependency.h:115
@ OCLASS_SCHEMA
Definition: dependency.h:108
@ OCLASS_EVENT_TRIGGER
Definition: dependency.h:122
@ OCLASS_CLASS
Definition: dependency.h:90
@ OCLASS_TRANSFORM
Definition: dependency.h:129
@ OCLASS_ROLE
Definition: dependency.h:114
@ OCLASS_CONSTRAINT
Definition: dependency.h:95
@ OCLASS_POLICY
Definition: dependency.h:124
@ OCLASS_USER_MAPPING
Definition: dependency.h:119
@ OCLASS_PUBLICATION_REL
Definition: dependency.h:127
@ OCLASS_AM
Definition: dependency.h:103
@ OCLASS_TSDICT
Definition: dependency.h:111
@ OCLASS_PUBLICATION
Definition: dependency.h:125
@ OCLASS_AMOP
Definition: dependency.h:104
#define _(x)
Definition: elog.c:89
char * get_extension_name(Oid ext_oid)
Definition: extension.c:185
ForeignServer * GetForeignServerExtended(Oid serverid, bits16 flags)
Definition: foreign.c:122
ForeignDataWrapper * GetForeignDataWrapperExtended(Oid fdwid, bits16 flags)
Definition: foreign.c:48
ForeignServer * GetForeignServer(Oid serverid)
Definition: foreign.c:110
char * format_type_extended(Oid type_oid, int32 typemod, bits16 flags)
Definition: format_type.c:112
char * get_language_name(Oid langoid, bool missing_ok)
Definition: lsyscache.c:1164
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3326
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition: lsyscache.c:825
void pfree(void *pointer)
Definition: mcxt.c:1175
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:913
bool TSTemplateIsVisible(Oid tmplId)
Definition: namespace.c:2657
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2094
bool ConversionIsVisible(Oid conid)
Definition: namespace.c:2177
bool OpclassIsVisible(Oid opcid)
Definition: namespace.c:1879
bool StatisticsObjIsVisible(Oid relid)
Definition: namespace.c:2281
bool TSParserIsVisible(Oid prsId)
Definition: namespace.c:2404
bool TSConfigIsVisible(Oid cfgid)
Definition: namespace.c:2783
bool TSDictionaryIsVisible(Oid dictId)
Definition: namespace.c:2530
static void getRelationDescription(StringInfo buffer, Oid relid, bool missing_ok)
static bool getPublicationSchemaInfo(const ObjectAddress *object, bool missing_ok, char **pubname, char **nspname)
static void getOpFamilyDescription(StringInfo buffer, Oid opfid, bool missing_ok)
FormData_pg_am * Form_pg_am
Definition: pg_am.h:48
ObjectAddress GetAttrDefaultColumnAddress(Oid attrdefoid)
Definition: pg_attrdef.c:384
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:57
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:57
FormData_pg_conversion * Form_pg_conversion
Definition: pg_conversion.h:61
NameData datname
Definition: pg_database.h:35
FormData_pg_event_trigger * Form_pg_event_trigger
FormData_pg_opclass * Form_pg_opclass
Definition: pg_opclass.h:83
FormData_pg_policy * Form_pg_policy
Definition: pg_policy.h:51
NameData proname
Definition: pg_proc.h:35
char * get_publication_name(Oid pubid, bool missing_ok)
FormData_pg_publication_rel * Form_pg_publication_rel
FormData_pg_rewrite * Form_pg_rewrite
Definition: pg_rewrite.h:52
FormData_pg_statistic_ext * Form_pg_statistic_ext
char * get_subscription_name(Oid subid, bool missing_ok)
NameData subname
FormData_pg_transform * Form_pg_transform
Definition: pg_transform.h:43
FormData_pg_trigger * Form_pg_trigger
Definition: pg_trigger.h:80
FormData_pg_ts_config * Form_pg_ts_config
Definition: pg_ts_config.h:48
FormData_pg_ts_dict * Form_pg_ts_dict
Definition: pg_ts_dict.h:52
FormData_pg_ts_parser * Form_pg_ts_parser
Definition: pg_ts_parser.h:55
FormData_pg_ts_template * Form_pg_ts_template
NameData typname
Definition: pg_type.h:41
uintptr_t Datum
Definition: postgres.h:411
char * format_operator(Oid operator_oid)
Definition: regproc.c:852
char * format_procedure(Oid procedure_oid)
Definition: regproc.c:323
char * format_operator_extended(Oid operator_oid, bits16 flags)
Definition: regproc.c:781
char * format_procedure_extended(Oid procedure_oid, bits16 flags)
Definition: regproc.c:350
#define FORMAT_OPERATOR_INVALID_AS_NULL
Definition: regproc.h:24
#define FORMAT_PROC_INVALID_AS_NULL
Definition: regproc.h:19
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:12276
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
char * fdwname
Definition: foreign.h:28
char * servername
Definition: foreign.h:39
Definition: localtime.c:73
@ PARAMETERACLOID
Definition: syscache.h:76
@ TSTEMPLATEOID
Definition: syscache.h:112
@ TSDICTOID
Definition: syscache.h:108
@ PUBLICATIONREL
Definition: syscache.h:84
@ STATEXTOID
Definition: syscache.h:96
@ AMOID
Definition: syscache.h:36
@ EVENTTRIGGEROID
Definition: syscache.h:60
@ CONVOID
Definition: syscache.h:54
@ COLLOID
Definition: syscache.h:50
@ TRFOID
Definition: syscache.h:102
@ CLAOID
Definition: syscache.h:48
@ USERMAPPINGOID
Definition: syscache.h:115
@ TSPARSEROID
Definition: syscache.h:110
@ TSCONFIGOID
Definition: syscache.h:106

References _, AccessShareLock, AMOID, appendStringInfo(), Assert(), attname, BTEqualStrategyNumber, CLAOID, CollationIsVisible(), COLLOID, CONSTROID, ConversionIsVisible(), CONVOID, StringInfoData::data, datname, elog, ERROR, EVENTTRIGGEROID, ForeignDataWrapper::fdwname, format_operator(), format_operator_extended(), FORMAT_OPERATOR_INVALID_AS_NULL, FORMAT_PROC_INVALID_AS_NULL, format_procedure(), format_procedure_extended(), format_type_be(), format_type_extended(), FORMAT_TYPE_INVALID_AS_NULL, get_attname(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name(), get_publication_name(), get_subscription_name(), get_tablespace_name(), GetAttrDefaultColumnAddress(), GetForeignDataWrapperExtended(), GetForeignServer(), GetForeignServerExtended(), getObjectClass(), getOpFamilyDescription(), getPublicationSchemaInfo(), getRelationDescription(), GETSTRUCT, GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), LargeObjectExists(), StringInfoData::len, NameStr, ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, OCLASS_AM, OCLASS_AMOP, OCLASS_AMPROC, OCLASS_CAST, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONSTRAINT, OCLASS_CONVERSION, OCLASS_DATABASE, OCLASS_DEFACL, OCLASS_DEFAULT, OCLASS_EVENT_TRIGGER, OCLASS_EXTENSION, OCLASS_FDW, OCLASS_FOREIGN_SERVER, OCLASS_LANGUAGE, OCLASS_LARGEOBJECT, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_PARAMETER_ACL, OCLASS_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_NAMESPACE, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, OCLASS_SCHEMA, OCLASS_STATISTIC_EXT, OCLASS_SUBSCRIPTION, OCLASS_TBLSPACE, OCLASS_TRANSFORM, OCLASS_TRIGGER, OCLASS_TSCONFIG, OCLASS_TSDICT, OCLASS_TSPARSER, OCLASS_TSTEMPLATE, OCLASS_TYPE, OCLASS_USER_MAPPING, OidIsValid, OpclassIsVisible(), PARAMETERACLOID, pfree(), proname, PUBLICATIONREL, quote_qualified_identifier(), ReleaseSysCache(), ScanKeyInit(), SearchSysCache1(), ForeignServer::servername, STATEXTOID, StatisticsObjIsVisible(), subname, SysCacheGetAttr(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TextDatumGetCString, TRFOID, TSConfigIsVisible(), TSCONFIGOID, TSDictionaryIsVisible(), TSDICTOID, TSParserIsVisible(), TSPARSEROID, TSTemplateIsVisible(), TSTEMPLATEOID, typname, USERMAPPINGOID, and username.

Referenced by AlterExtensionNamespace(), ATExecAlterColumnType(), changeDependenciesOn(), check_relation_privileges(), checkSharedDependencies(), ExecAlterExtensionContentsStmt(), findDependentObjects(), get_object_address_opf_member(), getObjectDescriptionOids(), pg_describe_object(), recordDependencyOnCurrentExtension(), reportDependentObjects(), sepgsql_fmgr_hook(), shdepDropOwned(), shdepReassignOwned(), and storeObjectDescription().

◆ getObjectDescriptionOids()

char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 4062 of file objectaddress.c.

4063 {
4064  ObjectAddress address;
4065 
4066  address.classId = classid;
4067  address.objectId = objid;
4068  address.objectSubId = 0;
4069 
4070  return getObjectDescription(&address, false);
4071 }

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

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

◆ getObjectIdentity()

◆ getObjectIdentityParts()

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

Definition at line 4768 of file objectaddress.c.

4771 {
4772  StringInfoData buffer;
4773 
4774  initStringInfo(&buffer);
4775 
4776  /*
4777  * Make sure that both objname and objargs were passed, or none was; and
4778  * initialize them to empty lists. For objname this is useless because it
4779  * will be initialized in all cases inside the switch; but we do it anyway
4780  * so that we can test below that no branch leaves it unset.
4781  */
4782  Assert(PointerIsValid(objname) == PointerIsValid(objargs));
4783  if (objname)
4784  {
4785  *objname = NIL;
4786  *objargs = NIL;
4787  }
4788 
4789  switch (getObjectClass(object))
4790  {
4791  case OCLASS_CLASS:
4792  {
4793  char *attr = NULL;
4794 
4795  /*
4796  * Check for the attribute first, so as if it is missing we
4797  * can skip the entire relation description.
4798  */
4799  if (object->objectSubId != 0)
4800  {
4801  attr = get_attname(object->objectId,
4802  object->objectSubId,
4803  missing_ok);
4804 
4805  if (missing_ok && attr == NULL)
4806  break;
4807  }
4808 
4809  getRelationIdentity(&buffer, object->objectId, objname,
4810  missing_ok);
4811  if (objname && *objname == NIL)
4812  break;
4813 
4814  if (attr)
4815  {
4816  appendStringInfo(&buffer, ".%s",
4817  quote_identifier(attr));
4818  if (objname)
4819  *objname = lappend(*objname, attr);
4820  }
4821  }
4822  break;
4823 
4824  case OCLASS_PROC:
4825  {
4827  char *proname = format_procedure_extended(object->objectId,
4828  flags);
4829 
4830  if (proname == NULL)
4831  break;
4832 
4833  appendStringInfoString(&buffer, proname);
4834  if (objname)
4835  format_procedure_parts(object->objectId, objname, objargs,
4836  missing_ok);
4837  break;
4838  }
4839 
4840  case OCLASS_TYPE:
4841  {
4843  char *typeout;
4844 
4845  typeout = format_type_extended(object->objectId, -1, flags);
4846 
4847  if (typeout == NULL)
4848  break;
4849 
4850  appendStringInfoString(&buffer, typeout);
4851  if (objname)
4852  *objname = list_make1(typeout);
4853  }
4854  break;
4855 
4856  case OCLASS_CAST:
4857  {
4858  Relation castRel;
4859  HeapTuple tup;
4860  Form_pg_cast castForm;
4861 
4862  castRel = table_open(CastRelationId, AccessShareLock);
4863 
4864  tup = get_catalog_object_by_oid(castRel, Anum_pg_cast_oid,
4865  object->objectId);
4866 
4867  if (!HeapTupleIsValid(tup))
4868  {
4869  if (!missing_ok)
4870  elog(ERROR, "could not find tuple for cast %u",
4871  object->objectId);
4872 
4873  table_close(castRel, AccessShareLock);
4874  break;
4875  }
4876 
4877  castForm = (Form_pg_cast) GETSTRUCT(tup);
4878 
4879  appendStringInfo(&buffer, "(%s AS %s)",
4880  format_type_be_qualified(castForm->castsource),
4881  format_type_be_qualified(castForm->casttarget));
4882 
4883  if (objname)
4884  {
4885  *objname = list_make1(format_type_be_qualified(castForm->castsource));
4886  *objargs = list_make1(format_type_be_qualified(castForm->casttarget));
4887  }
4888 
4889  table_close(castRel, AccessShareLock);
4890  break;
4891  }
4892 
4893  case OCLASS_COLLATION:
4894  {
4895  HeapTuple collTup;
4896  Form_pg_collation coll;
4897  char *schema;
4898 
4899  collTup = SearchSysCache1(COLLOID,
4900  ObjectIdGetDatum(object->objectId));
4901  if (!HeapTupleIsValid(collTup))
4902  {
4903  if (!missing_ok)
4904  elog(ERROR, "cache lookup failed for collation %u",
4905  object->objectId);
4906  break;
4907  }
4908  coll = (Form_pg_collation) GETSTRUCT(collTup);
4909  schema = get_namespace_name_or_temp(coll->collnamespace);
4910  appendStringInfoString(&buffer,
4912  NameStr(coll->collname)));
4913  if (objname)
4914  *objname = list_make2(schema,
4915  pstrdup(NameStr(coll->collname)));
4916  ReleaseSysCache(collTup);
4917  break;
4918  }
4919 
4920  case OCLASS_CONSTRAINT:
4921  {
4922  HeapTuple conTup;
4923  Form_pg_constraint con;
4924 
4925  conTup = SearchSysCache1(CONSTROID,
4926  ObjectIdGetDatum(object->objectId));
4927  if (!HeapTupleIsValid(conTup))
4928  {
4929  if (!missing_ok)
4930  elog(ERROR, "cache lookup failed for constraint %u",
4931  object->objectId);
4932  break;
4933  }
4934  con = (Form_pg_constraint) GETSTRUCT(conTup);
4935 
4936  if (OidIsValid(con->conrelid))
4937  {
4938  appendStringInfo(&buffer, "%s on ",
4939  quote_identifier(NameStr(con->conname)));
4940  getRelationIdentity(&buffer, con->conrelid, objname,
4941  false);
4942  if (objname)
4943  *objname = lappend(*objname, pstrdup(NameStr(con->conname)));
4944  }
4945  else
4946  {
4947  ObjectAddress domain;
4948 
4949  Assert(OidIsValid(con->contypid));
4950  domain.classId = TypeRelationId;
4951  domain.objectId = con->contypid;
4952  domain.objectSubId = 0;
4953 
4954  appendStringInfo(&buffer, "%s on %s",
4955  quote_identifier(NameStr(con->conname)),
4956  getObjectIdentityParts(&domain, objname,
4957  objargs, false));
4958 
4959  if (objname)
4960  *objargs = lappend(*objargs, pstrdup(NameStr(con->conname)));
4961  }
4962 
4963  ReleaseSysCache(conTup);
4964  break;
4965  }
4966 
4967  case OCLASS_CONVERSION:
4968  {
4969  HeapTuple conTup;
4970  Form_pg_conversion conForm;
4971  char *schema;
4972 
4973  conTup = SearchSysCache1(CONVOID,
4974  ObjectIdGetDatum(object->objectId));
4975  if (!HeapTupleIsValid(conTup))
4976  {
4977  if (!missing_ok)
4978  elog(ERROR, "cache lookup failed for conversion %u",
4979  object->objectId);
4980  break;
4981  }
4982  conForm = (Form_pg_conversion) GETSTRUCT(conTup);
4983  schema = get_namespace_name_or_temp(conForm->connamespace);
4984  appendStringInfoString(&buffer,
4986  NameStr(conForm->conname)));
4987  if (objname)
4988  *objname = list_make2(schema,
4989  pstrdup(NameStr(conForm->conname)));
4990  ReleaseSysCache(conTup);
4991  break;
4992  }
4993 
4994  case OCLASS_DEFAULT:
4995  {
4996  ObjectAddress colobject;
4997 
4998  colobject = GetAttrDefaultColumnAddress(object->objectId);
4999 
5000  if (!OidIsValid(colobject.objectId))
5001  {
5002  if (!missing_ok)
5003  elog(ERROR, "could not find tuple for attrdef %u",
5004  object->objectId);
5005  break;
5006  }
5007 
5008  appendStringInfo(&buffer, "for %s",
5009  getObjectIdentityParts(&colobject,
5010  objname, objargs,
5011  false));
5012  break;
5013  }
5014 
5015  case OCLASS_LANGUAGE:
5016  {
5017  HeapTuple langTup;
5018  Form_pg_language langForm;
5019 
5020  langTup = SearchSysCache1(LANGOID,
5021  ObjectIdGetDatum(object->objectId));
5022  if (!HeapTupleIsValid(langTup))
5023  {
5024  if (!missing_ok)
5025  elog(ERROR, "cache lookup failed for language %u",
5026  object->objectId);
5027  break;
5028  }
5029  langForm = (Form_pg_language) GETSTRUCT(langTup);
5030  appendStringInfoString(&buffer,
5031  quote_identifier(NameStr(langForm->lanname)));
5032  if (objname)
5033  *objname = list_make1(pstrdup(NameStr(langForm->lanname)));
5034  ReleaseSysCache(langTup);
5035  break;
5036  }
5037  case OCLASS_LARGEOBJECT:
5038  if (!LargeObjectExists(object->objectId))
5039  break;
5040  appendStringInfo(&buffer, "%u",
5041  object->objectId);
5042  if (objname)
5043  *objname = list_make1(psprintf("%u", object->objectId));
5044  break;
5045 
5046  case OCLASS_OPERATOR:
5047  {
5049  char *oprname = format_operator_extended(object->objectId,
5050  flags);
5051 
5052  if (oprname == NULL)
5053  break;
5054 
5055  appendStringInfoString(&buffer, oprname);
5056  if (objname)
5057  format_operator_parts(object->objectId, objname, objargs, missing_ok);
5058  break;
5059  }
5060 
5061  case OCLASS_OPCLASS:
5062  {
5063  HeapTuple opcTup;
5064  Form_pg_opclass opcForm;
5065  HeapTuple amTup;
5066  Form_pg_am amForm;
5067  char *schema;
5068 
5069  opcTup = SearchSysCache1(CLAOID,
5070  ObjectIdGetDatum(object->objectId));
5071  if (!HeapTupleIsValid(opcTup))
5072  {
5073  if (!missing_ok)
5074  elog(ERROR, "cache lookup failed for opclass %u",
5075  object->objectId);
5076  break;
5077  }
5078  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
5079  schema = get_namespace_name_or_temp(opcForm->opcnamespace);
5080 
5081  amTup = SearchSysCache1(AMOID,
5082  ObjectIdGetDatum(opcForm->opcmethod));
5083  if (!HeapTupleIsValid(amTup))
5084  elog(ERROR, "cache lookup failed for access method %u",
5085  opcForm->opcmethod);
5086  amForm = (Form_pg_am) GETSTRUCT(amTup);
5087 
5088  appendStringInfo(&buffer, "%s USING %s",
5090  NameStr(opcForm->opcname)),
5091  quote_identifier(NameStr(amForm->amname)));
5092  if (objname)
5093  *objname = list_make3(pstrdup(NameStr(amForm->amname)),
5094  schema,
5095  pstrdup(NameStr(opcForm->opcname)));
5096 
5097  ReleaseSysCache(amTup);
5098  ReleaseSysCache(opcTup);
5099  break;
5100  }
5101 
5102  case OCLASS_OPFAMILY:
5103  getOpFamilyIdentity(&buffer, object->objectId, objname,
5104  missing_ok);
5105  break;
5106 
5107  case OCLASS_AM:
5108  {
5109  char *amname;
5110 
5111  amname = get_am_name(object->objectId);
5112  if (!amname)
5113  {
5114  if (!missing_ok)
5115  elog(ERROR, "cache lookup failed for access method %u",
5116  object->objectId);
5117  break;
5118  }
5119  appendStringInfoString(&buffer, quote_identifier(amname));
5120  if (objname)
5121  *objname = list_make1(amname);
5122  }
5123  break;
5124 
5125  case OCLASS_AMOP:
5126  {
5127  Relation amopDesc;
5128  HeapTuple tup;
5129  ScanKeyData skey[1];
5130  SysScanDesc amscan;
5131  Form_pg_amop amopForm;
5132  StringInfoData opfam;
5133  char *ltype;
5134  char *rtype;
5135 
5136  amopDesc = table_open(AccessMethodOperatorRelationId,
5137  AccessShareLock);
5138 
5139  ScanKeyInit(&skey[0],
5140  Anum_pg_amop_oid,
5141  BTEqualStrategyNumber, F_OIDEQ,
5142  ObjectIdGetDatum(object->objectId));
5143 
5144  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
5145  NULL, 1, skey);
5146 
5147  tup = systable_getnext(amscan);
5148 
5149  if (!HeapTupleIsValid(tup))
5150  {
5151  if (!missing_ok)
5152  elog(ERROR, "could not find tuple for amop entry %u",
5153  object->objectId);
5154 
5155  systable_endscan(amscan);
5156  table_close(amopDesc, AccessShareLock);
5157  break;
5158  }
5159 
5160  amopForm = (Form_pg_amop) GETSTRUCT(tup);
5161 
5162  initStringInfo(&opfam);
5163  getOpFamilyIdentity(&opfam, amopForm->amopfamily, objname,
5164  false);
5165 
5166  ltype = format_type_be_qualified(amopForm->amoplefttype);
5167  rtype = format_type_be_qualified(amopForm->amoprighttype);
5168 
5169  if (objname)
5170  {
5171  *objname = lappend(*objname,
5172  psprintf("%d", amopForm->amopstrategy));
5173  *objargs = list_make2(ltype, rtype);
5174  }
5175 
5176  appendStringInfo(&buffer, "operator %d (%s, %s) of %s",
5177  amopForm->amopstrategy,
5178  ltype, rtype, opfam.data);
5179 
5180  pfree(opfam.data);
5181 
5182  systable_endscan(amscan);
5183  table_close(amopDesc, AccessShareLock);
5184  break;
5185  }
5186 
5187  case OCLASS_AMPROC:
5188  {
5189  Relation amprocDesc;
5190  ScanKeyData skey[1];
5191  SysScanDesc amscan;
5192  HeapTuple tup;
5193  Form_pg_amproc amprocForm;
5194  StringInfoData opfam;
5195  char *ltype;
5196  char *rtype;
5197 
5198  amprocDesc = table_open(AccessMethodProcedureRelationId,
5199  AccessShareLock);
5200 
5201  ScanKeyInit(&skey[0],
5202  Anum_pg_amproc_oid,
5203  BTEqualStrategyNumber, F_OIDEQ,
5204  ObjectIdGetDatum(object->objectId));
5205 
5206  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
5207  NULL, 1, skey);
5208 
5209  tup = systable_getnext(amscan);
5210 
5211  if (!HeapTupleIsValid(tup))
5212  {
5213  if (!missing_ok)
5214  elog(ERROR, "could not find tuple for amproc entry %u",
5215  object->objectId);
5216 
5217  systable_endscan(amscan);
5218  table_close(amprocDesc, AccessShareLock);
5219  break;
5220  }
5221 
5222  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
5223 
5224  initStringInfo(&opfam);
5225  getOpFamilyIdentity(&opfam, amprocForm->amprocfamily, objname,
5226  false);
5227 
5228  ltype = format_type_be_qualified(amprocForm->amproclefttype);
5229  rtype = format_type_be_qualified(amprocForm->amprocrighttype);
5230 
5231  if (objname)
5232  {
5233  *objname = lappend(*objname,
5234  psprintf("%d", amprocForm->amprocnum));
5235  *objargs = list_make2(ltype, rtype);
5236  }
5237 
5238  appendStringInfo(&buffer, "function %d (%s, %s) of %s",
5239  amprocForm->amprocnum,
5240  ltype, rtype, opfam.data);
5241 
5242  pfree(opfam.data);
5243 
5244  systable_endscan(amscan);
5245  table_close(amprocDesc, AccessShareLock);
5246  break;
5247  }
5248 
5249  case OCLASS_REWRITE:
5250  {
5251  Relation ruleDesc;
5252  HeapTuple tup;
5254 
5255  ruleDesc = table_open(RewriteRelationId, AccessShareLock);
5256 
5257  tup = get_catalog_object_by_oid(ruleDesc, Anum_pg_rewrite_oid,
5258  object->objectId);
5259 
5260  if (!HeapTupleIsValid(tup))
5261  {
5262  if (!missing_ok)
5263  elog(ERROR, "could not find tuple for rule %u",
5264  object->objectId);
5265 
5266  table_close(ruleDesc, AccessShareLock);
5267  break;
5268  }
5269 
5270  rule = (Form_pg_rewrite) GETSTRUCT(tup);
5271 
5272  appendStringInfo(&buffer, "%s on ",
5273  quote_identifier(NameStr(rule->rulename)));
5274  getRelationIdentity(&buffer, rule->ev_class, objname, false);
5275  if (objname)
5276  *objname = lappend(*objname, pstrdup(NameStr(rule->rulename)));
5277 
5278  table_close(ruleDesc, AccessShareLock);
5279  break;
5280  }
5281 
5282  case OCLASS_TRIGGER:
5283  {
5284  Relation trigDesc;
5285  HeapTuple tup;
5286  Form_pg_trigger trig;
5287 
5288  trigDesc = table_open(TriggerRelationId, AccessShareLock);
5289 
5290  tup = get_catalog_object_by_oid(trigDesc, Anum_pg_trigger_oid,
5291  object->objectId);
5292 
5293  if (!HeapTupleIsValid(tup))
5294  {
5295  if (!missing_ok)
5296  elog(ERROR, "could not find tuple for trigger %u",
5297  object->objectId);
5298 
5299  table_close(trigDesc, AccessShareLock);
5300  break;
5301  }
5302 
5303  trig = (Form_pg_trigger) GETSTRUCT(tup);
5304 
5305  appendStringInfo(&buffer, "%s on ",
5306  quote_identifier(NameStr(trig->tgname)));
5307  getRelationIdentity(&buffer, trig->tgrelid, objname, false);
5308  if (objname)
5309  *objname = lappend(*objname, pstrdup(NameStr(trig->tgname)));
5310 
5311  table_close(trigDesc, AccessShareLock);
5312  break;
5313  }
5314 
5315  case OCLASS_SCHEMA:
5316  {
5317  char *nspname;
5318 
5319  nspname = get_namespace_name_or_temp(object->objectId);
5320  if (!nspname)
5321  {
5322  if (!missing_ok)
5323  elog(ERROR, "cache lookup failed for namespace %u",
5324  object->objectId);
5325  break;
5326  }
5327  appendStringInfoString(&buffer,
5328  quote_identifier(nspname));
5329  if (objname)
5330  *objname = list_make1(nspname);
5331  break;
5332  }
5333 
5334  case OCLASS_STATISTIC_EXT:
5335  {
5336  HeapTuple tup;
5337  Form_pg_statistic_ext formStatistic;
5338  char *schema;
5339 
5341  ObjectIdGetDatum(object->objectId));
5342  if (!HeapTupleIsValid(tup))
5343  {
5344  if (!missing_ok)
5345  elog(ERROR, "cache lookup failed for statistics object %u",
5346  object->objectId);
5347  break;
5348  }
5349  formStatistic = (Form_pg_statistic_ext) GETSTRUCT(tup);
5350  schema = get_namespace_name_or_temp(formStatistic->stxnamespace);
5351  appendStringInfoString(&buffer,
5353  NameStr(formStatistic->stxname)));
5354  if (objname)
5355  *objname = list_make2(schema,
5356  pstrdup(NameStr(formStatistic->stxname)));
5357  ReleaseSysCache(tup);
5358  }
5359  break;
5360 
5361  case OCLASS_TSPARSER:
5362  {
5363  HeapTuple tup;
5364  Form_pg_ts_parser formParser;
5365  char *schema;
5366 
5368  ObjectIdGetDatum(object->objectId));
5369  if (!HeapTupleIsValid(tup))
5370  {
5371  if (!missing_ok)
5372  elog(ERROR, "cache lookup failed for text search parser %u",
5373  object->objectId);
5374  break;
5375  }
5376  formParser = (Form_pg_ts_parser) GETSTRUCT(tup);
5377  schema = get_namespace_name_or_temp(formParser->prsnamespace);
5378  appendStringInfoString(&buffer,
5380  NameStr(formParser->prsname)));
5381  if (objname)
5382  *objname = list_make2(schema,
5383  pstrdup(NameStr(formParser->prsname)));
5384  ReleaseSysCache(tup);
5385  break;
5386  }
5387 
5388  case OCLASS_TSDICT:
5389  {
5390  HeapTuple tup;
5391  Form_pg_ts_dict formDict;
5392  char *schema;
5393 
5394  tup = SearchSysCache1(TSDICTOID,
5395  ObjectIdGetDatum(object->objectId));
5396  if (!HeapTupleIsValid(tup))
5397  {
5398  if (!missing_ok)
5399  elog(ERROR, "cache lookup failed for text search dictionary %u",
5400  object->objectId);
5401  break;
5402  }
5403  formDict = (Form_pg_ts_dict) GETSTRUCT(tup);
5404  schema = get_namespace_name_or_temp(formDict->dictnamespace);
5405  appendStringInfoString(&buffer,
5407  NameStr(formDict->dictname)));
5408  if (objname)
5409  *objname = list_make2(schema,
5410  pstrdup(NameStr(formDict->dictname)));
5411  ReleaseSysCache(tup);
5412  break;
5413  }
5414 
5415  case OCLASS_TSTEMPLATE:
5416  {
5417  HeapTuple tup;
5418  Form_pg_ts_template formTmpl;
5419  char *schema;
5420 
5422  ObjectIdGetDatum(object->objectId));
5423  if (!HeapTupleIsValid(tup))
5424  {
5425  if (!missing_ok)
5426  elog(ERROR, "cache lookup failed for text search template %u",
5427  object->objectId);
5428  break;
5429  }
5430  formTmpl = (Form_pg_ts_template) GETSTRUCT(tup);
5431  schema = get_namespace_name_or_temp(formTmpl->tmplnamespace);
5432  appendStringInfoString(&buffer,
5434  NameStr(formTmpl->tmplname)));
5435  if (objname)
5436  *objname = list_make2(schema,
5437  pstrdup(NameStr(formTmpl->tmplname)));
5438  ReleaseSysCache(tup);
5439  break;
5440  }
5441 
5442  case OCLASS_TSCONFIG:
5443  {
5444  HeapTuple tup;
5445  Form_pg_ts_config formCfg;
5446  char *schema;
5447 
5449  ObjectIdGetDatum(object->objectId));
5450  if (!HeapTupleIsValid(tup))
5451  {
5452  if (!missing_ok)
5453  elog(ERROR, "cache lookup failed for text search configuration %u",
5454  object->objectId);
5455  break;
5456  }
5457  formCfg = (Form_pg_ts_config) GETSTRUCT(tup);
5458  schema = get_namespace_name_or_temp(formCfg->cfgnamespace);
5459  appendStringInfoString(&buffer,
5461  NameStr(formCfg->cfgname)));
5462  if (objname)
5463  *objname = list_make2(schema,
5464  pstrdup(NameStr(formCfg->cfgname)));
5465  ReleaseSysCache(tup);
5466  break;
5467  }
5468 
5469  case OCLASS_ROLE:
5470  {
5471  char *username;
5472 
5473  username = GetUserNameFromId(object->objectId, missing_ok);
5474  if (!username)
5475  break;
5476  if (objname)
5477  *objname = list_make1(username);
5478  appendStringInfoString(&buffer,
5480  break;
5481  }
5482 
5483  case OCLASS_DATABASE:
5484  {
5485  char *datname;
5486 
5487  datname = get_database_name(object->objectId);
5488  if (!datname)
5489  {
5490  if (!missing_ok)
5491  elog(ERROR, "cache lookup failed for database %u",
5492  object->objectId);
5493  break;
5494  }
5495  if (objname)
5496  *objname = list_make1(datname);
5497  appendStringInfoString(&buffer,
5499  break;
5500  }
5501 
5502  case OCLASS_TBLSPACE:
5503  {
5504  char *tblspace;
5505 
5506  tblspace = get_tablespace_name(object->objectId);
5507  if (!tblspace)
5508  {
5509  if (!missing_ok)
5510  elog(ERROR, "cache lookup failed for tablespace %u",
5511  object->objectId);
5512  break;
5513  }
5514  if (objname)
5515  *objname = list_make1(tblspace);
5516  appendStringInfoString(&buffer,
5517  quote_identifier(tblspace));
5518  break;
5519  }
5520 
5521  case OCLASS_FDW:
5522  {
5523  ForeignDataWrapper *fdw;
5524 
5526  missing_ok);
5527  if (fdw)
5528  {
5530  if (objname)
5531  *objname = list_make1(pstrdup(fdw->fdwname));
5532  }
5533  break;
5534  }
5535 
5536  case OCLASS_FOREIGN_SERVER:
5537  {
5538  ForeignServer *srv;
5539 
5540  srv = GetForeignServerExtended(object->objectId,
5541  missing_ok);
5542  if (srv)
5543  {
5544  appendStringInfoString(&buffer,
5546  if (objname)
5547  *objname = list_make1(pstrdup(srv->servername));
5548  }
5549  break;
5550  }
5551 
5552  case OCLASS_USER_MAPPING:
5553  {
5554  HeapTuple tup;
5555  Oid useid;
5556  Form_pg_user_mapping umform;
5557  ForeignServer *srv;
5558  const char *usename;
5559 
5561  ObjectIdGetDatum(object->objectId));
5562  if (!HeapTupleIsValid(tup))
5563  {
5564  if (!missing_ok)
5565  elog(ERROR, "cache lookup failed for user mapping %u",
5566  object->objectId);
5567  break;
5568  }
5569  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
5570  useid = umform->umuser;
5571  srv = GetForeignServer(umform->umserver);
5572 
5573  ReleaseSysCache(tup);
5574 
5575  if (OidIsValid(useid))
5576  usename = GetUserNameFromId(useid, false);
5577  else
5578  usename = "public";
5579 
5580  if (objname)
5581  {
5582  *objname = list_make1(pstrdup(usename));
5583  *objargs = list_make1(pstrdup(srv->servername));
5584  }
5585 
5586  appendStringInfo(&buffer, "%s on server %s",
5587  quote_identifier(usename),
5588  srv->servername);
5589  break;
5590  }
5591 
5592  case OCLASS_DEFACL:
5593  {
5594  Relation defaclrel;
5595  ScanKeyData skey[1];
5596  SysScanDesc rcscan;
5597  HeapTuple tup;
5598  Form_pg_default_acl defacl;
5599  char *schema;
5600  char *username;
5601 
5602  defaclrel = table_open(DefaultAclRelationId, AccessShareLock);
5603 
5604  ScanKeyInit(&skey[0],
5605  Anum_pg_default_acl_oid,
5606  BTEqualStrategyNumber, F_OIDEQ,
5607  ObjectIdGetDatum(object->objectId));
5608 
5609  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
5610  true, NULL, 1, skey);
5611 
5612  tup = systable_getnext(rcscan);
5613 
5614  if (!HeapTupleIsValid(tup))
5615  {
5616  if (!missing_ok)
5617  elog(ERROR, "could not find tuple for default ACL %u",
5618  object->objectId);
5619 
5620  systable_endscan(rcscan);
5621  table_close(defaclrel, AccessShareLock);
5622  break;
5623  }
5624 
5625  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
5626 
5627  username = GetUserNameFromId(defacl->defaclrole, false);
5628  appendStringInfo(&buffer,
5629  "for role %s",
5631 
5632  if (OidIsValid(defacl->defaclnamespace))
5633  {
5634  schema = get_namespace_name_or_temp(defacl->defaclnamespace);
5635  appendStringInfo(&buffer,
5636  " in schema %s",
5637  quote_identifier(schema));
5638  }
5639  else
5640  schema = NULL;
5641 
5642  switch (defacl->defaclobjtype)
5643  {
5644  case DEFACLOBJ_RELATION:
5645  appendStringInfoString(&buffer,
5646  " on tables");
5647  break;
5648  case DEFACLOBJ_SEQUENCE:
5649  appendStringInfoString(&buffer,
5650  " on sequences");
5651  break;
5652  case DEFACLOBJ_FUNCTION:
5653  appendStringInfoString(&buffer,
5654  " on functions");
5655  break;
5656  case DEFACLOBJ_TYPE:
5657  appendStringInfoString(&buffer,
5658  " on types");
5659  break;
5660  case DEFACLOBJ_NAMESPACE:
5661  appendStringInfoString(&buffer,
5662  " on schemas");
5663  break;
5664  }
5665 
5666  if (objname)
5667  {
5668  *objname = list_make1(username);
5669  if (schema)
5670  *objname = lappend(*objname, schema);
5671  *objargs = list_make1(psprintf("%c", defacl->defaclobjtype));
5672  }
5673 
5674  systable_endscan(rcscan);
5675  table_close(defaclrel, AccessShareLock);
5676  break;
5677  }
5678 
5679  case OCLASS_EXTENSION:
5680  {
5681  char *extname;
5682 
5683  extname = get_extension_name(object->objectId);
5684  if (!extname)
5685  {
5686  if (!missing_ok)
5687  elog(ERROR, "cache lookup failed for extension %u",
5688  object->objectId);
5689  break;
5690  }
5691  appendStringInfoString(&buffer, quote_identifier(extname));
5692  if (objname)
5693  *objname = list_make1(extname);
5694  break;
5695  }
5696 
5697  case OCLASS_EVENT_TRIGGER:
5698  {
5699  HeapTuple tup;
5700  Form_pg_event_trigger trigForm;
5701  char *evtname;
5702 
5704  ObjectIdGetDatum(object->objectId));
5705  if (!HeapTupleIsValid(tup))
5706  {
5707  if (!missing_ok)
5708  elog(ERROR, "cache lookup failed for event trigger %u",
5709  object->objectId);
5710  break;
5711  }
5712  trigForm = (Form_pg_event_trigger) GETSTRUCT(tup);
5713  evtname = pstrdup(NameStr(trigForm->evtname));
5714  appendStringInfoString(&buffer, quote_identifier(evtname));
5715  if (objname)
5716  *objname = list_make1(evtname);
5717  ReleaseSysCache(tup);
5718  break;
5719  }
5720 
5721  case OCLASS_PARAMETER_ACL:
5722  {
5723  HeapTuple tup;
5724  Datum nameDatum;
5725  bool isNull;
5726  char *parname;
5727 
5729  ObjectIdGetDatum(object->objectId));
5730  if (!HeapTupleIsValid(tup))
5731  {
5732  if (!missing_ok)
5733  elog(ERROR, "cache lookup failed for parameter ACL %u",
5734  object->objectId);
5735  break;
5736  }
5737  nameDatum = SysCacheGetAttr(PARAMETERACLOID, tup,
5738  Anum_pg_parameter_acl_parname,
5739  &isNull);
5740  Assert(!isNull);
5741  parname = TextDatumGetCString(nameDatum);
5742  appendStringInfoString(&buffer, parname);
5743  if (objname)
5744  *objname = list_make1(parname);
5745  ReleaseSysCache(tup);
5746  break;
5747  }
5748 
5749  case OCLASS_POLICY:
5750  {
5751  Relation polDesc;
5752  HeapTuple tup;
5753  Form_pg_policy policy;
5754 
5755  polDesc = table_open(PolicyRelationId, AccessShareLock);
5756 
5757  tup = get_catalog_object_by_oid(polDesc, Anum_pg_policy_oid,
5758  object->objectId);
5759 
5760  if (!HeapTupleIsValid(tup))
5761  {
5762  if (!missing_ok)
5763  elog(ERROR, "could not find tuple for policy %u",
5764  object->objectId);
5765 
5766  table_close(polDesc, AccessShareLock);
5767  break;
5768  }
5769 
5770  policy = (Form_pg_policy) GETSTRUCT(tup);
5771 
5772  appendStringInfo(&buffer, "%s on ",
5773  quote_identifier(NameStr(policy->polname)));
5774  getRelationIdentity(&buffer, policy->polrelid, objname, false);
5775  if (objname)
5776  *objname = lappend(*objname, pstrdup(NameStr(policy->polname)));
5777 
5778  table_close(polDesc, AccessShareLock);
5779  break;
5780  }
5781 
5782  case OCLASS_PUBLICATION:
5783  {
5784  char *pubname;
5785 
5786  pubname = get_publication_name(object->objectId, missing_ok);
5787  if (pubname)
5788  {
5789  appendStringInfoString(&buffer,
5790  quote_identifier(pubname));
5791  if (objname)
5792  *objname = list_make1(pubname);
5793  }
5794  break;
5795  }
5796 
5798  {
5799  char *pubname;
5800  char *nspname;
5801 
5802  if (!getPublicationSchemaInfo(object, missing_ok, &pubname,
5803  &nspname))
5804  break;
5805  appendStringInfo(&buffer, "%s in publication %s",
5806  nspname, pubname);
5807 
5808  if (objargs)
5809  *objargs = list_make1(pubname);
5810  else
5811  pfree(pubname);
5812 
5813  if (objname)
5814  *objname = list_make1(nspname);
5815  else
5816  pfree(nspname);
5817 
5818  break;
5819  }
5820 
5822  {
5823  HeapTuple tup;
5824  char *pubname;
5825  Form_pg_publication_rel prform;
5826 
5828  ObjectIdGetDatum(object->objectId));
5829  if (!HeapTupleIsValid(tup))
5830  {
5831  if (!missing_ok)
5832  elog(ERROR, "cache lookup failed for publication table %u",
5833  object->objectId);
5834  break;
5835  }
5836 
5837  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
5838  pubname = get_publication_name(prform->prpubid, false);
5839 
5840  getRelationIdentity(&buffer, prform->prrelid, objname, false);
5841  appendStringInfo(&buffer, " in publication %s", pubname);
5842 
5843  if (objargs)
5844  *objargs = list_make1(pubname);
5845 
5846  ReleaseSysCache(tup);
5847  break;
5848  }
5849 
5850  case OCLASS_SUBSCRIPTION:
5851  {
5852  char *subname;
5853 
5854  subname = get_subscription_name(object->objectId, missing_ok);
5855  if (subname)
5856  {
5857  appendStringInfoString(&buffer,
5859  if (objname)
5860  *objname = list_make1(subname);
5861  }
5862  break;
5863  }
5864 
5865  case OCLASS_TRANSFORM:
5866  {
5867  Relation transformDesc;
5868  HeapTuple tup;
5869  Form_pg_transform transform;
5870  char *transformLang;
5871  char *transformType;
5872 
5873  transformDesc = table_open(TransformRelationId, AccessShareLock);
5874 
5875  tup = get_catalog_object_by_oid(transformDesc,
5876  Anum_pg_transform_oid,
5877  object->