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/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_auth_members.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_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 "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)
 
Datum pg_get_acl (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 2382 of file objectaddress.c.

2384 {
2385  switch (objtype)
2386  {
2387  case OBJECT_INDEX:
2388  case OBJECT_SEQUENCE:
2389  case OBJECT_TABLE:
2390  case OBJECT_VIEW:
2391  case OBJECT_MATVIEW:
2392  case OBJECT_FOREIGN_TABLE:
2393  case OBJECT_COLUMN:
2394  case OBJECT_RULE:
2395  case OBJECT_TRIGGER:
2396  case OBJECT_POLICY:
2397  case OBJECT_TABCONSTRAINT:
2398  if (!object_ownercheck(RelationRelationId, RelationGetRelid(relation), roleid))
2400  RelationGetRelationName(relation));
2401  break;
2402  case OBJECT_TYPE:
2403  case OBJECT_DOMAIN:
2404  case OBJECT_ATTRIBUTE:
2405  if (!object_ownercheck(address.classId, address.objectId, roleid))
2407  break;
2408  case OBJECT_DOMCONSTRAINT:
2409  {
2410  HeapTuple tuple;
2411  Oid contypid;
2412 
2413  tuple = SearchSysCache1(CONSTROID,
2414  ObjectIdGetDatum(address.objectId));
2415  if (!HeapTupleIsValid(tuple))
2416  elog(ERROR, "constraint with OID %u does not exist",
2417  address.objectId);
2418 
2419  contypid = ((Form_pg_constraint) GETSTRUCT(tuple))->contypid;
2420 
2421  ReleaseSysCache(tuple);
2422 
2423  /*
2424  * Fallback to type ownership check in this case as this is
2425  * what domain constraints rely on.
2426  */
2427  if (!object_ownercheck(TypeRelationId, contypid, roleid))
2429  }
2430  break;
2431  case OBJECT_AGGREGATE:
2432  case OBJECT_FUNCTION:
2433  case OBJECT_PROCEDURE:
2434  case OBJECT_ROUTINE:
2435  case OBJECT_OPERATOR:
2436  if (!object_ownercheck(address.classId, address.objectId, roleid))
2438  NameListToString((castNode(ObjectWithArgs, object))->objname));
2439  break;
2440  case OBJECT_DATABASE:
2441  case OBJECT_EVENT_TRIGGER:
2442  case OBJECT_EXTENSION:
2443  case OBJECT_FDW:
2444  case OBJECT_FOREIGN_SERVER:
2445  case OBJECT_LANGUAGE:
2446  case OBJECT_PUBLICATION:
2447  case OBJECT_SCHEMA:
2448  case OBJECT_SUBSCRIPTION:
2449  case OBJECT_TABLESPACE:
2450  if (!object_ownercheck(address.classId, address.objectId, roleid))
2452  strVal(object));
2453  break;
2454  case OBJECT_COLLATION:
2455  case OBJECT_CONVERSION:
2456  case OBJECT_OPCLASS:
2457  case OBJECT_OPFAMILY:
2458  case OBJECT_STATISTIC_EXT:
2459  case OBJECT_TSDICTIONARY:
2461  if (!object_ownercheck(address.classId, address.objectId, roleid))
2463  NameListToString(castNode(List, object)));
2464  break;
2465  case OBJECT_LARGEOBJECT:
2466  if (!lo_compat_privileges &&
2467  !object_ownercheck(address.classId, address.objectId, roleid))
2468  ereport(ERROR,
2469  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2470  errmsg("must be owner of large object %u",
2471  address.objectId)));
2472  break;
2473  case OBJECT_CAST:
2474  {
2475  /* We can only check permissions on the source/target types */
2476  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2477  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2478  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2479  Oid targettypeid = typenameTypeId(NULL, targettype);
2480 
2481  if (!object_ownercheck(TypeRelationId, sourcetypeid, roleid)
2482  && !object_ownercheck(TypeRelationId, targettypeid, roleid))
2483  ereport(ERROR,
2484  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2485  errmsg("must be owner of type %s or type %s",
2486  format_type_be(sourcetypeid),
2487  format_type_be(targettypeid))));
2488  }
2489  break;
2490  case OBJECT_TRANSFORM:
2491  {
2492  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2493  Oid typeid = typenameTypeId(NULL, typename);
2494 
2495  if (!object_ownercheck(TypeRelationId, typeid, roleid))
2497  }
2498  break;
2499  case OBJECT_ROLE:
2500 
2501  /*
2502  * We treat roles as being "owned" by those with CREATEROLE priv,
2503  * provided that they also have admin option on the role.
2504  *
2505  * However, superusers are only owned by superusers.
2506  */
2507  if (superuser_arg(address.objectId))
2508  {
2509  if (!superuser_arg(roleid))
2510  ereport(ERROR,
2511  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2512  errmsg("permission denied"),
2513  errdetail("The current user must have the %s attribute.",
2514  "SUPERUSER")));
2515  }
2516  else
2517  {
2518  if (!has_createrole_privilege(roleid))
2519  ereport(ERROR,
2520  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2521  errmsg("permission denied"),
2522  errdetail("The current user must have the %s attribute.",
2523  "CREATEROLE")));
2524  if (!is_admin_of_role(roleid, address.objectId))
2525  ereport(ERROR,
2526  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2527  errmsg("permission denied"),
2528  errdetail("The current user must have the %s option on role \"%s\".",
2529  "ADMIN",
2530  GetUserNameFromId(address.objectId,
2531  true))));
2532  }
2533  break;
2534  case OBJECT_TSPARSER:
2535  case OBJECT_TSTEMPLATE:
2536  case OBJECT_ACCESS_METHOD:
2537  case OBJECT_PARAMETER_ACL:
2538  /* We treat these object types as being owned by superusers */
2539  if (!superuser_arg(roleid))
2540  ereport(ERROR,
2541  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2542  errmsg("must be superuser")));
2543  break;
2544  case OBJECT_AMOP:
2545  case OBJECT_AMPROC:
2546  case OBJECT_DEFAULT:
2547  case OBJECT_DEFACL:
2550  case OBJECT_USER_MAPPING:
2551  /* These are currently not supported or don't make sense here. */
2552  elog(ERROR, "unsupported object type: %d", (int) objtype);
2553  break;
2554  }
2555 }
bool is_admin_of_role(Oid member, Oid role)
Definition: acl.c:5264
@ ACLCHECK_NOT_OWNER
Definition: acl.h:185
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:2700
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition: aclchk.c:4142
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3019
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:4223
int errdetail(const char *fmt,...)
Definition: elog.c:1205
int errcode(int sqlerrcode)
Definition: elog.c:855
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
#define ereport(elevel,...)
Definition: elog.h:149
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:653
bool lo_compat_privileges
Definition: inv_api.c:57
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:980
char * NameListToString(const List *names)
Definition: namespace.c:3579
#define castNode(_type_, nodeptr)
Definition: nodes.h:176
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:291
@ OBJECT_EVENT_TRIGGER
Definition: parsenodes.h:2275
@ OBJECT_FDW
Definition: parsenodes.h:2277
@ OBJECT_TSPARSER
Definition: parsenodes.h:2308
@ OBJECT_COLLATION
Definition: parsenodes.h:2268
@ OBJECT_USER_MAPPING
Definition: parsenodes.h:2311
@ OBJECT_ACCESS_METHOD
Definition: parsenodes.h:2261
@ OBJECT_OPCLASS
Definition: parsenodes.h:2285
@ OBJECT_DEFACL
Definition: parsenodes.h:2272
@ OBJECT_AGGREGATE
Definition: parsenodes.h:2262
@ OBJECT_MATVIEW
Definition: parsenodes.h:2284
@ OBJECT_SCHEMA
Definition: parsenodes.h:2297
@ OBJECT_POLICY
Definition: parsenodes.h:2289
@ OBJECT_OPERATOR
Definition: parsenodes.h:2286
@ OBJECT_FOREIGN_TABLE
Definition: parsenodes.h:2279
@ OBJECT_TSCONFIGURATION
Definition: parsenodes.h:2306
@ OBJECT_OPFAMILY
Definition: parsenodes.h:2287
@ OBJECT_DOMAIN
Definition: parsenodes.h:2273
@ OBJECT_COLUMN
Definition: parsenodes.h:2267
@ OBJECT_TABLESPACE
Definition: parsenodes.h:2303
@ OBJECT_ROLE
Definition: parsenodes.h:2294
@ OBJECT_ROUTINE
Definition: parsenodes.h:2295
@ OBJECT_LARGEOBJECT
Definition: parsenodes.h:2283
@ OBJECT_PUBLICATION_NAMESPACE
Definition: parsenodes.h:2292
@ OBJECT_PROCEDURE
Definition: parsenodes.h:2290
@ OBJECT_EXTENSION
Definition: parsenodes.h:2276
@ OBJECT_INDEX
Definition: parsenodes.h:2281
@ OBJECT_DEFAULT
Definition: parsenodes.h:2271
@ OBJECT_DATABASE
Definition: parsenodes.h:2270
@ OBJECT_SEQUENCE
Definition: parsenodes.h:2298
@ OBJECT_TSTEMPLATE
Definition: parsenodes.h:2309
@ OBJECT_LANGUAGE
Definition: parsenodes.h:2282
@ OBJECT_AMOP
Definition: parsenodes.h:2263
@ OBJECT_PUBLICATION_REL
Definition: parsenodes.h:2293
@ OBJECT_FOREIGN_SERVER
Definition: parsenodes.h:2278
@ OBJECT_TSDICTIONARY
Definition: parsenodes.h:2307
@ OBJECT_ATTRIBUTE
Definition: parsenodes.h:2265
@ OBJECT_PUBLICATION
Definition: parsenodes.h:2291
@ OBJECT_RULE
Definition: parsenodes.h:2296
@ OBJECT_CONVERSION
Definition: parsenodes.h:2269
@ OBJECT_AMPROC
Definition: parsenodes.h:2264
@ OBJECT_TABLE
Definition: parsenodes.h:2302
@ OBJECT_VIEW
Definition: parsenodes.h:2312
@ OBJECT_PARAMETER_ACL
Definition: parsenodes.h:2288
@ OBJECT_TYPE
Definition: parsenodes.h:2310
@ OBJECT_FUNCTION
Definition: parsenodes.h:2280
@ OBJECT_TABCONSTRAINT
Definition: parsenodes.h:2301
@ OBJECT_DOMCONSTRAINT
Definition: parsenodes.h:2274
@ OBJECT_SUBSCRIPTION
Definition: parsenodes.h:2299
@ OBJECT_STATISTIC_EXT
Definition: parsenodes.h:2300
@ OBJECT_CAST
Definition: parsenodes.h:2266
@ OBJECT_TRIGGER
Definition: parsenodes.h:2305
@ OBJECT_TRANSFORM
Definition: parsenodes.h:2304
FormData_pg_constraint * Form_pg_constraint
#define linitial_node(type, l)
Definition: pg_list.h:181
#define lsecond_node(type, l)
Definition: pg_list.h:186
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
unsigned int Oid
Definition: postgres_ext.h:31
#define RelationGetRelid(relation)
Definition: rel.h:505
#define RelationGetRelationName(relation)
Definition: rel.h:539
Definition: pg_list.h:54
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:266
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:218
#define strVal(v)
Definition: value.h:82

References aclcheck_error(), aclcheck_error_type(), ACLCHECK_NOT_OWNER, castNode, ObjectAddress::classId, elog, ereport, errcode(), errdetail(), errmsg(), ERROR, format_type_be(), GETSTRUCT, GetUserNameFromId(), has_createrole_privilege(), HeapTupleIsValid, is_admin_of_role(), linitial_node, lo_compat_privileges, lsecond_node, NameListToString(), OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_AMOP, OBJECT_AMPROC, OBJECT_ATTRIBUTE, 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_ownercheck(), 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, ObjectIdGetDatum(), 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 2781 of file objectaddress.c.

2782 {
2783  HeapTuple tuple;
2784  Oid classId = RelationGetRelid(catalog);
2785  int oidCacheId = get_object_catcache_oid(classId);
2786 
2787  if (oidCacheId > 0)
2788  {
2789  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2790  if (!HeapTupleIsValid(tuple)) /* should not happen */
2791  return NULL;
2792  }
2793  else
2794  {
2795  Oid oidIndexId = get_object_oid_index(classId);
2796  SysScanDesc scan;
2797  ScanKeyData skey;
2798 
2799  Assert(OidIsValid(oidIndexId));
2800 
2801  ScanKeyInit(&skey,
2802  oidcol,
2803  BTEqualStrategyNumber, F_OIDEQ,
2804  ObjectIdGetDatum(objectId));
2805 
2806  scan = systable_beginscan(catalog, oidIndexId, true,
2807  NULL, 1, &skey);
2808  tuple = systable_getnext(scan);
2809  if (!HeapTupleIsValid(tuple))
2810  {
2811  systable_endscan(scan);
2812  return NULL;
2813  }
2814  tuple = heap_copytuple(tuple);
2815 
2816  systable_endscan(scan);
2817  }
2818 
2819  return tuple;
2820 }
#define Assert(condition)
Definition: c.h:858
#define OidIsValid(objectId)
Definition: c.h:775
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:596
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:503
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:384
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:776
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:86

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(), pg_get_acl(), 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 922 of file objectaddress.c.

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

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_ATTRIBUTE, 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 1545 of file objectaddress.c.

1548 {
1549  ObjectAddress address;
1550  List *relname;
1551  Oid reloid;
1552  Relation relation;
1553  const char *attname;
1555  TupleDesc tupdesc;
1556  Oid defoid;
1557 
1558  /* Extract relation name and open relation. */
1559  if (list_length(object) < 2)
1560  ereport(ERROR,
1561  (errcode(ERRCODE_SYNTAX_ERROR),
1562  errmsg("column name must be qualified")));
1563  attname = strVal(llast(object));
1564  relname = list_copy_head(object, list_length(object) - 1);
1565  /* XXX no missing_ok support here */
1566  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1567  reloid = RelationGetRelid(relation);
1568 
1569  tupdesc = RelationGetDescr(relation);
1570 
1571  /* Look up attribute number and fetch the pg_attrdef OID */
1572  attnum = get_attnum(reloid, attname);
1573  defoid = InvalidOid;
1574  if (attnum != InvalidAttrNumber && tupdesc->constr != NULL)
1575  defoid = GetAttrDefaultOid(reloid, attnum);
1576  if (!OidIsValid(defoid))
1577  {
1578  if (!missing_ok)
1579  ereport(ERROR,
1580  (errcode(ERRCODE_UNDEFINED_COLUMN),
1581  errmsg("default value for column \"%s\" of relation \"%s\" does not exist",
1583 
1584  address.classId = AttrDefaultRelationId;
1585  address.objectId = InvalidOid;
1586  address.objectSubId = InvalidAttrNumber;
1587  relation_close(relation, lockmode);
1588  return address;
1589  }
1590 
1591  address.classId = AttrDefaultRelationId;
1592  address.objectId = defoid;
1593  address.objectSubId = 0;
1594 
1595  *relp = relation;
1596  return address;
1597 }
int16 AttrNumber
Definition: attnum.h:21
#define InvalidAttrNumber
Definition: attnum.h:23
List * list_copy_head(const List *oldlist, int len)
Definition: list.c:1593
AttrNumber get_attnum(Oid relid, const char *attname)
Definition: lsyscache.c:858
RangeVar * makeRangeVarFromNameList(const List *names)
Definition: namespace.c:3539
Oid GetAttrDefaultOid(Oid relid, AttrNumber attnum)
Definition: pg_attrdef.c:339
NameData attname
Definition: pg_attribute.h:41
int16 attnum
Definition: pg_attribute.h:74
NameData relname
Definition: pg_class.h:38
#define llast(l)
Definition: pg_list.h:198
static int list_length(const List *l)
Definition: pg_list.h:152
#define RelationGetDescr(relation)
Definition: rel.h:531
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:205
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:137
TupleConstr * constr
Definition: tupdesc.h:85

References attname, attnum, ObjectAddress::classId, TupleDescData::constr, ereport, errcode(), errmsg(), ERROR, get_attnum(), GetAttrDefaultOid(), InvalidAttrNumber, InvalidOid, list_copy_head(), list_length(), 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 1494 of file objectaddress.c.

1497 {
1498  ObjectAddress address;
1499  List *relname;
1500  Oid reloid;
1501  Relation relation;
1502  const char *attname;
1504 
1505  /* Extract relation name and open relation. */
1506  if (list_length(object) < 2)
1507  ereport(ERROR,
1508  (errcode(ERRCODE_SYNTAX_ERROR),
1509  errmsg("column name must be qualified")));
1510  attname = strVal(llast(object));
1511  relname = list_copy_head(object, list_length(object) - 1);
1512  /* XXX no missing_ok support here */
1513  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1514  reloid = RelationGetRelid(relation);
1515 
1516  /* Look up attribute and construct return value. */
1517  attnum = get_attnum(reloid, attname);
1518  if (attnum == InvalidAttrNumber)
1519  {
1520  if (!missing_ok)
1521  ereport(ERROR,
1522  (errcode(ERRCODE_UNDEFINED_COLUMN),
1523  errmsg("column \"%s\" of relation \"%s\" does not exist",
1525 
1526  address.classId = RelationRelationId;
1527  address.objectId = InvalidOid;
1528  address.objectSubId = InvalidAttrNumber;
1529  relation_close(relation, lockmode);
1530  return address;
1531  }
1532 
1533  address.classId = RelationRelationId;
1534  address.objectId = reloid;
1535  address.objectSubId = attnum;
1536 
1537  *relp = relation;
1538  return address;
1539 }

References attname, attnum, ObjectAddress::classId, ereport, errcode(), errmsg(), ERROR, get_attnum(), InvalidAttrNumber, InvalidOid, list_copy_head(), list_length(), 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 1958 of file objectaddress.c.

1959 {
1960  HeapTuple tp;
1961  Oid userid;
1962  Oid schemaid;
1963  char *username;
1964  char *schema;
1965  char objtype;
1966  char *objtype_str;
1967  ObjectAddress address;
1968 
1969  ObjectAddressSet(address, DefaultAclRelationId, InvalidOid);
1970 
1971  /*
1972  * First figure out the textual attributes so that they can be used for
1973  * error reporting.
1974  */
1975  username = strVal(lsecond(object));
1976  if (list_length(object) >= 3)
1977  schema = (char *) strVal(lthird(object));
1978  else
1979  schema = NULL;
1980 
1981  /*
1982  * Decode defaclobjtype. Only first char is considered; the rest of the
1983  * string, if any, is blissfully ignored.
1984  */
1985  objtype = ((char *) strVal(linitial(object)))[0];
1986  switch (objtype)
1987  {
1988  case DEFACLOBJ_RELATION:
1989  objtype_str = "tables";
1990  break;
1991  case DEFACLOBJ_SEQUENCE:
1992  objtype_str = "sequences";
1993  break;
1994  case DEFACLOBJ_FUNCTION:
1995  objtype_str = "functions";
1996  break;
1997  case DEFACLOBJ_TYPE:
1998  objtype_str = "types";
1999  break;
2000  case DEFACLOBJ_NAMESPACE:
2001  objtype_str = "schemas";
2002  break;
2003  default:
2004  ereport(ERROR,
2005  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2006  errmsg("unrecognized default ACL object type \"%c\"", objtype),
2007  errhint("Valid object types are \"%c\", \"%c\", \"%c\", \"%c\", \"%c\".",
2008  DEFACLOBJ_RELATION,
2009  DEFACLOBJ_SEQUENCE,
2010  DEFACLOBJ_FUNCTION,
2011  DEFACLOBJ_TYPE,
2012  DEFACLOBJ_NAMESPACE)));
2013  }
2014 
2015  /*
2016  * Look up user ID. Behave as "default ACL not found" if the user doesn't
2017  * exist.
2018  */
2019  tp = SearchSysCache1(AUTHNAME,
2021  if (!HeapTupleIsValid(tp))
2022  goto not_found;
2023  userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
2024  ReleaseSysCache(tp);
2025 
2026  /*
2027  * If a schema name was given, look up its OID. If it doesn't exist,
2028  * behave as "default ACL not found".
2029  */
2030  if (schema)
2031  {
2032  schemaid = get_namespace_oid(schema, true);
2033  if (schemaid == InvalidOid)
2034  goto not_found;
2035  }
2036  else
2037  schemaid = InvalidOid;
2038 
2039  /* Finally, look up the pg_default_acl object */
2040  tp = SearchSysCache3(DEFACLROLENSPOBJ,
2041  ObjectIdGetDatum(userid),
2042  ObjectIdGetDatum(schemaid),
2043  CharGetDatum(objtype));
2044  if (!HeapTupleIsValid(tp))
2045  goto not_found;
2046 
2047  address.objectId = ((Form_pg_default_acl) GETSTRUCT(tp))->oid;
2048  ReleaseSysCache(tp);
2049 
2050  return address;
2051 
2052 not_found:
2053  if (!missing_ok)
2054  {
2055  if (schema)
2056  ereport(ERROR,
2057  (errcode(ERRCODE_UNDEFINED_OBJECT),
2058  errmsg("default ACL for user \"%s\" in schema \"%s\" on %s does not exist",
2059  username, schema, objtype_str)));
2060  else
2061  ereport(ERROR,
2062  (errcode(ERRCODE_UNDEFINED_OBJECT),
2063  errmsg("default ACL for user \"%s\" on %s does not exist",
2064  username, objtype_str)));
2065  }
2066  return address;
2067 }
int errhint(const char *fmt,...)
Definition: elog.c:1319
static char * username
Definition: initdb.c:153
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3520
#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:188
#define linitial(l)
Definition: pg_list.h:178
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:350
static Datum CharGetDatum(char X)
Definition: postgres.h:122
HeapTuple SearchSysCache3(int cacheId, Datum key1, Datum key2, Datum key3)
Definition: syscache.c:240

References CharGetDatum(), CStringGetDatum(), 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 1642 of file objectaddress.c.

1643 {
1644  Oid amoid;
1645  ObjectAddress address;
1646 
1647  /* XXX no missing_ok support here */
1648  amoid = get_index_am_oid(strVal(linitial(object)), false);
1649  object = list_copy_tail(object, 1);
1650 
1651  switch (objtype)
1652  {
1653  case OBJECT_OPCLASS:
1654  address.classId = OperatorClassRelationId;
1655  address.objectId = get_opclass_oid(amoid, object, missing_ok);
1656  address.objectSubId = 0;
1657  break;
1658  case OBJECT_OPFAMILY:
1659  address.classId = OperatorFamilyRelationId;
1660  address.objectId = get_opfamily_oid(amoid, object, missing_ok);
1661  address.objectSubId = 0;
1662  break;
1663  default:
1664  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1665  /* placate compiler, which doesn't know elog won't return */
1666  address.classId = InvalidOid;
1667  address.objectId = InvalidOid;
1668  address.objectSubId = 0;
1669  }
1670 
1671  return address;
1672 }
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:1613
Oid get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
Definition: opclasscmds.c:219
Oid get_opfamily_oid(Oid amID, List *opfamilyname, bool missing_ok)
Definition: opclasscmds.c:138

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

1682 {
1683  ObjectAddress famaddr;
1684  ObjectAddress address;
1685  ListCell *cell;
1686  List *copy;
1687  TypeName *typenames[2];
1688  Oid typeoids[2];
1689  int membernum;
1690  int i;
1691 
1692  /*
1693  * The last element of the object list contains the strategy or procedure
1694  * number. We need to strip that out before getting the opclass/family
1695  * address. The rest can be used directly by get_object_address_opcf().
1696  */
1697  membernum = atoi(strVal(llast(linitial(object))));
1698  copy = list_copy_head(linitial(object), list_length(linitial(object)) - 1);
1699 
1700  /* no missing_ok support here */
1701  famaddr = get_object_address_opcf(OBJECT_OPFAMILY, copy, false);
1702 
1703  /* find out left/right type names and OIDs */
1704  typenames[0] = typenames[1] = NULL;
1705  typeoids[0] = typeoids[1] = InvalidOid;
1706  i = 0;
1707  foreach(cell, lsecond(object))
1708  {
1709  ObjectAddress typaddr;
1710 
1711  typenames[i] = lfirst_node(TypeName, cell);
1712  typaddr = get_object_address_type(OBJECT_TYPE, typenames[i], missing_ok);
1713  typeoids[i] = typaddr.objectId;
1714  if (++i >= 2)
1715  break;
1716  }
1717 
1718  switch (objtype)
1719  {
1720  case OBJECT_AMOP:
1721  {
1722  HeapTuple tp;
1723 
1724  ObjectAddressSet(address, AccessMethodOperatorRelationId,
1725  InvalidOid);
1726 
1727  tp = SearchSysCache4(AMOPSTRATEGY,
1728  ObjectIdGetDatum(famaddr.objectId),
1729  ObjectIdGetDatum(typeoids[0]),
1730  ObjectIdGetDatum(typeoids[1]),
1731  Int16GetDatum(membernum));
1732  if (!HeapTupleIsValid(tp))
1733  {
1734  if (!missing_ok)
1735  ereport(ERROR,
1736  (errcode(ERRCODE_UNDEFINED_OBJECT),
1737  errmsg("operator %d (%s, %s) of %s does not exist",
1738  membernum,
1741  getObjectDescription(&famaddr, false))));
1742  }
1743  else
1744  {
1745  address.objectId = ((Form_pg_amop) GETSTRUCT(tp))->oid;
1746  ReleaseSysCache(tp);
1747  }
1748  }
1749  break;
1750 
1751  case OBJECT_AMPROC:
1752  {
1753  HeapTuple tp;
1754 
1755  ObjectAddressSet(address, AccessMethodProcedureRelationId,
1756  InvalidOid);
1757 
1758  tp = SearchSysCache4(AMPROCNUM,
1759  ObjectIdGetDatum(famaddr.objectId),
1760  ObjectIdGetDatum(typeoids[0]),
1761  ObjectIdGetDatum(typeoids[1]),
1762  Int16GetDatum(membernum));
1763  if (!HeapTupleIsValid(tp))
1764  {
1765  if (!missing_ok)
1766  ereport(ERROR,
1767  (errcode(ERRCODE_UNDEFINED_OBJECT),
1768  errmsg("function %d (%s, %s) of %s does not exist",
1769  membernum,
1772  getObjectDescription(&famaddr, false))));
1773  }
1774  else
1775  {
1776  address.objectId = ((Form_pg_amproc) GETSTRUCT(tp))->oid;
1777  ReleaseSysCache(tp);
1778  }
1779  }
1780  break;
1781  default:
1782  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1783  }
1784 
1785  return address;
1786 }
int i
Definition: isn.c:73
const char ** typenames
Definition: lexi.c:115
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
char * TypeNameToString(const TypeName *typeName)
Definition: parse_type.c:478
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:176
static Datum Int16GetDatum(int16 X)
Definition: postgres.h:172
HeapTuple SearchSysCache4(int cacheId, Datum key1, Datum key2, Datum key3, Datum key4)
Definition: syscache.c:251

References elog, ereport, errcode(), errmsg(), ERROR, get_object_address_opcf(), get_object_address_type(), getObjectDescription(), GETSTRUCT, HeapTupleIsValid, i, Int16GetDatum(), InvalidOid, lfirst_node, linitial, list_copy_head(), list_length(), llast, lsecond, OBJECT_AMOP, OBJECT_AMPROC, OBJECT_OPFAMILY, OBJECT_TYPE, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache4(), strVal, typenames, 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 1863 of file objectaddress.c.

1865 {
1866  ObjectAddress address;
1867  Relation relation;
1868  List *relname;
1869  char *pubname;
1870  Publication *pub;
1871 
1872  ObjectAddressSet(address, PublicationRelRelationId, InvalidOid);
1873 
1874  relname = linitial(object);
1876  AccessShareLock, missing_ok);
1877  if (!relation)
1878  return address;
1879 
1880  /* fetch publication name from input list */
1881  pubname = strVal(lsecond(object));
1882 
1883  /* Now look up the pg_publication tuple */
1884  pub = GetPublicationByName(pubname, missing_ok);
1885  if (!pub)
1886  {
1887  relation_close(relation, AccessShareLock);
1888  return address;
1889  }
1890 
1891  /* Find the publication relation mapping in syscache. */
1892  address.objectId =
1893  GetSysCacheOid2(PUBLICATIONRELMAP, Anum_pg_publication_rel_oid,
1895  ObjectIdGetDatum(pub->oid));
1896  if (!OidIsValid(address.objectId))
1897  {
1898  if (!missing_ok)
1899  ereport(ERROR,
1900  (errcode(ERRCODE_UNDEFINED_OBJECT),
1901  errmsg("publication relation \"%s\" in publication \"%s\" does not exist",
1902  RelationGetRelationName(relation), pubname)));
1903  relation_close(relation, AccessShareLock);
1904  return address;
1905  }
1906 
1907  *relp = relation;
1908  return address;
1909 }
#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:172
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition: syscache.h:106

References AccessShareLock, ereport, errcode(), errmsg(), ERROR, GetPublicationByName(), GetSysCacheOid2, InvalidOid, linitial, lsecond, makeRangeVarFromNameList(), ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), Publication::oid, OidIsValid, 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 1916 of file objectaddress.c.

1917 {
1918  ObjectAddress address;
1919  Publication *pub;
1920  char *pubname;
1921  char *schemaname;
1922  Oid schemaid;
1923 
1924  ObjectAddressSet(address, PublicationNamespaceRelationId, InvalidOid);
1925 
1926  /* Fetch schema name and publication name from input list */
1927  schemaname = strVal(linitial(object));
1928  pubname = strVal(lsecond(object));
1929 
1930  schemaid = get_namespace_oid(schemaname, missing_ok);
1931  if (!OidIsValid(schemaid))
1932  return address;
1933 
1934  /* Now look up the pg_publication tuple */
1935  pub = GetPublicationByName(pubname, missing_ok);
1936  if (!pub)
1937  return address;
1938 
1939  /* Find the publication schema mapping in syscache */
1940  address.objectId =
1941  GetSysCacheOid2(PUBLICATIONNAMESPACEMAP,
1942  Anum_pg_publication_namespace_oid,
1943  ObjectIdGetDatum(schemaid),
1944  ObjectIdGetDatum(pub->oid));
1945  if (!OidIsValid(address.objectId) && !missing_ok)
1946  ereport(ERROR,
1947  (errcode(ERRCODE_UNDEFINED_OBJECT),
1948  errmsg("publication schema \"%s\" in publication \"%s\" does not exist",
1949  schemaname, pubname)));
1950 
1951  return address;
1952 }

References ereport, errcode(), errmsg(), ERROR, get_namespace_oid(), GetPublicationByName(), GetSysCacheOid2, InvalidOid, linitial, lsecond, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum(), Publication::oid, OidIsValid, 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 1415 of file objectaddress.c.

1417 {
1418  ObjectAddress address;
1419  Relation relation = NULL;
1420  int nnames;
1421  const char *depname;
1422  List *relname;
1423  Oid reloid;
1424 
1425  /* Extract name of dependent object. */
1426  depname = strVal(llast(object));
1427 
1428  /* Separate relation name from dependent object name. */
1429  nnames = list_length(object);
1430  if (nnames < 2)
1431  ereport(ERROR,
1432  (errcode(ERRCODE_SYNTAX_ERROR),
1433  errmsg("must specify relation and object name")));
1434 
1435  /* Extract relation name and open relation. */
1436  relname = list_copy_head(object, nnames - 1);
1439  missing_ok);
1440 
1441  reloid = relation ? RelationGetRelid(relation) : InvalidOid;
1442 
1443  switch (objtype)
1444  {
1445  case OBJECT_RULE:
1446  address.classId = RewriteRelationId;
1447  address.objectId = relation ?
1448  get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
1449  address.objectSubId = 0;
1450  break;
1451  case OBJECT_TRIGGER:
1452  address.classId = TriggerRelationId;
1453  address.objectId = relation ?
1454  get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
1455  address.objectSubId = 0;
1456  break;
1457  case OBJECT_TABCONSTRAINT:
1458  address.classId = ConstraintRelationId;
1459  address.objectId = relation ?
1460  get_relation_constraint_oid(reloid, depname, missing_ok) :
1461  InvalidOid;
1462  address.objectSubId = 0;
1463  break;
1464  case OBJECT_POLICY:
1465  address.classId = PolicyRelationId;
1466  address.objectId = relation ?
1467  get_relation_policy_oid(reloid, depname, missing_ok) :
1468  InvalidOid;
1469  address.objectSubId = 0;
1470  break;
1471  default:
1472  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1473  }
1474 
1475  /* Avoid relcache leak when object not found. */
1476  if (!OidIsValid(address.objectId))
1477  {
1478  if (relation != NULL)
1479  table_close(relation, AccessShareLock);
1480 
1481  relation = NULL; /* department of accident prevention */
1482  return address;
1483  }
1484 
1485  /* Done. */
1486  *relp = relation;
1487  return address;
1488 }
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:1204
Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok)
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: table.c:103
Oid get_trigger_oid(Oid relid, const char *trigname, bool missing_ok)
Definition: trigger.c:1365

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_head(), list_length(), 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 1220 of file objectaddress.c.

1223 {
1224  if (rel)
1225  {
1226  object = lcons(makeString(rel->relname), object);
1227  if (rel->schemaname)
1228  object = lcons(makeString(rel->schemaname), object);
1229  if (rel->catalogname)
1230  object = lcons(makeString(rel->catalogname), object);
1231  }
1232 
1233  return get_object_address(objtype, (Node *) object,
1234  relp, lockmode, missing_ok);
1235 }
List * lcons(void *datum, List *list)
Definition: list.c:495
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
Definition: nodes.h:129
char * relname
Definition: primnodes.h:82
char * catalogname
Definition: primnodes.h:76
char * schemaname
Definition: primnodes.h:79
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 1603 of file objectaddress.c.

1604 {
1605  ObjectAddress address;
1606  Type tup;
1607 
1608  address.classId = TypeRelationId;
1609  address.objectId = InvalidOid;
1610  address.objectSubId = 0;
1611 
1612  tup = LookupTypeName(NULL, typename, NULL, missing_ok);
1613  if (!HeapTupleIsValid(tup))
1614  {
1615  if (!missing_ok)
1616  ereport(ERROR,
1617  (errcode(ERRCODE_UNDEFINED_OBJECT),
1618  errmsg("type \"%s\" does not exist",
1619  TypeNameToString(typename))));
1620  return address;
1621  }
1622  address.objectId = typeTypeId(tup);
1623 
1624  if (objtype == OBJECT_DOMAIN)
1625  {
1626  if (((Form_pg_type) GETSTRUCT(tup))->typtype != TYPTYPE_DOMAIN)
1627  ereport(ERROR,
1628  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1629  errmsg("\"%s\" is not a domain",
1630  TypeNameToString(typename))));
1631  }
1632 
1633  ReleaseSysCache(tup);
1634 
1635  return address;
1636 }
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:590
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 1242 of file objectaddress.c.

1244 {
1245  const char *name;
1246  ObjectAddress address;
1247 
1248  name = strVal(strval);
1249 
1250  /* Translate name to OID. */
1251  switch (objtype)
1252  {
1253  case OBJECT_ACCESS_METHOD:
1254  address.classId = AccessMethodRelationId;
1255  address.objectId = get_am_oid(name, missing_ok);
1256  address.objectSubId = 0;
1257  break;
1258  case OBJECT_DATABASE:
1259  address.classId = DatabaseRelationId;
1260  address.objectId = get_database_oid(name, missing_ok);
1261  address.objectSubId = 0;
1262  break;
1263  case OBJECT_EXTENSION:
1264  address.classId = ExtensionRelationId;
1265  address.objectId = get_extension_oid(name, missing_ok);
1266  address.objectSubId = 0;
1267  break;
1268  case OBJECT_TABLESPACE:
1269  address.classId = TableSpaceRelationId;
1270  address.objectId = get_tablespace_oid(name, missing_ok);
1271  address.objectSubId = 0;
1272  break;
1273  case OBJECT_ROLE:
1274  address.classId = AuthIdRelationId;
1275  address.objectId = get_role_oid(name, missing_ok);
1276  address.objectSubId = 0;
1277  break;
1278  case OBJECT_SCHEMA:
1279  address.classId = NamespaceRelationId;
1280  address.objectId = get_namespace_oid(name, missing_ok);
1281  address.objectSubId = 0;
1282  break;
1283  case OBJECT_LANGUAGE:
1284  address.classId = LanguageRelationId;
1285  address.objectId = get_language_oid(name, missing_ok);
1286  address.objectSubId = 0;
1287  break;
1288  case OBJECT_FDW:
1289  address.classId = ForeignDataWrapperRelationId;
1290  address.objectId = get_foreign_data_wrapper_oid(name, missing_ok);
1291  address.objectSubId = 0;
1292  break;
1293  case OBJECT_FOREIGN_SERVER:
1294  address.classId = ForeignServerRelationId;
1295  address.objectId = get_foreign_server_oid(name, missing_ok);
1296  address.objectSubId = 0;
1297  break;
1298  case OBJECT_EVENT_TRIGGER:
1299  address.classId = EventTriggerRelationId;
1300  address.objectId = get_event_trigger_oid(name, missing_ok);
1301  address.objectSubId = 0;
1302  break;
1303  case OBJECT_PARAMETER_ACL:
1304  address.classId = ParameterAclRelationId;
1305  address.objectId = ParameterAclLookup(name, missing_ok);
1306  address.objectSubId = 0;
1307  break;
1308  case OBJECT_PUBLICATION:
1309  address.classId = PublicationRelationId;
1310  address.objectId = get_publication_oid(name, missing_ok);
1311  address.objectSubId = 0;
1312  break;
1313  case OBJECT_SUBSCRIPTION:
1314  address.classId = SubscriptionRelationId;
1315  address.objectId = get_subscription_oid(name, missing_ok);
1316  address.objectSubId = 0;
1317  break;
1318  default:
1319  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1320  /* placate compiler, which doesn't know elog won't return */
1321  address.classId = InvalidOid;
1322  address.objectId = InvalidOid;
1323  address.objectSubId = 0;
1324  }
1325 
1326  return address;
1327 }
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5420
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:1426
Oid get_database_oid(const char *dbname, bool missing_ok)
Definition: dbcommands.c:3119
Oid get_event_trigger_oid(const char *trigname, bool missing_ok)
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:145
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition: foreign.c:694
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition: foreign.c:671
Oid get_publication_oid(const char *pubname, bool missing_ok)
Definition: lsyscache.c:3625
Oid get_subscription_oid(const char *subname, bool missing_ok)
Definition: lsyscache.c:3675
Oid ParameterAclLookup(const char *parameter, bool missing_ok)
const char * name

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

1793 {
1794  ObjectAddress address;
1795  Oid userid;
1796  char *username;
1797  char *servername;
1798  ForeignServer *server;
1799  HeapTuple tp;
1800 
1801  ObjectAddressSet(address, UserMappingRelationId, InvalidOid);
1802 
1803  /* fetch string names from input lists, for error messages */
1804  username = strVal(linitial(object));
1805  servername = strVal(lsecond(object));
1806 
1807  /* look up pg_authid OID of mapped user; InvalidOid if PUBLIC */
1808  if (strcmp(username, "public") == 0)
1809  userid = InvalidOid;
1810  else
1811  {
1812  tp = SearchSysCache1(AUTHNAME,
1814  if (!HeapTupleIsValid(tp))
1815  {
1816  if (!missing_ok)
1817  ereport(ERROR,
1818  (errcode(ERRCODE_UNDEFINED_OBJECT),
1819  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1820  username, servername)));
1821  return address;
1822  }
1823  userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
1824  ReleaseSysCache(tp);
1825  }
1826 
1827  /* Now look up the pg_user_mapping tuple */
1828  server = GetForeignServerByName(servername, true);
1829  if (!server)
1830  {
1831  if (!missing_ok)
1832  ereport(ERROR,
1833  (errcode(ERRCODE_UNDEFINED_OBJECT),
1834  errmsg("server \"%s\" does not exist", servername)));
1835  return address;
1836  }
1837  tp = SearchSysCache2(USERMAPPINGUSERSERVER,
1838  ObjectIdGetDatum(userid),
1839  ObjectIdGetDatum(server->serverid));
1840  if (!HeapTupleIsValid(tp))
1841  {
1842  if (!missing_ok)
1843  ereport(ERROR,
1844  (errcode(ERRCODE_UNDEFINED_OBJECT),
1845  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1846  username, servername)));
1847  return address;
1848  }
1849 
1850  address.objectId = ((Form_pg_user_mapping) GETSTRUCT(tp))->oid;
1851 
1852  ReleaseSysCache(tp);
1853 
1854  return address;
1855 }
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:229

References 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 2684 of file objectaddress.c.

2685 {
2686  const ObjectPropertyType *prop = get_object_property_data(class_id);
2687 
2688  return prop->attnum_acl;
2689 }
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(), ExecGrant_common(), object_aclmask_ext(), pg_get_acl(), and recordExtObjInitPriv().

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

◆ get_object_catcache_name()

int get_object_catcache_name ( Oid  class_id)

Definition at line 2644 of file objectaddress.c.

2645 {
2646  const ObjectPropertyType *prop = get_object_property_data(class_id);
2647 
2648  return prop->name_catcache_id;
2649 }

References get_object_property_data(), and ObjectPropertyType::name_catcache_id.

Referenced by AlterObjectNamespace_internal(), and AlterObjectRename_internal().

◆ get_object_catcache_oid()

◆ get_object_class_descr()

const char* get_object_class_descr ( Oid  class_id)

◆ get_object_namensp_unique()

bool get_object_namensp_unique ( Oid  class_id)

Definition at line 2717 of file objectaddress.c.

2718 {
2719  const ObjectPropertyType *prop = get_object_property_data(class_id);
2720 
2721  return prop->is_nsp_name_unique;
2722 }

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

2565 {
2566  int cache;
2567  HeapTuple tuple;
2568  Oid oid;
2569  const ObjectPropertyType *property;
2570 
2571  /* If not owned by a namespace, just return InvalidOid. */
2572  property = get_object_property_data(address->classId);
2573  if (property->attnum_namespace == InvalidAttrNumber)
2574  return InvalidOid;
2575 
2576  /* Currently, we can only handle object types with system caches. */
2577  cache = property->oid_catcache_id;
2578  Assert(cache != -1);
2579 
2580  /* Fetch tuple from syscache and extract namespace attribute. */
2581  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2582  if (!HeapTupleIsValid(tuple))
2583  elog(ERROR, "cache lookup failed for cache %d oid %u",
2584  cache, address->objectId);
2586  tuple,
2587  property->attnum_namespace));
2588  ReleaseSysCache(tuple);
2589 
2590  return oid;
2591 }
static Oid DatumGetObjectId(Datum X)
Definition: postgres.h:242
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition: syscache.c:510

References Assert, ObjectPropertyType::attnum_namespace, ObjectAddress::classId, DatumGetObjectId(), elog, ERROR, get_object_property_data(), HeapTupleIsValid, InvalidAttrNumber, InvalidOid, ObjectAddress::objectId, ObjectIdGetDatum(), ReleaseSysCache(), SearchSysCache1(), and SysCacheGetAttrNotNull().

Referenced by RemoveObjects().

◆ get_object_oid_index()

Oid get_object_oid_index ( Oid  class_id)

Definition at line 2628 of file objectaddress.c.

2629 {
2630  const ObjectPropertyType *prop = get_object_property_data(class_id);
2631 
2632  return prop->oid_index_oid;
2633 }

References get_object_property_data(), and ObjectPropertyType::oid_index_oid.

Referenced by DropObjectById(), get_catalog_object_by_oid(), and object_ownercheck().

◆ get_object_property_data()

static const ObjectPropertyType * get_object_property_data ( Oid  class_id)
static

Definition at line 2746 of file objectaddress.c.

2747 {
2748  static const ObjectPropertyType *prop_last = NULL;
2749  int index;
2750 
2751  /*
2752  * A shortcut to speed up multiple consecutive lookups of a particular
2753  * object class.
2754  */
2755  if (prop_last && prop_last->class_oid == class_id)
2756  return prop_last;
2757 
2758  for (index = 0; index < lengthof(ObjectProperty); index++)
2759  {
2760  if (ObjectProperty[index].class_oid == class_id)
2761  {
2762  prop_last = &ObjectProperty[index];
2763  return &ObjectProperty[index];
2764  }
2765  }
2766 
2767  ereport(ERROR,
2768  (errmsg_internal("unrecognized class ID: %u", class_id)));
2769 
2770  return NULL; /* keep MSC compiler happy */
2771 }
#define lengthof(array)
Definition: c.h:788
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1159
static const ObjectPropertyType ObjectProperty[]
Definition: type.h:95

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

2700 {
2701  const ObjectPropertyType *prop = get_object_property_data(class_id);
2702 
2703  if (prop->objtype == OBJECT_TABLE)
2704  {
2705  /*
2706  * If the property data says it's a table, dig a little deeper to get
2707  * the real relation kind, so that callers can produce more precise
2708  * error messages.
2709  */
2710  return get_relkind_objtype(get_rel_relkind(object_id));
2711  }
2712  else
2713  return prop->objtype;
2714 }
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:2003
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(), AlterObjectRename_internal(), ExecGrant_common(), and object_aclmask_ext().

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

1336 {
1337  Relation relation;
1338  ObjectAddress address;
1339 
1340  address.classId = RelationRelationId;
1341  address.objectId = InvalidOid;
1342  address.objectSubId = 0;
1343 
1345  lockmode, missing_ok);
1346  if (!relation)
1347  return address;
1348 
1349  switch (objtype)
1350  {
1351  case OBJECT_INDEX:
1352  if (relation->rd_rel->relkind != RELKIND_INDEX &&
1353  relation->rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
1354  ereport(ERROR,
1355  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1356  errmsg("\"%s\" is not an index",
1357  RelationGetRelationName(relation))));
1358  break;
1359  case OBJECT_SEQUENCE:
1360  if (relation->rd_rel->relkind != RELKIND_SEQUENCE)
1361  ereport(ERROR,
1362  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1363  errmsg("\"%s\" is not a sequence",
1364  RelationGetRelationName(relation))));
1365  break;
1366  case OBJECT_TABLE:
1367  if (relation->rd_rel->relkind != RELKIND_RELATION &&
1368  relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1369  ereport(ERROR,
1370  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1371  errmsg("\"%s\" is not a table",
1372  RelationGetRelationName(relation))));
1373  break;
1374  case OBJECT_VIEW:
1375  if (relation->rd_rel->relkind != RELKIND_VIEW)
1376  ereport(ERROR,
1377  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1378  errmsg("\"%s\" is not a view",
1379  RelationGetRelationName(relation))));
1380  break;
1381  case OBJECT_MATVIEW:
1382  if (relation->rd_rel->relkind != RELKIND_MATVIEW)
1383  ereport(ERROR,
1384  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1385  errmsg("\"%s\" is not a materialized view",
1386  RelationGetRelationName(relation))));
1387  break;
1388  case OBJECT_FOREIGN_TABLE:
1389  if (relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE)
1390  ereport(ERROR,
1391  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1392  errmsg("\"%s\" is not a foreign table",
1393  RelationGetRelationName(relation))));
1394  break;
1395  default:
1396  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1397  break;
1398  }
1399 
1400  /* Done. */
1401  address.objectId = RelationGetRelid(relation);
1402  *relp = relation;
1403 
1404  return address;
1405 }
Form_pg_class rd_rel
Definition: rel.h:111

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

6127 {
6128  switch (relkind)
6129  {
6130  case RELKIND_RELATION:
6131  case RELKIND_PARTITIONED_TABLE:
6132  return OBJECT_TABLE;
6133  case RELKIND_INDEX:
6134  case RELKIND_PARTITIONED_INDEX:
6135  return OBJECT_INDEX;
6136  case RELKIND_SEQUENCE:
6137  return OBJECT_SEQUENCE;
6138  case RELKIND_VIEW:
6139  return OBJECT_VIEW;
6140  case RELKIND_MATVIEW:
6141  return OBJECT_MATVIEW;
6142  case RELKIND_FOREIGN_TABLE:
6143  return OBJECT_FOREIGN_TABLE;
6144  case RELKIND_TOASTVALUE:
6145  return OBJECT_TABLE;
6146  default:
6147  /* Per above, don't raise an error */
6148  return OBJECT_TABLE;
6149  }
6150 }

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

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

◆ getConstraintTypeDescription()

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

Definition at line 4694 of file objectaddress.c.

4695 {
4696  Relation constrRel;
4697  HeapTuple constrTup;
4698  Form_pg_constraint constrForm;
4699 
4700  constrRel = table_open(ConstraintRelationId, AccessShareLock);
4701  constrTup = get_catalog_object_by_oid(constrRel, Anum_pg_constraint_oid,
4702  constroid);
4703  if (!HeapTupleIsValid(constrTup))
4704  {
4705  if (!missing_ok)
4706  elog(ERROR, "cache lookup failed for constraint %u", constroid);
4707 
4708  table_close(constrRel, AccessShareLock);
4709 
4710  /* fallback to "constraint" for an undefined object */
4711  appendStringInfoString(buffer, "constraint");
4712  return;
4713  }
4714 
4715  constrForm = (Form_pg_constraint) GETSTRUCT(constrTup);
4716 
4717  if (OidIsValid(constrForm->conrelid))
4718  appendStringInfoString(buffer, "table constraint");
4719  else if (OidIsValid(constrForm->contypid))
4720  appendStringInfoString(buffer, "domain constraint");
4721  else
4722  elog(ERROR, "invalid constraint %u", constrForm->oid);
4723 
4724  table_close(constrRel, AccessShareLock);
4725 }
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:182
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40

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

2879 {
2880  StringInfoData buffer;
2881 
2882  initStringInfo(&buffer);
2883 
2884  switch (object->classId)
2885  {
2886  case RelationRelationId:
2887  if (object->objectSubId == 0)
2888  getRelationDescription(&buffer, object->objectId, missing_ok);
2889  else
2890  {
2891  /* column, not whole relation */
2892  StringInfoData rel;
2893  char *attname = get_attname(object->objectId,
2894  object->objectSubId,
2895  missing_ok);
2896 
2897  if (!attname)
2898  break;
2899 
2900  initStringInfo(&rel);
2901  getRelationDescription(&rel, object->objectId, missing_ok);
2902  /* translator: second %s is, e.g., "table %s" */
2903  appendStringInfo(&buffer, _("column %s of %s"),
2904  attname, rel.data);
2905  pfree(rel.data);
2906  }
2907  break;
2908 
2909  case ProcedureRelationId:
2910  {
2912  char *proname = format_procedure_extended(object->objectId,
2913  flags);
2914 
2915  if (proname == NULL)
2916  break;
2917 
2918  appendStringInfo(&buffer, _("function %s"), proname);
2919  break;
2920  }
2921 
2922  case TypeRelationId:
2923  {
2925  char *typname = format_type_extended(object->objectId, -1,
2926  flags);
2927 
2928  if (typname == NULL)
2929  break;
2930 
2931  appendStringInfo(&buffer, _("type %s"), typname);
2932  break;
2933  }
2934 
2935  case CastRelationId:
2936  {
2937  Relation castDesc;
2938  ScanKeyData skey[1];
2939  SysScanDesc rcscan;
2940  HeapTuple tup;
2941  Form_pg_cast castForm;
2942 
2943  castDesc = table_open(CastRelationId, AccessShareLock);
2944 
2945  ScanKeyInit(&skey[0],
2946  Anum_pg_cast_oid,
2947  BTEqualStrategyNumber, F_OIDEQ,
2948  ObjectIdGetDatum(object->objectId));
2949 
2950  rcscan = systable_beginscan(castDesc, CastOidIndexId, true,
2951  NULL, 1, skey);
2952 
2953  tup = systable_getnext(rcscan);
2954 
2955  if (!HeapTupleIsValid(tup))
2956  {
2957  if (!missing_ok)
2958  elog(ERROR, "could not find tuple for cast %u",
2959  object->objectId);
2960 
2961  systable_endscan(rcscan);
2962  table_close(castDesc, AccessShareLock);
2963  break;
2964  }
2965 
2966  castForm = (Form_pg_cast) GETSTRUCT(tup);
2967 
2968  appendStringInfo(&buffer, _("cast from %s to %s"),
2969  format_type_be(castForm->castsource),
2970  format_type_be(castForm->casttarget));
2971 
2972  systable_endscan(rcscan);
2973  table_close(castDesc, AccessShareLock);
2974  break;
2975  }
2976 
2977  case CollationRelationId:
2978  {
2979  HeapTuple collTup;
2980  Form_pg_collation coll;
2981  char *nspname;
2982 
2983  collTup = SearchSysCache1(COLLOID,
2984  ObjectIdGetDatum(object->objectId));
2985  if (!HeapTupleIsValid(collTup))
2986  {
2987  if (!missing_ok)
2988  elog(ERROR, "cache lookup failed for collation %u",
2989  object->objectId);
2990  break;
2991  }
2992 
2993  coll = (Form_pg_collation) GETSTRUCT(collTup);
2994 
2995  /* Qualify the name if not visible in search path */
2996  if (CollationIsVisible(object->objectId))
2997  nspname = NULL;
2998  else
2999  nspname = get_namespace_name(coll->collnamespace);
3000 
3001  appendStringInfo(&buffer, _("collation %s"),
3003  NameStr(coll->collname)));
3004  ReleaseSysCache(collTup);
3005  break;
3006  }
3007 
3008  case ConstraintRelationId:
3009  {
3010  HeapTuple conTup;
3011  Form_pg_constraint con;
3012 
3013  conTup = SearchSysCache1(CONSTROID,
3014  ObjectIdGetDatum(object->objectId));
3015  if (!HeapTupleIsValid(conTup))
3016  {
3017  if (!missing_ok)
3018  elog(ERROR, "cache lookup failed for constraint %u",
3019  object->objectId);
3020  break;
3021  }
3022 
3023  con = (Form_pg_constraint) GETSTRUCT(conTup);
3024 
3025  if (OidIsValid(con->conrelid))
3026  {
3027  StringInfoData rel;
3028 
3029  initStringInfo(&rel);
3030  getRelationDescription(&rel, con->conrelid, false);
3031  /* translator: second %s is, e.g., "table %s" */
3032  appendStringInfo(&buffer, _("constraint %s on %s"),
3033  NameStr(con->conname), rel.data);
3034  pfree(rel.data);
3035  }
3036  else
3037  {
3038  appendStringInfo(&buffer, _("constraint %s"),
3039  NameStr(con->conname));
3040  }
3041 
3042  ReleaseSysCache(conTup);
3043  break;
3044  }
3045 
3046  case ConversionRelationId:
3047  {
3048  HeapTuple conTup;
3049  Form_pg_conversion conv;
3050  char *nspname;
3051 
3052  conTup = SearchSysCache1(CONVOID,
3053  ObjectIdGetDatum(object->objectId));
3054  if (!HeapTupleIsValid(conTup))
3055  {
3056  if (!missing_ok)
3057  elog(ERROR, "cache lookup failed for conversion %u",
3058  object->objectId);
3059  break;
3060  }
3061 
3062  conv = (Form_pg_conversion) GETSTRUCT(conTup);
3063 
3064  /* Qualify the name if not visible in search path */
3065  if (ConversionIsVisible(object->objectId))
3066  nspname = NULL;
3067  else
3068  nspname = get_namespace_name(conv->connamespace);
3069 
3070  appendStringInfo(&buffer, _("conversion %s"),
3072  NameStr(conv->conname)));
3073  ReleaseSysCache(conTup);
3074  break;
3075  }
3076 
3077  case AttrDefaultRelationId:
3078  {
3079  ObjectAddress colobject;
3080 
3081  colobject = GetAttrDefaultColumnAddress(object->objectId);
3082 
3083  if (!OidIsValid(colobject.objectId))
3084  {
3085  if (!missing_ok)
3086  elog(ERROR, "could not find tuple for attrdef %u",
3087  object->objectId);
3088  break;
3089  }
3090 
3091  /* translator: %s is typically "column %s of table %s" */
3092  appendStringInfo(&buffer, _("default value for %s"),
3093  getObjectDescription(&colobject, false));
3094  break;
3095  }
3096 
3097  case LanguageRelationId:
3098  {
3099  char *langname = get_language_name(object->objectId,
3100  missing_ok);
3101 
3102  if (langname)
3103  appendStringInfo(&buffer, _("language %s"),
3104  get_language_name(object->objectId, false));
3105  break;
3106  }
3107 
3108  case LargeObjectRelationId:
3109  if (!LargeObjectExists(object->objectId))
3110  break;
3111  appendStringInfo(&buffer, _("large object %u"),
3112  object->objectId);
3113  break;
3114 
3115  case OperatorRelationId:
3116  {
3118  char *oprname = format_operator_extended(object->objectId,
3119  flags);
3120 
3121  if (oprname == NULL)
3122  break;
3123 
3124  appendStringInfo(&buffer, _("operator %s"), oprname);
3125  break;
3126  }
3127 
3128  case OperatorClassRelationId:
3129  {
3130  HeapTuple opcTup;
3131  Form_pg_opclass opcForm;
3132  HeapTuple amTup;
3133  Form_pg_am amForm;
3134  char *nspname;
3135 
3136  opcTup = SearchSysCache1(CLAOID,
3137  ObjectIdGetDatum(object->objectId));
3138  if (!HeapTupleIsValid(opcTup))
3139  {
3140  if (!missing_ok)
3141  elog(ERROR, "cache lookup failed for opclass %u",
3142  object->objectId);
3143  break;
3144  }
3145 
3146  opcForm = (Form_pg_opclass) GETSTRUCT(opcTup);
3147 
3148  amTup = SearchSysCache1(AMOID,
3149  ObjectIdGetDatum(opcForm->opcmethod));
3150  if (!HeapTupleIsValid(amTup))
3151  elog(ERROR, "cache lookup failed for access method %u",
3152  opcForm->opcmethod);
3153  amForm = (Form_pg_am) GETSTRUCT(amTup);
3154 
3155  /* Qualify the name if not visible in search path */
3156  if (OpclassIsVisible(object->objectId))
3157  nspname = NULL;
3158  else
3159  nspname = get_namespace_name(opcForm->opcnamespace);
3160 
3161  appendStringInfo(&buffer, _("operator class %s for access method %s"),
3163  NameStr(opcForm->opcname)),
3164  NameStr(amForm->amname));
3165 
3166  ReleaseSysCache(amTup);
3167  ReleaseSysCache(opcTup);
3168  break;
3169  }
3170 
3171  case OperatorFamilyRelationId:
3172  getOpFamilyDescription(&buffer, object->objectId, missing_ok);
3173  break;
3174 
3175  case AccessMethodRelationId:
3176  {
3177  HeapTuple tup;
3178 
3179  tup = SearchSysCache1(AMOID,
3180  ObjectIdGetDatum(object->objectId));
3181  if (!HeapTupleIsValid(tup))
3182  {
3183  if (!missing_ok)
3184  elog(ERROR, "cache lookup failed for access method %u",
3185  object->objectId);
3186  break;
3187  }
3188 
3189  appendStringInfo(&buffer, _("access method %s"),
3190  NameStr(((Form_pg_am) GETSTRUCT(tup))->amname));
3191  ReleaseSysCache(tup);
3192  break;
3193  }
3194 
3195  case AccessMethodOperatorRelationId:
3196  {
3197  Relation amopDesc;
3198  HeapTuple tup;
3199  ScanKeyData skey[1];
3200  SysScanDesc amscan;
3201  Form_pg_amop amopForm;
3202  StringInfoData opfam;
3203 
3204  amopDesc = table_open(AccessMethodOperatorRelationId,
3205  AccessShareLock);
3206 
3207  ScanKeyInit(&skey[0],
3208  Anum_pg_amop_oid,
3209  BTEqualStrategyNumber, F_OIDEQ,
3210  ObjectIdGetDatum(object->objectId));
3211 
3212  amscan = systable_beginscan(amopDesc, AccessMethodOperatorOidIndexId, true,
3213  NULL, 1, skey);
3214 
3215  tup = systable_getnext(amscan);
3216 
3217  if (!HeapTupleIsValid(tup))
3218  {
3219  if (!missing_ok)
3220  elog(ERROR, "could not find tuple for amop entry %u",
3221  object->objectId);
3222 
3223  systable_endscan(amscan);
3224  table_close(amopDesc, AccessShareLock);
3225  break;
3226  }
3227 
3228  amopForm = (Form_pg_amop) GETSTRUCT(tup);
3229 
3230  initStringInfo(&opfam);
3231  getOpFamilyDescription(&opfam, amopForm->amopfamily, false);
3232 
3233  /*------
3234  translator: %d is the operator strategy (a number), the
3235  first two %s's are data type names, the third %s is the
3236  description of the operator family, and the last %s is the
3237  textual form of the operator with arguments. */
3238  appendStringInfo(&buffer, _("operator %d (%s, %s) of %s: %s"),
3239  amopForm->amopstrategy,
3240  format_type_be(amopForm->amoplefttype),
3241  format_type_be(amopForm->amoprighttype),
3242  opfam.data,
3243  format_operator(amopForm->amopopr));
3244 
3245  pfree(opfam.data);
3246 
3247  systable_endscan(amscan);
3248  table_close(amopDesc, AccessShareLock);
3249  break;
3250  }
3251 
3252  case AccessMethodProcedureRelationId:
3253  {
3254  Relation amprocDesc;
3255  ScanKeyData skey[1];
3256  SysScanDesc amscan;
3257  HeapTuple tup;
3258  Form_pg_amproc amprocForm;
3259  StringInfoData opfam;
3260 
3261  amprocDesc = table_open(AccessMethodProcedureRelationId,
3262  AccessShareLock);
3263 
3264  ScanKeyInit(&skey[0],
3265  Anum_pg_amproc_oid,
3266  BTEqualStrategyNumber, F_OIDEQ,
3267  ObjectIdGetDatum(object->objectId));
3268 
3269  amscan = systable_beginscan(amprocDesc, AccessMethodProcedureOidIndexId, true,
3270  NULL, 1, skey);
3271 
3272  tup = systable_getnext(amscan);
3273 
3274  if (!HeapTupleIsValid(tup))
3275  {
3276  if (!missing_ok)
3277  elog(ERROR, "could not find tuple for amproc entry %u",
3278  object->objectId);
3279 
3280  systable_endscan(amscan);
3281  table_close(amprocDesc, AccessShareLock);
3282  break;
3283  }
3284 
3285  amprocForm = (Form_pg_amproc) GETSTRUCT(tup);
3286 
3287  initStringInfo(&opfam);
3288  getOpFamilyDescription(&opfam, amprocForm->amprocfamily, false);
3289 
3290  /*------
3291  translator: %d is the function number, the first two %s's
3292  are data type names, the third %s is the description of the
3293  operator family, and the last %s is the textual form of the
3294  function with arguments. */
3295  appendStringInfo(&buffer, _("function %d (%s, %s) of %s: %s"),
3296  amprocForm->amprocnum,
3297  format_type_be(amprocForm->amproclefttype),
3298  format_type_be(amprocForm->amprocrighttype),
3299  opfam.data,
3300  format_procedure(amprocForm->amproc));
3301 
3302  pfree(opfam.data);
3303 
3304  systable_endscan(amscan);
3305  table_close(amprocDesc, AccessShareLock);
3306  break;
3307  }
3308 
3309  case RewriteRelationId:
3310  {
3311  Relation ruleDesc;
3312  ScanKeyData skey[1];
3313  SysScanDesc rcscan;
3314  HeapTuple tup;
3316  StringInfoData rel;
3317 
3318  ruleDesc = table_open(RewriteRelationId, AccessShareLock);
3319 
3320  ScanKeyInit(&skey[0],
3321  Anum_pg_rewrite_oid,
3322  BTEqualStrategyNumber, F_OIDEQ,
3323  ObjectIdGetDatum(object->objectId));
3324 
3325  rcscan = systable_beginscan(ruleDesc, RewriteOidIndexId, true,
3326  NULL, 1, skey);
3327 
3328  tup = systable_getnext(rcscan);
3329 
3330  if (!HeapTupleIsValid(tup))
3331  {
3332  if (!missing_ok)
3333  elog(ERROR, "could not find tuple for rule %u",
3334  object->objectId);
3335 
3336  systable_endscan(rcscan);
3337  table_close(ruleDesc, AccessShareLock);
3338  break;
3339  }
3340 
3341  rule = (Form_pg_rewrite) GETSTRUCT(tup);
3342 
3343  initStringInfo(&rel);
3344  getRelationDescription(&rel, rule->ev_class, false);
3345 
3346  /* translator: second %s is, e.g., "table %s" */
3347  appendStringInfo(&buffer, _("rule %s on %s"),
3348  NameStr(rule->rulename), rel.data);
3349  pfree(rel.data);
3350  systable_endscan(rcscan);
3351  table_close(ruleDesc, AccessShareLock);
3352  break;
3353  }
3354 
3355  case TriggerRelationId:
3356  {
3357  Relation trigDesc;
3358  ScanKeyData skey[1];
3359  SysScanDesc tgscan;
3360  HeapTuple tup;
3361  Form_pg_trigger trig;
3362  StringInfoData rel;
3363 
3364  trigDesc = table_open(TriggerRelationId, AccessShareLock);
3365 
3366  ScanKeyInit(&skey[0],
3367  Anum_pg_trigger_oid,
3368  BTEqualStrategyNumber, F_OIDEQ,
3369  ObjectIdGetDatum(object->objectId));
3370 
3371  tgscan = systable_beginscan(trigDesc, TriggerOidIndexId, true,
3372  NULL, 1, skey);
3373 
3374  tup = systable_getnext(tgscan);
3375 
3376  if (!HeapTupleIsValid(tup))
3377  {
3378  if (!missing_ok)
3379  elog(ERROR, "could not find tuple for trigger %u",
3380  object->objectId);
3381 
3382  systable_endscan(tgscan);
3383  table_close(trigDesc, AccessShareLock);
3384  break;
3385  }
3386 
3387  trig = (Form_pg_trigger) GETSTRUCT(tup);
3388 
3389  initStringInfo(&rel);
3390  getRelationDescription(&rel, trig->tgrelid, false);
3391 
3392  /* translator: second %s is, e.g., "table %s" */
3393  appendStringInfo(&buffer, _("trigger %s on %s"),
3394  NameStr(trig->tgname), rel.data);
3395  pfree(rel.data);
3396  systable_endscan(tgscan);
3397  table_close(trigDesc, AccessShareLock);
3398  break;
3399  }
3400 
3401  case NamespaceRelationId:
3402  {
3403  char *nspname;
3404 
3405  nspname = get_namespace_name(object->objectId);
3406  if (!nspname)
3407  {
3408  if (!missing_ok)
3409  elog(ERROR, "cache lookup failed for namespace %u",
3410  object->objectId);
3411  break;
3412  }
3413  appendStringInfo(&buffer, _("schema %s"), nspname);
3414  break;
3415  }
3416 
3417  case StatisticExtRelationId:
3418  {
3419  HeapTuple stxTup;
3420  Form_pg_statistic_ext stxForm;
3421  char *nspname;
3422 
3423  stxTup = SearchSysCache1(STATEXTOID,
3424  ObjectIdGetDatum(object->objectId));
3425  if (!HeapTupleIsValid(stxTup))
3426  {
3427  if (!missing_ok)
3428  elog(ERROR, "could not find tuple for statistics object %u",
3429  object->objectId);
3430  break;
3431  }
3432 
3433  stxForm = (Form_pg_statistic_ext) GETSTRUCT(stxTup);
3434 
3435  /* Qualify the name if not visible in search path */
3436  if (StatisticsObjIsVisible(object->objectId))
3437  nspname = NULL;
3438  else
3439  nspname = get_namespace_name(stxForm->stxnamespace);
3440 
3441  appendStringInfo(&buffer, _("statistics object %s"),
3443  NameStr(stxForm->stxname)));
3444 
3445  ReleaseSysCache(stxTup);
3446  break;
3447  }
3448 
3449  case TSParserRelationId:
3450  {
3451  HeapTuple tup;
3452  Form_pg_ts_parser prsForm;
3453  char *nspname;
3454 
3455  tup = SearchSysCache1(TSPARSEROID,
3456  ObjectIdGetDatum(object->objectId));
3457  if (!HeapTupleIsValid(tup))
3458  {
3459  if (!missing_ok)
3460  elog(ERROR, "cache lookup failed for text search parser %u",
3461  object->objectId);
3462  break;
3463  }
3464  prsForm = (Form_pg_ts_parser) GETSTRUCT(tup);
3465 
3466  /* Qualify the name if not visible in search path */
3467  if (TSParserIsVisible(object->objectId))
3468  nspname = NULL;
3469  else
3470  nspname = get_namespace_name(prsForm->prsnamespace);
3471 
3472  appendStringInfo(&buffer, _("text search parser %s"),
3474  NameStr(prsForm->prsname)));
3475  ReleaseSysCache(tup);
3476  break;
3477  }
3478 
3479  case TSDictionaryRelationId:
3480  {
3481  HeapTuple tup;
3482  Form_pg_ts_dict dictForm;
3483  char *nspname;
3484 
3485  tup = SearchSysCache1(TSDICTOID,
3486  ObjectIdGetDatum(object->objectId));
3487  if (!HeapTupleIsValid(tup))
3488  {
3489  if (!missing_ok)
3490  elog(ERROR, "cache lookup failed for text search dictionary %u",
3491  object->objectId);
3492  break;
3493  }
3494 
3495  dictForm = (Form_pg_ts_dict) GETSTRUCT(tup);
3496 
3497  /* Qualify the name if not visible in search path */
3498  if (TSDictionaryIsVisible(object->objectId))
3499  nspname = NULL;
3500  else
3501  nspname = get_namespace_name(dictForm->dictnamespace);
3502 
3503  appendStringInfo(&buffer, _("text search dictionary %s"),
3505  NameStr(dictForm->dictname)));
3506  ReleaseSysCache(tup);
3507  break;
3508  }
3509 
3510  case TSTemplateRelationId:
3511  {
3512  HeapTuple tup;
3513  Form_pg_ts_template tmplForm;
3514  char *nspname;
3515 
3516  tup = SearchSysCache1(TSTEMPLATEOID,
3517  ObjectIdGetDatum(object->objectId));
3518  if (!HeapTupleIsValid(tup))
3519  {
3520  if (!missing_ok)
3521  elog(ERROR, "cache lookup failed for text search template %u",
3522  object->objectId);
3523  break;
3524  }
3525 
3526  tmplForm = (Form_pg_ts_template) GETSTRUCT(tup);
3527 
3528  /* Qualify the name if not visible in search path */
3529  if (TSTemplateIsVisible(object->objectId))
3530  nspname = NULL;
3531  else
3532  nspname = get_namespace_name(tmplForm->tmplnamespace);
3533 
3534  appendStringInfo(&buffer, _("text search template %s"),
3536  NameStr(tmplForm->tmplname)));
3537  ReleaseSysCache(tup);
3538  break;
3539  }
3540 
3541  case TSConfigRelationId:
3542  {
3543  HeapTuple tup;
3544  Form_pg_ts_config cfgForm;
3545  char *nspname;
3546 
3547  tup = SearchSysCache1(TSCONFIGOID,
3548  ObjectIdGetDatum(object->objectId));
3549  if (!HeapTupleIsValid(tup))
3550  {
3551  if (!missing_ok)
3552  elog(ERROR, "cache lookup failed for text search configuration %u",
3553  object->objectId);
3554  break;
3555  }
3556 
3557  cfgForm = (Form_pg_ts_config) GETSTRUCT(tup);
3558 
3559  /* Qualify the name if not visible in search path */
3560  if (TSConfigIsVisible(object->objectId))
3561  nspname = NULL;
3562  else
3563  nspname = get_namespace_name(cfgForm->cfgnamespace);
3564 
3565  appendStringInfo(&buffer, _("text search configuration %s"),
3567  NameStr(cfgForm->cfgname)));
3568  ReleaseSysCache(tup);
3569  break;
3570  }
3571 
3572  case AuthIdRelationId:
3573  {
3574  char *username = GetUserNameFromId(object->objectId,
3575  missing_ok);
3576 
3577  if (username)
3578  appendStringInfo(&buffer, _("role %s"), username);
3579  break;
3580  }
3581 
3582  case AuthMemRelationId:
3583  {
3584  Relation amDesc;
3585  ScanKeyData skey[1];
3586  SysScanDesc rcscan;
3587  HeapTuple tup;
3588  Form_pg_auth_members amForm;
3589 
3590  amDesc = table_open(AuthMemRelationId, AccessShareLock);
3591 
3592  ScanKeyInit(&skey[0],
3593  Anum_pg_auth_members_oid,
3594  BTEqualStrategyNumber, F_OIDEQ,
3595  ObjectIdGetDatum(object->objectId));
3596 
3597  rcscan = systable_beginscan(amDesc, AuthMemOidIndexId, true,
3598  NULL, 1, skey);
3599 
3600  tup = systable_getnext(rcscan);
3601 
3602  if (!HeapTupleIsValid(tup))
3603  {
3604  if (!missing_ok)
3605  elog(ERROR, "could not find tuple for role membership %u",
3606  object->objectId);
3607 
3608  systable_endscan(rcscan);
3609  table_close(amDesc, AccessShareLock);
3610  break;
3611  }
3612 
3613  amForm = (Form_pg_auth_members) GETSTRUCT(tup);
3614 
3615  appendStringInfo(&buffer, _("membership of role %s in role %s"),
3616  GetUserNameFromId(amForm->member, false),
3617  GetUserNameFromId(amForm->roleid, false));
3618 
3619  systable_endscan(rcscan);
3620  table_close(amDesc, AccessShareLock);
3621  break;
3622  }
3623 
3624  case DatabaseRelationId:
3625  {
3626  char *datname;
3627 
3628  datname = get_database_name(object->objectId);
3629  if (!datname)
3630  {
3631  if (!missing_ok)
3632  elog(ERROR, "cache lookup failed for database %u",
3633  object->objectId);
3634  break;
3635  }
3636  appendStringInfo(&buffer, _("database %s"), datname);
3637  break;
3638  }
3639 
3640  case TableSpaceRelationId:
3641  {
3642  char *tblspace;
3643 
3644  tblspace = get_tablespace_name(object->objectId);
3645  if (!tblspace)
3646  {
3647  if (!missing_ok)
3648  elog(ERROR, "cache lookup failed for tablespace %u",
3649  object->objectId);
3650  break;
3651  }
3652  appendStringInfo(&buffer, _("tablespace %s"), tblspace);
3653  break;
3654  }
3655 
3656  case ForeignDataWrapperRelationId:
3657  {
3658  ForeignDataWrapper *fdw;
3659 
3661  missing_ok);
3662  if (fdw)
3663  appendStringInfo(&buffer, _("foreign-data wrapper %s"), fdw->fdwname);
3664  break;
3665  }
3666 
3667  case ForeignServerRelationId:
3668  {
3669  ForeignServer *srv;
3670 
3671  srv = GetForeignServerExtended(object->objectId, missing_ok);
3672  if (srv)
3673  appendStringInfo(&buffer, _("server %s"), srv->servername);
3674  break;
3675  }
3676 
3677  case UserMappingRelationId:
3678  {
3679  HeapTuple tup;
3680  Oid useid;
3681  char *usename;
3682  Form_pg_user_mapping umform;
3683  ForeignServer *srv;
3684 
3685  tup = SearchSysCache1(USERMAPPINGOID,
3686  ObjectIdGetDatum(object->objectId));
3687  if (!HeapTupleIsValid(tup))
3688  {
3689  if (!missing_ok)
3690  elog(ERROR, "cache lookup failed for user mapping %u",
3691  object->objectId);
3692  break;
3693  }
3694 
3695  umform = (Form_pg_user_mapping) GETSTRUCT(tup);
3696  useid = umform->umuser;
3697  srv = GetForeignServer(umform->umserver);
3698 
3699  ReleaseSysCache(tup);
3700 
3701  if (OidIsValid(useid))
3702  usename = GetUserNameFromId(useid, false);
3703  else
3704  usename = "public";
3705 
3706  appendStringInfo(&buffer, _("user mapping for %s on server %s"), usename,
3707  srv->servername);
3708  break;
3709  }
3710 
3711  case DefaultAclRelationId:
3712  {
3713  Relation defaclrel;
3714  ScanKeyData skey[1];
3715  SysScanDesc rcscan;
3716  HeapTuple tup;
3717  Form_pg_default_acl defacl;
3718  char *rolename;
3719  char *nspname;
3720 
3721  defaclrel = table_open(DefaultAclRelationId, AccessShareLock);
3722 
3723  ScanKeyInit(&skey[0],
3724  Anum_pg_default_acl_oid,
3725  BTEqualStrategyNumber, F_OIDEQ,
3726  ObjectIdGetDatum(object->objectId));
3727 
3728  rcscan = systable_beginscan(defaclrel, DefaultAclOidIndexId,
3729  true, NULL, 1, skey);
3730 
3731  tup = systable_getnext(rcscan);
3732 
3733  if (!HeapTupleIsValid(tup))
3734  {
3735  if (!missing_ok)
3736  elog(ERROR, "could not find tuple for default ACL %u",
3737  object->objectId);
3738 
3739  systable_endscan(rcscan);
3740  table_close(defaclrel, AccessShareLock);
3741  break;
3742  }
3743 
3744  defacl = (Form_pg_default_acl) GETSTRUCT(tup);
3745 
3746  rolename = GetUserNameFromId(defacl->defaclrole, false);
3747 
3748  if (OidIsValid(defacl->defaclnamespace))
3749  nspname = get_namespace_name(defacl->defaclnamespace);
3750  else
3751  nspname = NULL;
3752 
3753  switch (defacl->defaclobjtype)
3754  {
3755  case DEFACLOBJ_RELATION:
3756  if (nspname)
3757  appendStringInfo(&buffer,
3758  _("default privileges on new relations belonging to role %s in schema %s"),
3759  rolename, nspname);
3760  else
3761  appendStringInfo(&buffer,
3762  _("default privileges on new relations belonging to role %s"),
3763  rolename);
3764  break;
3765  case DEFACLOBJ_SEQUENCE:
3766  if (nspname)
3767  appendStringInfo(&buffer,
3768  _("default privileges on new sequences belonging to role %s in schema %s"),
3769  rolename, nspname);
3770  else
3771  appendStringInfo(&buffer,
3772  _("default privileges on new sequences belonging to role %s"),
3773  rolename);
3774  break;
3775  case DEFACLOBJ_FUNCTION:
3776  if (nspname)
3777  appendStringInfo(&buffer,
3778  _("default privileges on new functions belonging to role %s in schema %s"),
3779  rolename, nspname);
3780  else
3781  appendStringInfo(&buffer,
3782  _("default privileges on new functions belonging to role %s"),
3783  rolename);
3784  break;
3785  case DEFACLOBJ_TYPE:
3786  if (nspname)
3787  appendStringInfo(&buffer,
3788  _("default privileges on new types belonging to role %s in schema %s"),
3789  rolename, nspname);
3790  else
3791  appendStringInfo(&buffer,
3792  _("default privileges on new types belonging to role %s"),
3793  rolename);
3794  break;
3795  case DEFACLOBJ_NAMESPACE:
3796  Assert(!nspname);
3797  appendStringInfo(&buffer,
3798  _("default privileges on new schemas belonging to role %s"),
3799  rolename);
3800  break;
3801  default:
3802  /* shouldn't get here */
3803  if (nspname)
3804  appendStringInfo(&buffer,
3805  _("default privileges belonging to role %s in schema %s"),
3806  rolename, nspname);
3807  else
3808  appendStringInfo(&buffer,
3809  _("default privileges belonging to role %s"),
3810  rolename);
3811  break;
3812  }
3813 
3814  systable_endscan(rcscan);
3815  table_close(defaclrel, AccessShareLock);
3816  break;
3817  }
3818 
3819  case ExtensionRelationId:
3820  {
3821  char *extname;
3822 
3823  extname = get_extension_name(object->objectId);
3824  if (!extname)
3825  {
3826  if (!missing_ok)
3827  elog(ERROR, "cache lookup failed for extension %u",
3828  object->objectId);
3829  break;
3830  }
3831  appendStringInfo(&buffer, _("extension %s"), extname);
3832  break;
3833  }
3834 
3835  case EventTriggerRelationId:
3836  {
3837  HeapTuple tup;
3838 
3839  tup = SearchSysCache1(EVENTTRIGGEROID,
3840  ObjectIdGetDatum(object->objectId));
3841  if (!HeapTupleIsValid(tup))
3842  {
3843  if (!missing_ok)
3844  elog(ERROR, "cache lookup failed for event trigger %u",
3845  object->objectId);
3846  break;
3847  }
3848  appendStringInfo(&buffer, _("event trigger %s"),
3849  NameStr(((Form_pg_event_trigger) GETSTRUCT(tup))->evtname));
3850  ReleaseSysCache(tup);
3851  break;
3852  }
3853 
3854  case ParameterAclRelationId:
3855  {
3856  HeapTuple tup;
3857  Datum nameDatum;
3858  char *parname;
3859 
3860  tup = SearchSysCache1(PARAMETERACLOID,
3861  ObjectIdGetDatum(object->objectId));
3862  if (!HeapTupleIsValid(tup))
3863  {
3864  if (!missing_ok)
3865  elog(ERROR, "cache lookup failed for parameter ACL %u",
3866  object->objectId);
3867  break;
3868  }
3869  nameDatum = SysCacheGetAttrNotNull(PARAMETERACLOID, tup,
3870  Anum_pg_parameter_acl_parname);
3871  parname = TextDatumGetCString(nameDatum);
3872  appendStringInfo(&buffer, _("parameter %s"), parname);
3873  ReleaseSysCache(tup);
3874  break;
3875  }
3876 
3877  case PolicyRelationId:
3878  {
3879  Relation policy_rel;
3880  ScanKeyData skey[1];
3881  SysScanDesc sscan;
3882  HeapTuple tuple;
3883  Form_pg_policy form_policy;
3884  StringInfoData rel;
3885 
3886  policy_rel = table_open(PolicyRelationId, AccessShareLock);
3887 
3888  ScanKeyInit(&skey[0],
3889  Anum_pg_policy_oid,
3890  BTEqualStrategyNumber, F_OIDEQ,
3891  ObjectIdGetDatum(object->objectId));
3892 
3893  sscan = systable_beginscan(policy_rel, PolicyOidIndexId,
3894  true, NULL, 1, skey);
3895 
3896  tuple = systable_getnext(sscan);
3897 
3898  if (!HeapTupleIsValid(tuple))
3899  {
3900  if (!missing_ok)
3901  elog(ERROR, "could not find tuple for policy %u",
3902  object->objectId);
3903 
3904  systable_endscan(sscan);
3905  table_close(policy_rel, AccessShareLock);
3906  break;
3907  }
3908 
3909  form_policy = (Form_pg_policy) GETSTRUCT(tuple);
3910 
3911  initStringInfo(&rel);
3912  getRelationDescription(&rel, form_policy->polrelid, false);
3913 
3914  /* translator: second %s is, e.g., "table %s" */
3915  appendStringInfo(&buffer, _("policy %s on %s"),
3916  NameStr(form_policy->polname), rel.data);
3917  pfree(rel.data);
3918  systable_endscan(sscan);
3919  table_close(policy_rel, AccessShareLock);
3920  break;
3921  }
3922 
3923  case PublicationRelationId:
3924  {
3925  char *pubname = get_publication_name(object->objectId,
3926  missing_ok);
3927 
3928  if (pubname)
3929  appendStringInfo(&buffer, _("publication %s"), pubname);
3930  break;
3931  }
3932 
3933  case PublicationNamespaceRelationId:
3934  {
3935  char *pubname;
3936  char *nspname;
3937 
3938  if (!getPublicationSchemaInfo(object, missing_ok,
3939  &pubname, &nspname))
3940  break;
3941 
3942  appendStringInfo(&buffer, _("publication of schema %s in publication %s"),
3943  nspname, pubname);
3944  pfree(pubname);
3945  pfree(nspname);
3946  break;
3947  }
3948 
3949  case PublicationRelRelationId:
3950  {
3951  HeapTuple tup;
3952  char *pubname;
3953  Form_pg_publication_rel prform;
3954  StringInfoData rel;
3955 
3956  tup = SearchSysCache1(PUBLICATIONREL,
3957  ObjectIdGetDatum(object->objectId));
3958  if (!HeapTupleIsValid(tup))
3959  {
3960  if (!missing_ok)
3961  elog(ERROR, "cache lookup failed for publication table %u",
3962  object->objectId);
3963  break;
3964  }
3965 
3966  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
3967  pubname = get_publication_name(prform->prpubid, false);
3968 
3969  initStringInfo(&rel);
3970  getRelationDescription(&rel, prform->prrelid, false);
3971 
3972  /* translator: first %s is, e.g., "table %s" */
3973  appendStringInfo(&buffer, _("publication of %s in publication %s"),
3974  rel.data, pubname);
3975  pfree(rel.data);
3976  ReleaseSysCache(tup);
3977  break;
3978  }
3979 
3980  case SubscriptionRelationId:
3981  {
3982  char *subname = get_subscription_name(object->objectId,
3983  missing_ok);
3984 
3985  if (subname)
3986  appendStringInfo(&buffer, _("subscription %s"), subname);
3987  break;
3988  }
3989 
3990  case TransformRelationId:
3991  {
3992  HeapTuple trfTup;
3993  Form_pg_transform trfForm;
3994 
3995  trfTup = SearchSysCache1(TRFOID,
3996  ObjectIdGetDatum(object->objectId));
3997  if (!HeapTupleIsValid(trfTup))
3998  {
3999  if (!missing_ok)
4000  elog(ERROR, "could not find tuple for transform %u",
4001  object->objectId);
4002  break;
4003  }
4004 
4005  trfForm = (Form_pg_transform) GETSTRUCT(trfTup);
4006 
4007  appendStringInfo(&buffer, _("transform for %s language %s"),
4008  format_type_be(trfForm->trftype),
4009  get_language_name(trfForm->trflang, false));
4010 
4011  ReleaseSysCache(trfTup);
4012  break;
4013  }
4014 
4015  default:
4016  elog(ERROR, "unsupported object class: %u", object->classId);
4017  }
4018 
4019  /* an empty buffer is equivalent to no object found */
4020  if (buffer.len == 0)
4021  return NULL;
4022 
4023  return buffer.data;
4024 }
char * get_tablespace_name(Oid spc_oid)
Definition: tablespace.c:1472
#define TextDatumGetCString(d)
Definition: builtins.h:98
#define FORMAT_TYPE_INVALID_AS_NULL
Definition: builtins.h:127
#define NameStr(name)
Definition: c.h:746
uint16 bits16
Definition: c.h:514
char * get_database_name(Oid dbid)
Definition: dbcommands.c:3166
#define _(x)
Definition: elog.c:90
char * get_extension_name(Oid ext_oid)
Definition: extension.c:190
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:1161
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3366
char * get_publication_name(Oid pubid, bool missing_ok)
Definition: lsyscache.c:3645
char * get_subscription_name(Oid subid, bool missing_ok)
Definition: lsyscache.c:3695
char * get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
Definition: lsyscache.c:827
void pfree(void *pointer)
Definition: mcxt.c:1521
bool TSTemplateIsVisible(Oid tmplId)
Definition: namespace.c:3050
bool CollationIsVisible(Oid collid)
Definition: namespace.c:2392
bool ConversionIsVisible(Oid conid)
Definition: namespace.c:2494
bool OpclassIsVisible(Oid opcid)
Definition: namespace.c:2139
bool TSParserIsVisible(Oid prsId)
Definition: namespace.c:2759
bool TSConfigIsVisible(Oid cfgid)
Definition: namespace.c:3195
bool StatisticsObjIsVisible(Oid stxid)
Definition: namespace.c:2617
bool TSDictionaryIsVisible(Oid dictId)
Definition: namespace.c:2904
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:381
FormData_pg_auth_members * Form_pg_auth_members
FormData_pg_cast * Form_pg_cast
Definition: pg_cast.h:57
FormData_pg_collation * Form_pg_collation
Definition: pg_collation.h:58
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
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
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:64
char * format_operator(Oid operator_oid)
Definition: regproc.c:793
char * format_procedure(Oid procedure_oid)
Definition: regproc.c:299
char * format_operator_extended(Oid operator_oid, bits16 flags)
Definition: regproc.c:722
char * format_procedure_extended(Oid procedure_oid, bits16 flags)
Definition: regproc.c:326
#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:12680
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:97
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
char * fdwname
Definition: foreign.h:28
char * servername
Definition: foreign.h:39
Definition: localtime.c:73

References _, AccessShareLock, appendStringInfo(), Assert, attname, BTEqualStrategyNumber, ObjectAddress::classId, CollationIsVisible(), ConversionIsVisible(), StringInfoData::data, datname, elog, ERROR, 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(), getOpFamilyDescription(), getPublicationSchemaInfo(), getRelationDescription(), GETSTRUCT, GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), LargeObjectExists(), StringInfoData::len, NameStr, ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, OidIsValid, OpclassIsVisible(), pfree(), proname, quote_qualified_identifier(), ReleaseSysCache(), ScanKeyInit(), SearchSysCache1(), ForeignServer::servername, StatisticsObjIsVisible(), subname, SysCacheGetAttrNotNull(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TextDatumGetCString, TSConfigIsVisible(), TSDictionaryIsVisible(), TSParserIsVisible(), TSTemplateIsVisible(), typname, and username.

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

◆ getObjectDescriptionOids()

char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 4030 of file objectaddress.c.

4031 {
4032  ObjectAddress address;
4033 
4034  address.classId = classid;
4035  address.objectId = objid;
4036  address.objectSubId = 0;
4037 
4038  return getObjectDescription(&address, false);
4039 }

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

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

References _, AccessShareLock, appendStringInfo(), appendStringInfoString(), Assert, BTEqualStrategyNumber, ObjectAddress::classId, StringInfoData::data, datname, elog, ERROR, ForeignDataWrapper::fdwname, format_operator_extended(), FORMAT_OPERATOR_FORCE_QUALIFY, FORMAT_OPERATOR_INVALID_AS_NULL, format_operator_parts(), FORMAT_PROC_FORCE_QUALIFY, FORMAT_PROC_INVALID_AS_NULL, format_procedure_extended(), format_procedure_parts(), format_type_be_qualified(), format_type_extended(), FORMAT_TYPE_FORCE_QUALIFY, FORMAT_TYPE_INVALID_AS_NULL, get_am_name(), get_attname(), get_catalog_object_by_oid(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name_or_temp(), get_publication_name(), get_subscription_name(), get_tablespace_name(), GetAttrDefaultColumnAddress(), GetForeignDataWrapperExtended(), GetForeignServer(), GetForeignServerExtended(), getOpFamilyIdentity(), getPublicationSchemaInfo(), getRelationIdentity(), GETSTRUCT, GetUserNameFromId(), HeapTupleIsValid, initStringInfo(), lappend(), LargeObjectExists(), StringInfoData::len, list_make1, list_make2, list_make3, NameStr, NIL, ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, OidIsValid, pfree(), PointerIsValid, proname, psprintf(), pstrdup(), quote_identifier(), quote_qualified_identifier(), ReleaseSysCache(), ScanKeyInit(), SearchSysCache1(), ForeignServer::servername, subname, SysCacheGetAttrNotNull(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TextDatumGetCString, and username.

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

◆ getObjectTypeDescription()

char* getObjectTypeDescription ( const ObjectAddress object,
bool  missing_ok 
)

Definition at line 4441 of file objectaddress.c.

4442 {
4443  StringInfoData buffer;
4444 
4445  initStringInfo(&buffer);
4446 
4447  switch (object->classId)
4448  {
4449  case RelationRelationId:
4450  getRelationTypeDescription(&buffer, object->objectId,
4451  object->objectSubId,
4452  missing_ok);
4453  break;
4454 
4455  case ProcedureRelationId:
4456  getProcedureTypeDescription(&buffer, object->objectId,
4457  missing_ok);
4458  break;
4459 
4460  case TypeRelationId:
4461  appendStringInfoString(&buffer, "type");
4462  break;
4463 
4464  case CastRelationId:
4465  appendStringInfoString(&buffer, "cast");
4466  break;
4467 
4468  case CollationRelationId:
4469  appendStringInfoString(&buffer, "collation");
4470  break;
4471 
4472  case ConstraintRelationId:
4473  getConstraintTypeDescription(&buffer, object->objectId,
4474  missing_ok);
4475  break;
4476 
4477  case ConversionRelationId:
4478  appendStringInfoString(&buffer, "conversion");
4479  break;
4480 
4481  case AttrDefaultRelationId:
4482  appendStringInfoString(&buffer, "default value");
4483  break;
4484 
4485  case LanguageRelationId:
4486  appendStringInfoString(&buffer, "language");
4487  break;
4488 
4489  case LargeObjectRelationId:
4490  appendStringInfoString(&buffer, "large object");
4491  break;
4492 
4493  case OperatorRelationId:
4494  appendStringInfoString(&buffer, "operator");
4495  break;
4496 
4497  case OperatorClassRelationId:
4498  appendStringInfoString(&buffer, "operator class");
4499  break;
4500 
4501  case OperatorFamilyRelationId:
4502  appendStringInfoString(&buffer, "operator family");
4503  break;
4504 
4505  case AccessMethodRelationId:
4506  appendStringInfoString(&buffer, "access method");
4507  break;
4508 
4509  case AccessMethodOperatorRelationId:
4510  appendStringInfoString(&buffer, "operator of access method");
4511  break;
4512 
4513  case AccessMethodProcedureRelationId:
4514  appendStringInfoString(&buffer, "function of access method");
4515  break;
4516 
4517  case RewriteRelationId:
4518  appendStringInfoString(&buffer, "rule");
4519  break;
4520 
4521  case TriggerRelationId:
4522  appendStringInfoString(&buffer, "trigger");
4523  break;
4524 
4525  case NamespaceRelationId:
4526  appendStringInfoString(&buffer, "schema");
4527  break;
4528 
4529  case StatisticExtRelationId:
4530  appendStringInfoString(&buffer, "statistics object");
4531  break;
4532 
4533  case TSParserRelationId:
4534  appendStringInfoString(&buffer, "text search parser");
4535  break;
4536 
4537  case TSDictionaryRelationId:
4538  appendStringInfoString(&buffer, "text search dictionary");
4539  break;
4540 
4541  case TSTemplateRelationId:
4542  appendStringInfoString(&buffer, "text search template");
4543  break;
4544 
4545  case TSConfigRelationId:
4546  appendStringInfoString(&buffer, "text search configuration");
4547  break;
4548 
4549  case AuthIdRelationId:
4550  appendStringInfoString(&buffer, "role");
4551  break;
4552 
4553  case AuthMemRelationId:
4554  appendStringInfoString(&buffer, "role membership");
4555  break;
4556 
4557  case DatabaseRelationId:
4558  appendStringInfoString(&buffer, "database");
4559  break;
4560 
4561  case TableSpaceRelationId:
4562  appendStringInfoString(&buffer, "tablespace");
4563  break;
4564 
4565  case ForeignDataWrapperRelationId:
4566  appendStringInfoString(&buffer, "foreign-data wrapper");
4567  break;
4568 
4569  case ForeignServerRelationId: