PostgreSQL Source Code  git master
objectaddress.c File Reference
#include "postgres.h"
#include "access/genam.h"
#include "access/htup_details.h"
#include "access/relation.h"
#include "access/sysattr.h"
#include "access/table.h"
#include "catalog/catalog.h"
#include "catalog/objectaddress.h"
#include "catalog/pg_am.h"
#include "catalog/pg_amop.h"
#include "catalog/pg_amproc.h"
#include "catalog/pg_attrdef.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_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_enum.h"
#include "catalog/pg_event_trigger.h"
#include "catalog/pg_extension.h"
#include "catalog/pg_foreign_data_wrapper.h"
#include "catalog/pg_foreign_server.h"
#include "catalog/pg_language.h"
#include "catalog/pg_largeobject.h"
#include "catalog/pg_largeobject_metadata.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_opclass.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_opfamily.h"
#include "catalog/pg_parameter_acl.h"
#include "catalog/pg_policy.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_publication.h"
#include "catalog/pg_publication_namespace.h"
#include "catalog/pg_publication_rel.h"
#include "catalog/pg_rewrite.h"
#include "catalog/pg_statistic_ext.h"
#include "catalog/pg_subscription.h"
#include "catalog/pg_tablespace.h"
#include "catalog/pg_transform.h"
#include "catalog/pg_trigger.h"
#include "catalog/pg_ts_config.h"
#include "catalog/pg_ts_dict.h"
#include "catalog/pg_ts_parser.h"
#include "catalog/pg_ts_template.h"
#include "catalog/pg_type.h"
#include "catalog/pg_user_mapping.h"
#include "commands/dbcommands.h"
#include "commands/defrem.h"
#include "commands/event_trigger.h"
#include "commands/extension.h"
#include "commands/policy.h"
#include "commands/proclang.h"
#include "commands/tablespace.h"
#include "commands/trigger.h"
#include "foreign/foreign.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "parser/parse_func.h"
#include "parser/parse_oper.h"
#include "parser/parse_type.h"
#include "rewrite/rewriteSupport.h"
#include "storage/large_object.h"
#include "storage/lmgr.h"
#include "storage/sinval.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/regproc.h"
#include "utils/syscache.h"
Include dependency graph for objectaddress.c:

Go to the source code of this file.

Data Structures

struct  ObjectPropertyType
 
struct  object_type_map
 

Functions

static ObjectAddress get_object_address_unqualified (ObjectType objtype, String *strval, bool missing_ok)
 
static ObjectAddress get_relation_by_qualified_name (ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static ObjectAddress get_object_address_relobject (ObjectType objtype, List *object, Relation *relp, bool missing_ok)
 
static ObjectAddress get_object_address_attribute (ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static ObjectAddress get_object_address_attrdef (ObjectType objtype, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static ObjectAddress get_object_address_type (ObjectType objtype, TypeName *typename, bool missing_ok)
 
static ObjectAddress get_object_address_opcf (ObjectType objtype, List *object, bool missing_ok)
 
static ObjectAddress get_object_address_opf_member (ObjectType objtype, List *object, bool missing_ok)
 
static ObjectAddress get_object_address_usermapping (List *object, bool missing_ok)
 
static ObjectAddress get_object_address_publication_rel (List *object, Relation *relp, bool missing_ok)
 
static ObjectAddress get_object_address_publication_schema (List *object, bool missing_ok)
 
static ObjectAddress get_object_address_defacl (List *object, bool missing_ok)
 
static const ObjectPropertyTypeget_object_property_data (Oid class_id)
 
static void getRelationDescription (StringInfo buffer, Oid relid, bool missing_ok)
 
static void getOpFamilyDescription (StringInfo buffer, Oid opfid, bool missing_ok)
 
static void getRelationTypeDescription (StringInfo buffer, Oid relid, int32 objectSubId, bool missing_ok)
 
static void getProcedureTypeDescription (StringInfo buffer, Oid procid, bool missing_ok)
 
static void getConstraintTypeDescription (StringInfo buffer, Oid constroid, bool missing_ok)
 
static void getOpFamilyIdentity (StringInfo buffer, Oid opfid, List **object, bool missing_ok)
 
static void getRelationIdentity (StringInfo buffer, Oid relid, List **object, bool missing_ok)
 
ObjectAddress get_object_address (ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
ObjectAddress get_object_address_rv (ObjectType objtype, RangeVar *rel, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
 
static Listtextarray_to_strvaluelist (ArrayType *arr)
 
Datum pg_get_object_address (PG_FUNCTION_ARGS)
 
void check_object_ownership (Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
 
Oid get_object_namespace (const ObjectAddress *address)
 
int read_objtype_from_string (const char *objtype)
 
const char * get_object_class_descr (Oid class_id)
 
Oid get_object_oid_index (Oid class_id)
 
int get_object_catcache_oid (Oid class_id)
 
int get_object_catcache_name (Oid class_id)
 
AttrNumber get_object_attnum_oid (Oid class_id)
 
AttrNumber get_object_attnum_name (Oid class_id)
 
AttrNumber get_object_attnum_namespace (Oid class_id)
 
AttrNumber get_object_attnum_owner (Oid class_id)
 
AttrNumber get_object_attnum_acl (Oid class_id)
 
ObjectType get_object_type (Oid class_id, Oid object_id)
 
bool get_object_namensp_unique (Oid class_id)
 
bool is_objectclass_supported (Oid class_id)
 
HeapTuple get_catalog_object_by_oid (Relation catalog, AttrNumber oidcol, Oid objectId)
 
static bool getPublicationSchemaInfo (const ObjectAddress *object, bool missing_ok, char **pubname, char **nspname)
 
char * getObjectDescription (const ObjectAddress *object, bool missing_ok)
 
char * getObjectDescriptionOids (Oid classid, Oid objid)
 
Datum pg_describe_object (PG_FUNCTION_ARGS)
 
Datum pg_identify_object (PG_FUNCTION_ARGS)
 
Datum pg_identify_object_as_address (PG_FUNCTION_ARGS)
 
char * getObjectTypeDescription (const ObjectAddress *object, bool missing_ok)
 
char * getObjectIdentity (const ObjectAddress *object, bool missing_ok)
 
char * getObjectIdentityParts (const ObjectAddress *object, List **objname, List **objargs, bool missing_ok)
 
ArrayTypestrlist_to_textarray (List *list)
 
ObjectType get_relkind_objtype (char relkind)
 

Variables

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

Function Documentation

◆ check_object_ownership()

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

Definition at line 2420 of file objectaddress.c.

2422 {
2423  switch (objtype)
2424  {
2425  case OBJECT_INDEX:
2426  case OBJECT_SEQUENCE:
2427  case OBJECT_TABLE:
2428  case OBJECT_VIEW:
2429  case OBJECT_MATVIEW:
2430  case OBJECT_FOREIGN_TABLE:
2431  case OBJECT_COLUMN:
2432  case OBJECT_RULE:
2433  case OBJECT_TRIGGER:
2434  case OBJECT_POLICY:
2435  case OBJECT_TABCONSTRAINT:
2436  if (!object_ownercheck(RelationRelationId, RelationGetRelid(relation), roleid))
2438  RelationGetRelationName(relation));
2439  break;
2440  case OBJECT_TYPE:
2441  case OBJECT_DOMAIN:
2442  case OBJECT_ATTRIBUTE:
2443  if (!object_ownercheck(address.classId, address.objectId, roleid))
2445  break;
2446  case OBJECT_DOMCONSTRAINT:
2447  {
2448  HeapTuple tuple;
2449  Oid contypid;
2450 
2451  tuple = SearchSysCache1(CONSTROID,
2452  ObjectIdGetDatum(address.objectId));
2453  if (!HeapTupleIsValid(tuple))
2454  elog(ERROR, "constraint with OID %u does not exist",
2455  address.objectId);
2456 
2457  contypid = ((Form_pg_constraint) GETSTRUCT(tuple))->contypid;
2458 
2459  ReleaseSysCache(tuple);
2460 
2461  /*
2462  * Fallback to type ownership check in this case as this is
2463  * what domain constraints rely on.
2464  */
2465  if (!object_ownercheck(TypeRelationId, contypid, roleid))
2467  }
2468  break;
2469  case OBJECT_AGGREGATE:
2470  case OBJECT_FUNCTION:
2471  case OBJECT_PROCEDURE:
2472  case OBJECT_ROUTINE:
2473  case OBJECT_OPERATOR:
2474  if (!object_ownercheck(address.classId, address.objectId, roleid))
2476  NameListToString((castNode(ObjectWithArgs, object))->objname));
2477  break;
2478  case OBJECT_DATABASE:
2479  case OBJECT_EVENT_TRIGGER:
2480  case OBJECT_EXTENSION:
2481  case OBJECT_FDW:
2482  case OBJECT_FOREIGN_SERVER:
2483  case OBJECT_LANGUAGE:
2484  case OBJECT_PUBLICATION:
2485  case OBJECT_SCHEMA:
2486  case OBJECT_SUBSCRIPTION:
2487  case OBJECT_TABLESPACE:
2488  if (!object_ownercheck(address.classId, address.objectId, roleid))
2490  strVal(object));
2491  break;
2492  case OBJECT_COLLATION:
2493  case OBJECT_CONVERSION:
2494  case OBJECT_OPCLASS:
2495  case OBJECT_OPFAMILY:
2496  case OBJECT_STATISTIC_EXT:
2497  case OBJECT_TSDICTIONARY:
2499  if (!object_ownercheck(address.classId, address.objectId, roleid))
2501  NameListToString(castNode(List, object)));
2502  break;
2503  case OBJECT_LARGEOBJECT:
2504  if (!lo_compat_privileges &&
2505  !object_ownercheck(address.classId, address.objectId, roleid))
2506  ereport(ERROR,
2507  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2508  errmsg("must be owner of large object %u",
2509  address.objectId)));
2510  break;
2511  case OBJECT_CAST:
2512  {
2513  /* We can only check permissions on the source/target types */
2514  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2515  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2516  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2517  Oid targettypeid = typenameTypeId(NULL, targettype);
2518 
2519  if (!object_ownercheck(TypeRelationId, sourcetypeid, roleid)
2520  && !object_ownercheck(TypeRelationId, targettypeid, roleid))
2521  ereport(ERROR,
2522  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2523  errmsg("must be owner of type %s or type %s",
2524  format_type_be(sourcetypeid),
2525  format_type_be(targettypeid))));
2526  }
2527  break;
2528  case OBJECT_TRANSFORM:
2529  {
2530  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2531  Oid typeid = typenameTypeId(NULL, typename);
2532 
2533  if (!object_ownercheck(TypeRelationId, typeid, roleid))
2535  }
2536  break;
2537  case OBJECT_ROLE:
2538 
2539  /*
2540  * We treat roles as being "owned" by those with CREATEROLE priv,
2541  * provided that they also have admin option on the role.
2542  *
2543  * However, superusers are only owned by superusers.
2544  */
2545  if (superuser_arg(address.objectId))
2546  {
2547  if (!superuser_arg(roleid))
2548  ereport(ERROR,
2549  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2550  errmsg("permission denied"),
2551  errdetail("The current user must have the %s attribute.",
2552  "SUPERUSER")));
2553  }
2554  else
2555  {
2556  if (!has_createrole_privilege(roleid))
2557  ereport(ERROR,
2558  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2559  errmsg("permission denied"),
2560  errdetail("The current user must have the %s attribute.",
2561  "CREATEROLE")));
2562  if (!is_admin_of_role(roleid, address.objectId))
2563  ereport(ERROR,
2564  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2565  errmsg("permission denied"),
2566  errdetail("The current user must have the %s option on role \"%s\".",
2567  "ADMIN",
2568  GetUserNameFromId(address.objectId,
2569  true))));
2570  }
2571  break;
2572  case OBJECT_TSPARSER:
2573  case OBJECT_TSTEMPLATE:
2574  case OBJECT_ACCESS_METHOD:
2575  case OBJECT_PARAMETER_ACL:
2576  /* We treat these object types as being owned by superusers */
2577  if (!superuser_arg(roleid))
2578  ereport(ERROR,
2579  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2580  errmsg("must be superuser")));
2581  break;
2582  case OBJECT_AMOP:
2583  case OBJECT_AMPROC:
2584  case OBJECT_DEFAULT:
2585  case OBJECT_DEFACL:
2588  case OBJECT_USER_MAPPING:
2589  /* These are currently not supported or don't make sense here. */
2590  elog(ERROR, "unsupported object type: %d", (int) objtype);
2591  break;
2592  }
2593 }
bool is_admin_of_role(Oid member, Oid role)
Definition: acl.c:5099
@ ACLCHECK_NOT_OWNER
Definition: acl.h:185
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:2679
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition: aclchk.c:3984
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:2998
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:4065
int errdetail(const char *fmt,...)
Definition: elog.c:1202
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
char * format_type_be(Oid type_oid)
Definition: format_type.c:339
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
bool lo_compat_privileges
Definition: inv_api.c:58
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:984
char * NameListToString(List *names)
Definition: namespace.c:3145
#define castNode(_type_, nodeptr)
Definition: nodes.h:197
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:291
@ OBJECT_EVENT_TRIGGER
Definition: parsenodes.h:1989
@ OBJECT_FDW
Definition: parsenodes.h:1991
@ OBJECT_TSPARSER
Definition: parsenodes.h:2022
@ OBJECT_COLLATION
Definition: parsenodes.h:1982
@ OBJECT_USER_MAPPING
Definition: parsenodes.h:2025
@ OBJECT_ACCESS_METHOD
Definition: parsenodes.h:1975
@ OBJECT_OPCLASS
Definition: parsenodes.h:1999
@ OBJECT_DEFACL
Definition: parsenodes.h:1986
@ OBJECT_AGGREGATE
Definition: parsenodes.h:1976
@ OBJECT_MATVIEW
Definition: parsenodes.h:1998
@ OBJECT_SCHEMA
Definition: parsenodes.h:2011
@ OBJECT_POLICY
Definition: parsenodes.h:2003
@ OBJECT_OPERATOR
Definition: parsenodes.h:2000
@ OBJECT_FOREIGN_TABLE
Definition: parsenodes.h:1993
@ OBJECT_TSCONFIGURATION
Definition: parsenodes.h:2020
@ OBJECT_OPFAMILY
Definition: parsenodes.h:2001
@ OBJECT_DOMAIN
Definition: parsenodes.h:1987
@ OBJECT_COLUMN
Definition: parsenodes.h:1981
@ OBJECT_TABLESPACE
Definition: parsenodes.h:2017
@ OBJECT_ROLE
Definition: parsenodes.h:2008
@ OBJECT_ROUTINE
Definition: parsenodes.h:2009
@ OBJECT_LARGEOBJECT
Definition: parsenodes.h:1997
@ OBJECT_PUBLICATION_NAMESPACE
Definition: parsenodes.h:2006
@ OBJECT_PROCEDURE
Definition: parsenodes.h:2004
@ OBJECT_EXTENSION
Definition: parsenodes.h:1990
@ OBJECT_INDEX
Definition: parsenodes.h:1995
@ OBJECT_DEFAULT
Definition: parsenodes.h:1985
@ OBJECT_DATABASE
Definition: parsenodes.h:1984
@ OBJECT_SEQUENCE
Definition: parsenodes.h:2012
@ OBJECT_TSTEMPLATE
Definition: parsenodes.h:2023
@ OBJECT_LANGUAGE
Definition: parsenodes.h:1996
@ OBJECT_AMOP
Definition: parsenodes.h:1977
@ OBJECT_PUBLICATION_REL
Definition: parsenodes.h:2007
@ OBJECT_FOREIGN_SERVER
Definition: parsenodes.h:1992
@ OBJECT_TSDICTIONARY
Definition: parsenodes.h:2021
@ OBJECT_ATTRIBUTE
Definition: parsenodes.h:1979
@ OBJECT_PUBLICATION
Definition: parsenodes.h:2005
@ OBJECT_RULE
Definition: parsenodes.h:2010
@ OBJECT_CONVERSION
Definition: parsenodes.h:1983
@ OBJECT_AMPROC
Definition: parsenodes.h:1978
@ OBJECT_TABLE
Definition: parsenodes.h:2016
@ OBJECT_VIEW
Definition: parsenodes.h:2026
@ OBJECT_PARAMETER_ACL
Definition: parsenodes.h:2002
@ OBJECT_TYPE
Definition: parsenodes.h:2024
@ OBJECT_FUNCTION
Definition: parsenodes.h:1994
@ OBJECT_TABCONSTRAINT
Definition: parsenodes.h:2015
@ OBJECT_DOMCONSTRAINT
Definition: parsenodes.h:1988
@ OBJECT_SUBSCRIPTION
Definition: parsenodes.h:2013
@ OBJECT_STATISTIC_EXT
Definition: parsenodes.h:2014
@ OBJECT_CAST
Definition: parsenodes.h:1980
@ OBJECT_TRIGGER
Definition: parsenodes.h:2019
@ OBJECT_TRANSFORM
Definition: parsenodes.h:2018
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:501
#define RelationGetRelationName(relation)
Definition: rel.h:535
Definition: pg_list.h:54
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:865
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:817
@ CONSTROID
Definition: syscache.h:53
#define strVal(v)
Definition: value.h:82

References aclcheck_error(), aclcheck_error_type(), ACLCHECK_NOT_OWNER, castNode, ObjectAddress::classId, CONSTROID, 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 2822 of file objectaddress.c.

2823 {
2824  HeapTuple tuple;
2825  Oid classId = RelationGetRelid(catalog);
2826  int oidCacheId = get_object_catcache_oid(classId);
2827 
2828  if (oidCacheId > 0)
2829  {
2830  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2831  if (!HeapTupleIsValid(tuple)) /* should not happen */
2832  return NULL;
2833  }
2834  else
2835  {
2836  Oid oidIndexId = get_object_oid_index(classId);
2837  SysScanDesc scan;
2838  ScanKeyData skey;
2839 
2840  Assert(OidIsValid(oidIndexId));
2841 
2842  ScanKeyInit(&skey,
2843  oidcol,
2844  BTEqualStrategyNumber, F_OIDEQ,
2845  ObjectIdGetDatum(objectId));
2846 
2847  scan = systable_beginscan(catalog, oidIndexId, true,
2848  NULL, 1, &skey);
2849  tuple = systable_getnext(scan);
2850  if (!HeapTupleIsValid(tuple))
2851  {
2852  systable_endscan(scan);
2853  return NULL;
2854  }
2855  tuple = heap_copytuple(tuple);
2856 
2857  systable_endscan(scan);
2858  }
2859 
2860  return tuple;
2861 }
#define OidIsValid(objectId)
Definition: c.h:759
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:599
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:506
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:387
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:680
Assert(fmt[strlen(fmt) - 1] !='\n')
int get_object_catcache_oid(Oid class_id)
Oid get_object_oid_index(Oid class_id)
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:179

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

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

◆ get_object_address()

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

Definition at line 960 of file objectaddress.c.

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

1586 {
1587  ObjectAddress address;
1588  List *relname;
1589  Oid reloid;
1590  Relation relation;
1591  const char *attname;
1593  TupleDesc tupdesc;
1594  Oid defoid;
1595 
1596  /* Extract relation name and open relation. */
1597  if (list_length(object) < 2)
1598  ereport(ERROR,
1599  (errcode(ERRCODE_SYNTAX_ERROR),
1600  errmsg("column name must be qualified")));
1601  attname = strVal(llast(object));
1602  relname = list_copy_head(object, list_length(object) - 1);
1603  /* XXX no missing_ok support here */
1604  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1605  reloid = RelationGetRelid(relation);
1606 
1607  tupdesc = RelationGetDescr(relation);
1608 
1609  /* Look up attribute number and fetch the pg_attrdef OID */
1610  attnum = get_attnum(reloid, attname);
1611  defoid = InvalidOid;
1612  if (attnum != InvalidAttrNumber && tupdesc->constr != NULL)
1613  defoid = GetAttrDefaultOid(reloid, attnum);
1614  if (!OidIsValid(defoid))
1615  {
1616  if (!missing_ok)
1617  ereport(ERROR,
1618  (errcode(ERRCODE_UNDEFINED_COLUMN),
1619  errmsg("default value for column \"%s\" of relation \"%s\" does not exist",
1621 
1622  address.classId = AttrDefaultRelationId;
1623  address.objectId = InvalidOid;
1624  address.objectSubId = InvalidAttrNumber;
1625  relation_close(relation, lockmode);
1626  return address;
1627  }
1628 
1629  address.classId = AttrDefaultRelationId;
1630  address.objectId = defoid;
1631  address.objectSubId = 0;
1632 
1633  *relp = relation;
1634  return address;
1635 }
int16 AttrNumber
Definition: attnum.h:21
#define InvalidAttrNumber
Definition: attnum.h:23
List * list_copy_head(const List *oldlist, int len)
Definition: list.c:1592
AttrNumber get_attnum(Oid relid, const char *attname)
Definition: lsyscache.c:857
RangeVar * makeRangeVarFromNameList(List *names)
Definition: namespace.c:3105
Oid GetAttrDefaultOid(Oid relid, AttrNumber attnum)
Definition: pg_attrdef.c:339
NameData attname
Definition: pg_attribute.h:41
int16 attnum
Definition: pg_attribute.h:83
NameData relname
Definition: pg_class.h:38
#define llast(l)
Definition: pg_list.h:198
static int list_length(const List *l)
Definition: pg_list.h:152
#define RelationGetDescr(relation)
Definition: rel.h:527
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
Definition: relation.c:138
TupleConstr * constr
Definition: tupdesc.h:85

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

1535 {
1536  ObjectAddress address;
1537  List *relname;
1538  Oid reloid;
1539  Relation relation;
1540  const char *attname;
1542 
1543  /* Extract relation name and open relation. */
1544  if (list_length(object) < 2)
1545  ereport(ERROR,
1546  (errcode(ERRCODE_SYNTAX_ERROR),
1547  errmsg("column name must be qualified")));
1548  attname = strVal(llast(object));
1549  relname = list_copy_head(object, list_length(object) - 1);
1550  /* XXX no missing_ok support here */
1551  relation = relation_openrv(makeRangeVarFromNameList(relname), lockmode);
1552  reloid = RelationGetRelid(relation);
1553 
1554  /* Look up attribute and construct return value. */
1555  attnum = get_attnum(reloid, attname);
1556  if (attnum == InvalidAttrNumber)
1557  {
1558  if (!missing_ok)
1559  ereport(ERROR,
1560  (errcode(ERRCODE_UNDEFINED_COLUMN),
1561  errmsg("column \"%s\" of relation \"%s\" does not exist",
1563 
1564  address.classId = RelationRelationId;
1565  address.objectId = InvalidOid;
1566  address.objectSubId = InvalidAttrNumber;
1567  relation_close(relation, lockmode);
1568  return address;
1569  }
1570 
1571  address.classId = RelationRelationId;
1572  address.objectId = reloid;
1573  address.objectSubId = attnum;
1574 
1575  *relp = relation;
1576  return address;
1577 }

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

1997 {
1998  HeapTuple tp;
1999  Oid userid;
2000  Oid schemaid;
2001  char *username;
2002  char *schema;
2003  char objtype;
2004  char *objtype_str;
2005  ObjectAddress address;
2006 
2007  ObjectAddressSet(address, DefaultAclRelationId, InvalidOid);
2008 
2009  /*
2010  * First figure out the textual attributes so that they can be used for
2011  * error reporting.
2012  */
2013  username = strVal(lsecond(object));
2014  if (list_length(object) >= 3)
2015  schema = (char *) strVal(lthird(object));
2016  else
2017  schema = NULL;
2018 
2019  /*
2020  * Decode defaclobjtype. Only first char is considered; the rest of the
2021  * string, if any, is blissfully ignored.
2022  */
2023  objtype = ((char *) strVal(linitial(object)))[0];
2024  switch (objtype)
2025  {
2026  case DEFACLOBJ_RELATION:
2027  objtype_str = "tables";
2028  break;
2029  case DEFACLOBJ_SEQUENCE:
2030  objtype_str = "sequences";
2031  break;
2032  case DEFACLOBJ_FUNCTION:
2033  objtype_str = "functions";
2034  break;
2035  case DEFACLOBJ_TYPE:
2036  objtype_str = "types";
2037  break;
2038  case DEFACLOBJ_NAMESPACE:
2039  objtype_str = "schemas";
2040  break;
2041  default:
2042  ereport(ERROR,
2043  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2044  errmsg("unrecognized default ACL object type \"%c\"", objtype),
2045  errhint("Valid object types are \"%c\", \"%c\", \"%c\", \"%c\", \"%c\".",
2046  DEFACLOBJ_RELATION,
2047  DEFACLOBJ_SEQUENCE,
2048  DEFACLOBJ_FUNCTION,
2049  DEFACLOBJ_TYPE,
2050  DEFACLOBJ_NAMESPACE)));
2051  }
2052 
2053  /*
2054  * Look up user ID. Behave as "default ACL not found" if the user doesn't
2055  * exist.
2056  */
2059  if (!HeapTupleIsValid(tp))
2060  goto not_found;
2061  userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
2062  ReleaseSysCache(tp);
2063 
2064  /*
2065  * If a schema name was given, look up its OID. If it doesn't exist,
2066  * behave as "default ACL not found".
2067  */
2068  if (schema)
2069  {
2070  schemaid = get_namespace_oid(schema, true);
2071  if (schemaid == InvalidOid)
2072  goto not_found;
2073  }
2074  else
2075  schemaid = InvalidOid;
2076 
2077  /* Finally, look up the pg_default_acl object */
2079  ObjectIdGetDatum(userid),
2080  ObjectIdGetDatum(schemaid),
2081  CharGetDatum(objtype));
2082  if (!HeapTupleIsValid(tp))
2083  goto not_found;
2084 
2085  address.objectId = ((Form_pg_default_acl) GETSTRUCT(tp))->oid;
2086  ReleaseSysCache(tp);
2087 
2088  return address;
2089 
2090 not_found:
2091  if (!missing_ok)
2092  {
2093  if (schema)
2094  ereport(ERROR,
2095  (errcode(ERRCODE_UNDEFINED_OBJECT),
2096  errmsg("default ACL for user \"%s\" in schema \"%s\" on %s does not exist",
2097  username, schema, objtype_str)));
2098  else
2099  ereport(ERROR,
2100  (errcode(ERRCODE_UNDEFINED_OBJECT),
2101  errmsg("default ACL for user \"%s\" on %s does not exist",
2102  username, objtype_str)));
2103  }
2104  return address;
2105 }
int errhint(const char *fmt,...)
Definition: elog.c:1316
Oid get_namespace_oid(const char *nspname, bool missing_ok)
Definition: namespace.c:3086
#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
const char * username
Definition: pgbench.c:306
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:839
@ AUTHNAME
Definition: syscache.h:44
@ DEFACLROLENSPOBJ
Definition: syscache.h:56

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

Referenced by get_object_address().

◆ get_object_address_opcf()

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

Definition at line 1680 of file objectaddress.c.

1681 {
1682  Oid amoid;
1683  ObjectAddress address;
1684 
1685  /* XXX no missing_ok support here */
1686  amoid = get_index_am_oid(strVal(linitial(object)), false);
1687  object = list_copy_tail(object, 1);
1688 
1689  switch (objtype)
1690  {
1691  case OBJECT_OPCLASS:
1692  address.classId = OperatorClassRelationId;
1693  address.objectId = get_opclass_oid(amoid, object, missing_ok);
1694  address.objectSubId = 0;
1695  break;
1696  case OBJECT_OPFAMILY:
1697  address.classId = OperatorFamilyRelationId;
1698  address.objectId = get_opfamily_oid(amoid, object, missing_ok);
1699  address.objectSubId = 0;
1700  break;
1701  default:
1702  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1703  /* placate compiler, which doesn't know elog won't return */
1704  address.classId = InvalidOid;
1705  address.objectId = InvalidOid;
1706  address.objectSubId = 0;
1707  }
1708 
1709  return address;
1710 }
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:1612
Oid get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
Definition: opclasscmds.c:220
Oid get_opfamily_oid(Oid amID, List *opfamilyname, bool missing_ok)
Definition: opclasscmds.c:139

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

Referenced by get_object_address(), and get_object_address_opf_member().

◆ get_object_address_opf_member()

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

Definition at line 1718 of file objectaddress.c.

1720 {
1721  ObjectAddress famaddr;
1722  ObjectAddress address;
1723  ListCell *cell;
1724  List *copy;
1725  TypeName *typenames[2];
1726  Oid typeoids[2];
1727  int membernum;
1728  int i;
1729 
1730  /*
1731  * The last element of the object list contains the strategy or procedure
1732  * number. We need to strip that out before getting the opclass/family
1733  * address. The rest can be used directly by get_object_address_opcf().
1734  */
1735  membernum = atoi(strVal(llast(linitial(object))));
1736  copy = list_copy_head(linitial(object), list_length(linitial(object)) - 1);
1737 
1738  /* no missing_ok support here */
1739  famaddr = get_object_address_opcf(OBJECT_OPFAMILY, copy, false);
1740 
1741  /* find out left/right type names and OIDs */
1742  typenames[0] = typenames[1] = NULL;
1743  typeoids[0] = typeoids[1] = InvalidOid;
1744  i = 0;
1745  foreach(cell, lsecond(object))
1746  {
1747  ObjectAddress typaddr;
1748 
1749  typenames[i] = lfirst_node(TypeName, cell);
1750  typaddr = get_object_address_type(OBJECT_TYPE, typenames[i], missing_ok);
1751  typeoids[i] = typaddr.objectId;
1752  if (++i >= 2)
1753  break;
1754  }
1755 
1756  switch (objtype)
1757  {
1758  case OBJECT_AMOP:
1759  {
1760  HeapTuple tp;
1761 
1762  ObjectAddressSet(address, AccessMethodOperatorRelationId,
1763  InvalidOid);
1764 
1766  ObjectIdGetDatum(famaddr.objectId),
1767  ObjectIdGetDatum(typeoids[0]),
1768  ObjectIdGetDatum(typeoids[1]),
1769  Int16GetDatum(membernum));
1770  if (!HeapTupleIsValid(tp))
1771  {
1772  if (!missing_ok)
1773  ereport(ERROR,
1774  (errcode(ERRCODE_UNDEFINED_OBJECT),
1775  errmsg("operator %d (%s, %s) of %s does not exist",
1776  membernum,
1779  getObjectDescription(&famaddr, false))));
1780  }
1781  else
1782  {
1783  address.objectId = ((Form_pg_amop) GETSTRUCT(tp))->oid;
1784  ReleaseSysCache(tp);
1785  }
1786  }
1787  break;
1788 
1789  case OBJECT_AMPROC:
1790  {
1791  HeapTuple tp;
1792 
1793  ObjectAddressSet(address, AccessMethodProcedureRelationId,
1794  InvalidOid);
1795 
1797  ObjectIdGetDatum(famaddr.objectId),
1798  ObjectIdGetDatum(typeoids[0]),
1799  ObjectIdGetDatum(typeoids[1]),
1800  Int16GetDatum(membernum));
1801  if (!HeapTupleIsValid(tp))
1802  {
1803  if (!missing_ok)
1804  ereport(ERROR,
1805  (errcode(ERRCODE_UNDEFINED_OBJECT),
1806  errmsg("function %d (%s, %s) of %s does not exist",
1807  membernum,
1810  getObjectDescription(&famaddr, false))));
1811  }
1812  else
1813  {
1814  address.objectId = ((Form_pg_amproc) GETSTRUCT(tp))->oid;
1815  ReleaseSysCache(tp);
1816  }
1817  }
1818  break;
1819  default:
1820  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1821  }
1822 
1823  return address;
1824 }
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:850
@ AMPROCNUM
Definition: syscache.h:39
@ AMOPSTRATEGY
Definition: syscache.h:38

References AMOPSTRATEGY, AMPROCNUM, elog(), ereport, errcode(), errmsg(), ERROR, get_object_address_opcf(), get_object_address_type(), getObjectDescription(), GETSTRUCT, HeapTupleIsValid, i, Int16GetDatum(), InvalidOid, lfirst_node, linitial, list_copy_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 1901 of file objectaddress.c.

1903 {
1904  ObjectAddress address;
1905  Relation relation;
1906  List *relname;
1907  char *pubname;
1908  Publication *pub;
1909 
1910  ObjectAddressSet(address, PublicationRelRelationId, InvalidOid);
1911 
1912  relname = linitial(object);
1914  AccessShareLock, missing_ok);
1915  if (!relation)
1916  return address;
1917 
1918  /* fetch publication name from input list */
1919  pubname = strVal(lsecond(object));
1920 
1921  /* Now look up the pg_publication tuple */
1922  pub = GetPublicationByName(pubname, missing_ok);
1923  if (!pub)
1924  {
1925  relation_close(relation, AccessShareLock);
1926  return address;
1927  }
1928 
1929  /* Find the publication relation mapping in syscache. */
1930  address.objectId =
1931  GetSysCacheOid2(PUBLICATIONRELMAP, Anum_pg_publication_rel_oid,
1933  ObjectIdGetDatum(pub->oid));
1934  if (!OidIsValid(address.objectId))
1935  {
1936  if (!missing_ok)
1937  ereport(ERROR,
1938  (errcode(ERRCODE_UNDEFINED_OBJECT),
1939  errmsg("publication relation \"%s\" in publication \"%s\" does not exist",
1940  RelationGetRelationName(relation), pubname)));
1941  relation_close(relation, AccessShareLock);
1942  return address;
1943  }
1944 
1945  *relp = relation;
1946  return address;
1947 }
#define AccessShareLock
Definition: lockdefs.h:36
Publication * GetPublicationByName(const char *pubname, bool missing_ok)
Relation relation_openrv_extended(const RangeVar *relation, LOCKMODE lockmode, bool missing_ok)
Definition: relation.c:173
@ PUBLICATIONRELMAP
Definition: syscache.h:85
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition: syscache.h:199

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

Referenced by get_object_address().

◆ get_object_address_publication_schema()

static ObjectAddress get_object_address_publication_schema ( List object,
bool  missing_ok 
)
static

Definition at line 1954 of file objectaddress.c.

1955 {
1956  ObjectAddress address;
1957  Publication *pub;
1958  char *pubname;
1959  char *schemaname;
1960  Oid schemaid;
1961 
1962  ObjectAddressSet(address, PublicationNamespaceRelationId, InvalidOid);
1963 
1964  /* Fetch schema name and publication name from input list */
1965  schemaname = strVal(linitial(object));
1966  pubname = strVal(lsecond(object));
1967 
1968  schemaid = get_namespace_oid(schemaname, missing_ok);
1969  if (!OidIsValid(schemaid))
1970  return address;
1971 
1972  /* Now look up the pg_publication tuple */
1973  pub = GetPublicationByName(pubname, missing_ok);
1974  if (!pub)
1975  return address;
1976 
1977  /* Find the publication schema mapping in syscache */
1978  address.objectId =
1980  Anum_pg_publication_namespace_oid,
1981  ObjectIdGetDatum(schemaid),
1982  ObjectIdGetDatum(pub->oid));
1983  if (!OidIsValid(address.objectId) && !missing_ok)
1984  ereport(ERROR,
1985  (errcode(ERRCODE_UNDEFINED_OBJECT),
1986  errmsg("publication schema \"%s\" in publication \"%s\" does not exist",
1987  schemaname, pubname)));
1988 
1989  return address;
1990 }
@ PUBLICATIONNAMESPACEMAP
Definition: syscache.h:82

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

Referenced by get_object_address().

◆ get_object_address_relobject()

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

Definition at line 1453 of file objectaddress.c.

1455 {
1456  ObjectAddress address;
1457  Relation relation = NULL;
1458  int nnames;
1459  const char *depname;
1460  List *relname;
1461  Oid reloid;
1462 
1463  /* Extract name of dependent object. */
1464  depname = strVal(llast(object));
1465 
1466  /* Separate relation name from dependent object name. */
1467  nnames = list_length(object);
1468  if (nnames < 2)
1469  ereport(ERROR,
1470  (errcode(ERRCODE_SYNTAX_ERROR),
1471  errmsg("must specify relation and object name")));
1472 
1473  /* Extract relation name and open relation. */
1474  relname = list_copy_head(object, nnames - 1);
1477  missing_ok);
1478 
1479  reloid = relation ? RelationGetRelid(relation) : InvalidOid;
1480 
1481  switch (objtype)
1482  {
1483  case OBJECT_RULE:
1484  address.classId = RewriteRelationId;
1485  address.objectId = relation ?
1486  get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
1487  address.objectSubId = 0;
1488  break;
1489  case OBJECT_TRIGGER:
1490  address.classId = TriggerRelationId;
1491  address.objectId = relation ?
1492  get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
1493  address.objectSubId = 0;
1494  break;
1495  case OBJECT_TABCONSTRAINT:
1496  address.classId = ConstraintRelationId;
1497  address.objectId = relation ?
1498  get_relation_constraint_oid(reloid, depname, missing_ok) :
1499  InvalidOid;
1500  address.objectSubId = 0;
1501  break;
1502  case OBJECT_POLICY:
1503  address.classId = PolicyRelationId;
1504  address.objectId = relation ?
1505  get_relation_policy_oid(reloid, depname, missing_ok) :
1506  InvalidOid;
1507  address.objectSubId = 0;
1508  break;
1509  default:
1510  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1511  }
1512 
1513  /* Avoid relcache leak when object not found. */
1514  if (!OidIsValid(address.objectId))
1515  {
1516  if (relation != NULL)
1517  table_close(relation, AccessShareLock);
1518 
1519  relation = NULL; /* department of accident prevention */
1520  return address;
1521  }
1522 
1523  /* Done. */
1524  *relp = relation;
1525  return address;
1526 }
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:1207
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:1377

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

1261 {
1262  if (rel)
1263  {
1264  object = lcons(makeString(rel->relname), object);
1265  if (rel->schemaname)
1266  object = lcons(makeString(rel->schemaname), object);
1267  if (rel->catalogname)
1268  object = lcons(makeString(rel->catalogname), object);
1269  }
1270 
1271  return get_object_address(objtype, (Node *) object,
1272  relp, lockmode, missing_ok);
1273 }
List * lcons(void *datum, List *list)
Definition: list.c:494
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
Definition: nodes.h:129
char * relname
Definition: primnodes.h:74
char * catalogname
Definition: primnodes.h:68
char * schemaname
Definition: primnodes.h:71
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 1641 of file objectaddress.c.

1642 {
1643  ObjectAddress address;
1644  Type tup;
1645 
1646  address.classId = TypeRelationId;
1647  address.objectId = InvalidOid;
1648  address.objectSubId = 0;
1649 
1650  tup = LookupTypeName(NULL, typename, NULL, missing_ok);
1651  if (!HeapTupleIsValid(tup))
1652  {
1653  if (!missing_ok)
1654  ereport(ERROR,
1655  (errcode(ERRCODE_UNDEFINED_OBJECT),
1656  errmsg("type \"%s\" does not exist",
1657  TypeNameToString(typename))));
1658  return address;
1659  }
1660  address.objectId = typeTypeId(tup);
1661 
1662  if (objtype == OBJECT_DOMAIN)
1663  {
1664  if (((Form_pg_type) GETSTRUCT(tup))->typtype != TYPTYPE_DOMAIN)
1665  ereport(ERROR,
1666  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1667  errmsg("\"%s\" is not a domain",
1668  TypeNameToString(typename))));
1669  }
1670 
1671  ReleaseSysCache(tup);
1672 
1673  return address;
1674 }
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 1280 of file objectaddress.c.

1282 {
1283  const char *name;
1284  ObjectAddress address;
1285 
1286  name = strVal(strval);
1287 
1288  /* Translate name to OID. */
1289  switch (objtype)
1290  {
1291  case OBJECT_ACCESS_METHOD:
1292  address.classId = AccessMethodRelationId;
1293  address.objectId = get_am_oid(name, missing_ok);
1294  address.objectSubId = 0;
1295  break;
1296  case OBJECT_DATABASE:
1297  address.classId = DatabaseRelationId;
1298  address.objectId = get_database_oid(name, missing_ok);
1299  address.objectSubId = 0;
1300  break;
1301  case OBJECT_EXTENSION:
1302  address.classId = ExtensionRelationId;
1303  address.objectId = get_extension_oid(name, missing_ok);
1304  address.objectSubId = 0;
1305  break;
1306  case OBJECT_TABLESPACE:
1307  address.classId = TableSpaceRelationId;
1308  address.objectId = get_tablespace_oid(name, missing_ok);
1309  address.objectSubId = 0;
1310  break;
1311  case OBJECT_ROLE:
1312  address.classId = AuthIdRelationId;
1313  address.objectId = get_role_oid(name, missing_ok);
1314  address.objectSubId = 0;
1315  break;
1316  case OBJECT_SCHEMA:
1317  address.classId = NamespaceRelationId;
1318  address.objectId = get_namespace_oid(name, missing_ok);
1319  address.objectSubId = 0;
1320  break;
1321  case OBJECT_LANGUAGE:
1322  address.classId = LanguageRelationId;
1323  address.objectId = get_language_oid(name, missing_ok);
1324  address.objectSubId = 0;
1325  break;
1326  case OBJECT_FDW:
1327  address.classId = ForeignDataWrapperRelationId;
1328  address.objectId = get_foreign_data_wrapper_oid(name, missing_ok);
1329  address.objectSubId = 0;
1330  break;
1331  case OBJECT_FOREIGN_SERVER:
1332  address.classId = ForeignServerRelationId;
1333  address.objectId = get_foreign_server_oid(name, missing_ok);
1334  address.objectSubId = 0;
1335  break;
1336  case OBJECT_EVENT_TRIGGER:
1337  address.classId = EventTriggerRelationId;
1338  address.objectId = get_event_trigger_oid(name, missing_ok);
1339  address.objectSubId = 0;
1340  break;
1341  case OBJECT_PARAMETER_ACL:
1342  address.classId = ParameterAclRelationId;
1343  address.objectId = ParameterAclLookup(name, missing_ok);
1344  address.objectSubId = 0;
1345  break;
1346  case OBJECT_PUBLICATION:
1347  address.classId = PublicationRelationId;
1348  address.objectId = get_publication_oid(name, missing_ok);
1349  address.objectSubId = 0;
1350  break;
1351  case OBJECT_SUBSCRIPTION:
1352  address.classId = SubscriptionRelationId;
1353  address.objectId = get_subscription_oid(name, missing_ok);
1354  address.objectSubId = 0;
1355  break;
1356  default:
1357  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1358  /* placate compiler, which doesn't know elog won't return */
1359  address.classId = InvalidOid;
1360  address.objectId = InvalidOid;
1361  address.objectSubId = 0;
1362  }
1363 
1364  return address;
1365 }
Oid get_role_oid(const char *rolname, bool missing_ok)
Definition: acl.c:5255
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:1432
Oid get_database_oid(const char *dbname, bool missing_ok)
Definition: dbcommands.c:2981
const char * name
Definition: encode.c:571
Oid get_event_trigger_oid(const char *trigname, bool missing_ok)
Oid get_extension_oid(const char *extname, bool missing_ok)
Definition: extension.c:142
Oid get_foreign_server_oid(const char *servername, bool missing_ok)
Definition: foreign.c:690
Oid get_foreign_data_wrapper_oid(const char *fdwname, bool missing_ok)
Definition: foreign.c:667
Oid get_publication_oid(const char *pubname, bool missing_ok)
Definition: lsyscache.c:3594
Oid get_subscription_oid(const char *subname, bool missing_ok)
Definition: lsyscache.c:3644
Oid ParameterAclLookup(const char *parameter, bool missing_ok)

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

Referenced by get_object_address().

◆ get_object_address_usermapping()

static ObjectAddress get_object_address_usermapping ( List object,
bool  missing_ok 
)
static

Definition at line 1830 of file objectaddress.c.

1831 {
1832  ObjectAddress address;
1833  Oid userid;
1834  char *username;
1835  char *servername;
1836  ForeignServer *server;
1837  HeapTuple tp;
1838 
1839  ObjectAddressSet(address, UserMappingRelationId, InvalidOid);
1840 
1841  /* fetch string names from input lists, for error messages */
1842  username = strVal(linitial(object));
1843  servername = strVal(lsecond(object));
1844 
1845  /* look up pg_authid OID of mapped user; InvalidOid if PUBLIC */
1846  if (strcmp(username, "public") == 0)
1847  userid = InvalidOid;
1848  else
1849  {
1852  if (!HeapTupleIsValid(tp))
1853  {
1854  if (!missing_ok)
1855  ereport(ERROR,
1856  (errcode(ERRCODE_UNDEFINED_OBJECT),
1857  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1858  username, servername)));
1859  return address;
1860  }
1861  userid = ((Form_pg_authid) GETSTRUCT(tp))->oid;
1862  ReleaseSysCache(tp);
1863  }
1864 
1865  /* Now look up the pg_user_mapping tuple */
1866  server = GetForeignServerByName(servername, true);
1867  if (!server)
1868  {
1869  if (!missing_ok)
1870  ereport(ERROR,
1871  (errcode(ERRCODE_UNDEFINED_OBJECT),
1872  errmsg("server \"%s\" does not exist", servername)));
1873  return address;
1874  }
1875  tp = SearchSysCache2(USERMAPPINGUSERSERVER,
1876  ObjectIdGetDatum(userid),
1877  ObjectIdGetDatum(server->serverid));
1878  if (!HeapTupleIsValid(tp))
1879  {
1880  if (!missing_ok)
1881  ereport(ERROR,
1882  (errcode(ERRCODE_UNDEFINED_OBJECT),
1883  errmsg("user mapping for user \"%s\" on server \"%s\" does not exist",
1884  username, servername)));
1885  return address;
1886  }
1887 
1888  address.objectId = ((Form_pg_user_mapping) GETSTRUCT(tp))->oid;
1889 
1890  ReleaseSysCache(tp);
1891 
1892  return address;
1893 }
ForeignServer * GetForeignServerByName(const char *srvname, bool missing_ok)
Definition: foreign.c:182
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:828

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

Referenced by get_object_address().

◆ get_object_attnum_acl()

AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 2725 of file objectaddress.c.

2726 {
2727  const ObjectPropertyType *prop = get_object_property_data(class_id);
2728 
2729  return prop->attnum_acl;
2730 }
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(), 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()

AttrNumber get_object_attnum_owner ( Oid  class_id)

◆ get_object_catcache_name()

int get_object_catcache_name ( Oid  class_id)

Definition at line 2685 of file objectaddress.c.

2686 {
2687  const ObjectPropertyType *prop = get_object_property_data(class_id);
2688 
2689  return prop->name_catcache_id;
2690 }

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)

Definition at line 2661 of file objectaddress.c.

2662 {
2663  const ObjectPropertyType *prop = get_object_property_data(class_id);
2664 
2665  return prop->class_descr;
2666 }
const char * class_descr

References ObjectPropertyType::class_descr, and get_object_property_data().

Referenced by DropObjectById(), ExecGrant_common(), object_aclmask(), object_ownercheck(), and recordExtObjInitPriv().

◆ get_object_namensp_unique()

bool get_object_namensp_unique ( Oid  class_id)

Definition at line 2758 of file objectaddress.c.

2759 {
2760  const ObjectPropertyType *prop = get_object_property_data(class_id);
2761 
2762  return prop->is_nsp_name_unique;
2763 }

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

2603 {
2604  int cache;
2605  HeapTuple tuple;
2606  bool isnull;
2607  Oid oid;
2608  const ObjectPropertyType *property;
2609 
2610  /* If not owned by a namespace, just return InvalidOid. */
2611  property = get_object_property_data(address->classId);
2612  if (property->attnum_namespace == InvalidAttrNumber)
2613  return InvalidOid;
2614 
2615  /* Currently, we can only handle object types with system caches. */
2616  cache = property->oid_catcache_id;
2617  Assert(cache != -1);
2618 
2619  /* Fetch tuple from syscache and extract namespace attribute. */
2620  tuple = SearchSysCache1(cache, ObjectIdGetDatum(address->objectId));
2621  if (!HeapTupleIsValid(tuple))
2622  elog(ERROR, "cache lookup failed for cache %d oid %u",
2623  cache, address->objectId);
2624  oid = DatumGetObjectId(SysCacheGetAttr(cache,
2625  tuple,
2626  property->attnum_namespace,
2627  &isnull));
2628  Assert(!isnull);
2629  ReleaseSysCache(tuple);
2630 
2631  return oid;
2632 }
static Oid DatumGetObjectId(Datum X)
Definition: postgres.h:242
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1078

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

Referenced by RemoveObjects().

◆ get_object_oid_index()

Oid get_object_oid_index ( Oid  class_id)

Definition at line 2669 of file objectaddress.c.

2670 {
2671  const ObjectPropertyType *prop = get_object_property_data(class_id);
2672 
2673  return prop->oid_index_oid;
2674 }

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

2788 {
2789  static const ObjectPropertyType *prop_last = NULL;
2790  int index;
2791 
2792  /*
2793  * A shortcut to speed up multiple consecutive lookups of a particular
2794  * object class.
2795  */
2796  if (prop_last && prop_last->class_oid == class_id)
2797  return prop_last;
2798 
2799  for (index = 0; index < lengthof(ObjectProperty); index++)
2800  {
2801  if (ObjectProperty[index].class_oid == class_id)
2802  {
2803  prop_last = &ObjectProperty[index];
2804  return &ObjectProperty[index];
2805  }
2806  }
2807 
2808  ereport(ERROR,
2809  (errmsg_internal("unrecognized class ID: %u", class_id)));
2810 
2811  return NULL; /* keep MSC compiler happy */
2812 }
#define lengthof(array)
Definition: c.h:772
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1156
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 2740 of file objectaddress.c.

2741 {
2742  const ObjectPropertyType *prop = get_object_property_data(class_id);
2743 
2744  if (prop->objtype == OBJECT_TABLE)
2745  {
2746  /*
2747  * If the property data says it's a table, dig a little deeper to get
2748  * the real relation kind, so that callers can produce more precise
2749  * error messages.
2750  */
2751  return get_relkind_objtype(get_rel_relkind(object_id));
2752  }
2753  else
2754  return prop->objtype;
2755 }
char get_rel_relkind(Oid relid)
Definition: lsyscache.c:1985
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().

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

1374 {
1375  Relation relation;
1376  ObjectAddress address;
1377 
1378  address.classId = RelationRelationId;
1379  address.objectId = InvalidOid;
1380  address.objectSubId = 0;
1381 
1383  lockmode, missing_ok);
1384  if (!relation)
1385  return address;
1386 
1387  switch (objtype)
1388  {
1389  case OBJECT_INDEX:
1390  if (relation->rd_rel->relkind != RELKIND_INDEX &&
1391  relation->rd_rel->relkind != RELKIND_PARTITIONED_INDEX)
1392  ereport(ERROR,
1393  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1394  errmsg("\"%s\" is not an index",
1395  RelationGetRelationName(relation))));
1396  break;
1397  case OBJECT_SEQUENCE:
1398  if (relation->rd_rel->relkind != RELKIND_SEQUENCE)
1399  ereport(ERROR,
1400  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1401  errmsg("\"%s\" is not a sequence",
1402  RelationGetRelationName(relation))));
1403  break;
1404  case OBJECT_TABLE:
1405  if (relation->rd_rel->relkind != RELKIND_RELATION &&
1406  relation->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
1407  ereport(ERROR,
1408  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1409  errmsg("\"%s\" is not a table",
1410  RelationGetRelationName(relation))));
1411  break;
1412  case OBJECT_VIEW:
1413  if (relation->rd_rel->relkind != RELKIND_VIEW)
1414  ereport(ERROR,
1415  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1416  errmsg("\"%s\" is not a view",
1417  RelationGetRelationName(relation))));
1418  break;
1419  case OBJECT_MATVIEW:
1420  if (relation->rd_rel->relkind != RELKIND_MATVIEW)
1421  ereport(ERROR,
1422  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1423  errmsg("\"%s\" is not a materialized view",
1424  RelationGetRelationName(relation))));
1425  break;
1426  case OBJECT_FOREIGN_TABLE:
1427  if (relation->rd_rel->relkind != RELKIND_FOREIGN_TABLE)
1428  ereport(ERROR,
1429  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1430  errmsg("\"%s\" is not a foreign table",
1431  RelationGetRelationName(relation))));
1432  break;
1433  default:
1434  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1435  break;
1436  }
1437 
1438  /* Done. */
1439  address.objectId = RelationGetRelid(relation);
1440  *relp = relation;
1441 
1442  return address;
1443 }
Form_pg_class rd_rel
Definition: rel.h:110

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

6110 {
6111  switch (relkind)
6112  {
6113  case RELKIND_RELATION:
6114  case RELKIND_PARTITIONED_TABLE:
6115  return OBJECT_TABLE;
6116  case RELKIND_INDEX:
6117  case RELKIND_PARTITIONED_INDEX:
6118  return OBJECT_INDEX;
6119  case RELKIND_SEQUENCE:
6120  return OBJECT_SEQUENCE;
6121  case RELKIND_VIEW:
6122  return OBJECT_VIEW;
6123  case RELKIND_MATVIEW:
6124  return OBJECT_MATVIEW;
6125  case RELKIND_FOREIGN_TABLE:
6126  return OBJECT_FOREIGN_TABLE;
6127  case RELKIND_TOASTVALUE:
6128  return OBJECT_TABLE;
6129  default:
6130  /* Per above, don't raise an error */
6131  return OBJECT_TABLE;
6132  }
6133 }

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

Referenced by AlterTableMoveAll(), ATExecChangeOwner(), ATSimplePermissions(), checkFkeyPermissions(), CreateStatistics(), CreateTriggerFiringOn(), currtid_internal(), DefineQueryRewrite(), EnableDisableRule(), 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(), 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 4673 of file objectaddress.c.

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

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

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

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

◆ getObjectDescriptionOids()

char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 4076 of file objectaddress.c.

4077 {
4078  ObjectAddress address;
4079 
4080  address.classId = classid;
4081  address.objectId = objid;
4082  address.objectSubId = 0;
4083 
4084  return getObjectDescription(&address, false);
4085 }

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

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