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

2428 {
2429  switch (objtype)
2430  {
2431  case OBJECT_INDEX:
2432  case OBJECT_SEQUENCE:
2433  case OBJECT_TABLE:
2434  case OBJECT_VIEW:
2435  case OBJECT_MATVIEW:
2436  case OBJECT_FOREIGN_TABLE:
2437  case OBJECT_COLUMN:
2438  case OBJECT_RULE:
2439  case OBJECT_TRIGGER:
2440  case OBJECT_POLICY:
2441  case OBJECT_TABCONSTRAINT:
2442  if (!object_ownercheck(RelationRelationId, RelationGetRelid(relation), roleid))
2444  RelationGetRelationName(relation));
2445  break;
2446  case OBJECT_TYPE:
2447  case OBJECT_DOMAIN:
2448  case OBJECT_ATTRIBUTE:
2449  if (!object_ownercheck(address.classId, address.objectId, roleid))
2451  break;
2452  case OBJECT_DOMCONSTRAINT:
2453  {
2454  HeapTuple tuple;
2455  Oid contypid;
2456 
2457  tuple = SearchSysCache1(CONSTROID,
2458  ObjectIdGetDatum(address.objectId));
2459  if (!HeapTupleIsValid(tuple))
2460  elog(ERROR, "constraint with OID %u does not exist",
2461  address.objectId);
2462 
2463  contypid = ((Form_pg_constraint) GETSTRUCT(tuple))->contypid;
2464 
2465  ReleaseSysCache(tuple);
2466 
2467  /*
2468  * Fallback to type ownership check in this case as this is
2469  * what domain constraints rely on.
2470  */
2471  if (!object_ownercheck(TypeRelationId, contypid, roleid))
2473  }
2474  break;
2475  case OBJECT_AGGREGATE:
2476  case OBJECT_FUNCTION:
2477  case OBJECT_PROCEDURE:
2478  case OBJECT_ROUTINE:
2479  case OBJECT_OPERATOR:
2480  if (!object_ownercheck(address.classId, address.objectId, roleid))
2482  NameListToString((castNode(ObjectWithArgs, object))->objname));
2483  break;
2484  case OBJECT_DATABASE:
2485  case OBJECT_EVENT_TRIGGER:
2486  case OBJECT_EXTENSION:
2487  case OBJECT_FDW:
2488  case OBJECT_FOREIGN_SERVER:
2489  case OBJECT_LANGUAGE:
2490  case OBJECT_PUBLICATION:
2491  case OBJECT_SCHEMA:
2492  case OBJECT_SUBSCRIPTION:
2493  case OBJECT_TABLESPACE:
2494  if (!object_ownercheck(address.classId, address.objectId, roleid))
2496  strVal(object));
2497  break;
2498  case OBJECT_COLLATION:
2499  case OBJECT_CONVERSION:
2500  case OBJECT_OPCLASS:
2501  case OBJECT_OPFAMILY:
2502  case OBJECT_STATISTIC_EXT:
2503  case OBJECT_TSDICTIONARY:
2505  if (!object_ownercheck(address.classId, address.objectId, roleid))
2507  NameListToString(castNode(List, object)));
2508  break;
2509  case OBJECT_LARGEOBJECT:
2510  if (!lo_compat_privileges &&
2511  !object_ownercheck(address.classId, address.objectId, roleid))
2512  ereport(ERROR,
2513  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2514  errmsg("must be owner of large object %u",
2515  address.objectId)));
2516  break;
2517  case OBJECT_CAST:
2518  {
2519  /* We can only check permissions on the source/target types */
2520  TypeName *sourcetype = linitial_node(TypeName, castNode(List, object));
2521  TypeName *targettype = lsecond_node(TypeName, castNode(List, object));
2522  Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
2523  Oid targettypeid = typenameTypeId(NULL, targettype);
2524 
2525  if (!object_ownercheck(TypeRelationId, sourcetypeid, roleid)
2526  && !object_ownercheck(TypeRelationId, targettypeid, roleid))
2527  ereport(ERROR,
2528  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2529  errmsg("must be owner of type %s or type %s",
2530  format_type_be(sourcetypeid),
2531  format_type_be(targettypeid))));
2532  }
2533  break;
2534  case OBJECT_TRANSFORM:
2535  {
2536  TypeName *typename = linitial_node(TypeName, castNode(List, object));
2537  Oid typeid = typenameTypeId(NULL, typename);
2538 
2539  if (!object_ownercheck(TypeRelationId, typeid, roleid))
2541  }
2542  break;
2543  case OBJECT_ROLE:
2544 
2545  /*
2546  * We treat roles as being "owned" by those with CREATEROLE priv,
2547  * provided that they also have admin option on the role.
2548  *
2549  * However, superusers are only owned by superusers.
2550  */
2551  if (superuser_arg(address.objectId))
2552  {
2553  if (!superuser_arg(roleid))
2554  ereport(ERROR,
2555  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2556  errmsg("permission denied"),
2557  errdetail("The current user must have the %s attribute.",
2558  "SUPERUSER")));
2559  }
2560  else
2561  {
2562  if (!has_createrole_privilege(roleid))
2563  ereport(ERROR,
2564  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2565  errmsg("permission denied"),
2566  errdetail("The current user must have the %s attribute.",
2567  "CREATEROLE")));
2568  if (!is_admin_of_role(roleid, address.objectId))
2569  ereport(ERROR,
2570  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2571  errmsg("permission denied"),
2572  errdetail("The current user must have the %s option on role \"%s\".",
2573  "ADMIN",
2574  GetUserNameFromId(address.objectId,
2575  true))));
2576  }
2577  break;
2578  case OBJECT_TSPARSER:
2579  case OBJECT_TSTEMPLATE:
2580  case OBJECT_ACCESS_METHOD:
2581  case OBJECT_PARAMETER_ACL:
2582  /* We treat these object types as being owned by superusers */
2583  if (!superuser_arg(roleid))
2584  ereport(ERROR,
2585  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
2586  errmsg("must be superuser")));
2587  break;
2588  case OBJECT_AMOP:
2589  case OBJECT_AMPROC:
2590  case OBJECT_DEFAULT:
2591  case OBJECT_DEFACL:
2594  case OBJECT_USER_MAPPING:
2595  /* These are currently not supported or don't make sense here. */
2596  elog(ERROR, "unsupported object type: %d", (int) objtype);
2597  break;
2598  }
2599 }
bool is_admin_of_role(Oid member, Oid role)
Definition: acl.c:5190
@ ACLCHECK_NOT_OWNER
Definition: acl.h:184
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:2701
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition: aclchk.c:4132
void aclcheck_error_type(AclResult aclerr, Oid typeOid)
Definition: aclchk.c:3020
bool has_createrole_privilege(Oid roleid)
Definition: aclchk.c:4213
int errdetail(const char *fmt,...)
Definition: elog.c:1206
int errcode(int sqlerrcode)
Definition: elog.c:860
int errmsg(const char *fmt,...)
Definition: elog.c:1073
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
#define ereport(elevel,...)
Definition: elog.h:149
char * format_type_be(Oid type_oid)
Definition: format_type.c:343
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
bool lo_compat_privileges
Definition: inv_api.c:58
char * GetUserNameFromId(Oid roleid, bool noerr)
Definition: miscinit.c:981
char * NameListToString(const List *names)
Definition: namespace.c:3579
#define castNode(_type_, nodeptr)
Definition: nodes.h:176
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
Definition: parse_type.c:291
@ OBJECT_EVENT_TRIGGER
Definition: parsenodes.h:2118
@ OBJECT_FDW
Definition: parsenodes.h:2120
@ OBJECT_TSPARSER
Definition: parsenodes.h:2151
@ OBJECT_COLLATION
Definition: parsenodes.h:2111
@ OBJECT_USER_MAPPING
Definition: parsenodes.h:2154
@ OBJECT_ACCESS_METHOD
Definition: parsenodes.h:2104
@ OBJECT_OPCLASS
Definition: parsenodes.h:2128
@ OBJECT_DEFACL
Definition: parsenodes.h:2115
@ OBJECT_AGGREGATE
Definition: parsenodes.h:2105
@ OBJECT_MATVIEW
Definition: parsenodes.h:2127
@ OBJECT_SCHEMA
Definition: parsenodes.h:2140
@ OBJECT_POLICY
Definition: parsenodes.h:2132
@ OBJECT_OPERATOR
Definition: parsenodes.h:2129
@ OBJECT_FOREIGN_TABLE
Definition: parsenodes.h:2122
@ OBJECT_TSCONFIGURATION
Definition: parsenodes.h:2149
@ OBJECT_OPFAMILY
Definition: parsenodes.h:2130
@ OBJECT_DOMAIN
Definition: parsenodes.h:2116
@ OBJECT_COLUMN
Definition: parsenodes.h:2110
@ OBJECT_TABLESPACE
Definition: parsenodes.h:2146
@ OBJECT_ROLE
Definition: parsenodes.h:2137
@ OBJECT_ROUTINE
Definition: parsenodes.h:2138
@ OBJECT_LARGEOBJECT
Definition: parsenodes.h:2126
@ OBJECT_PUBLICATION_NAMESPACE
Definition: parsenodes.h:2135
@ OBJECT_PROCEDURE
Definition: parsenodes.h:2133
@ OBJECT_EXTENSION
Definition: parsenodes.h:2119
@ OBJECT_INDEX
Definition: parsenodes.h:2124
@ OBJECT_DEFAULT
Definition: parsenodes.h:2114
@ OBJECT_DATABASE
Definition: parsenodes.h:2113
@ OBJECT_SEQUENCE
Definition: parsenodes.h:2141
@ OBJECT_TSTEMPLATE
Definition: parsenodes.h:2152
@ OBJECT_LANGUAGE
Definition: parsenodes.h:2125
@ OBJECT_AMOP
Definition: parsenodes.h:2106
@ OBJECT_PUBLICATION_REL
Definition: parsenodes.h:2136
@ OBJECT_FOREIGN_SERVER
Definition: parsenodes.h:2121
@ OBJECT_TSDICTIONARY
Definition: parsenodes.h:2150
@ OBJECT_ATTRIBUTE
Definition: parsenodes.h:2108
@ OBJECT_PUBLICATION
Definition: parsenodes.h:2134
@ OBJECT_RULE
Definition: parsenodes.h:2139
@ OBJECT_CONVERSION
Definition: parsenodes.h:2112
@ OBJECT_AMPROC
Definition: parsenodes.h:2107
@ OBJECT_TABLE
Definition: parsenodes.h:2145
@ OBJECT_VIEW
Definition: parsenodes.h:2155
@ OBJECT_PARAMETER_ACL
Definition: parsenodes.h:2131
@ OBJECT_TYPE
Definition: parsenodes.h:2153
@ OBJECT_FUNCTION
Definition: parsenodes.h:2123
@ OBJECT_TABCONSTRAINT
Definition: parsenodes.h:2144
@ OBJECT_DOMCONSTRAINT
Definition: parsenodes.h:2117
@ OBJECT_SUBSCRIPTION
Definition: parsenodes.h:2142
@ OBJECT_STATISTIC_EXT
Definition: parsenodes.h:2143
@ OBJECT_CAST
Definition: parsenodes.h:2109
@ OBJECT_TRIGGER
Definition: parsenodes.h:2148
@ OBJECT_TRANSFORM
Definition: parsenodes.h:2147
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:504
#define RelationGetRelationName(relation)
Definition: rel.h:538
Definition: pg_list.h:54
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:267
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:219
#define strVal(v)
Definition: value.h:82

References aclcheck_error(), aclcheck_error_type(), ACLCHECK_NOT_OWNER, castNode, ObjectAddress::classId, elog, ereport, errcode(), errdetail(), errmsg(), ERROR, format_type_be(), GETSTRUCT, GetUserNameFromId(), has_createrole_privilege(), HeapTupleIsValid, is_admin_of_role(), linitial_node, lo_compat_privileges, lsecond_node, NameListToString(), OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_AMOP, OBJECT_AMPROC, OBJECT_ATTRIBUTE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DEFACL, OBJECT_DEFAULT, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, object_ownercheck(), OBJECT_PARAMETER_ACL, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_PUBLICATION_NAMESPACE, OBJECT_PUBLICATION_REL, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_USER_MAPPING, OBJECT_VIEW, ObjectAddress::objectId, ObjectIdGetDatum(), RelationGetRelationName, RelationGetRelid, ReleaseSysCache(), SearchSysCache1(), strVal, superuser_arg(), and typenameTypeId().

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

◆ get_catalog_object_by_oid()

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

Definition at line 2825 of file objectaddress.c.

2826 {
2827  HeapTuple tuple;
2828  Oid classId = RelationGetRelid(catalog);
2829  int oidCacheId = get_object_catcache_oid(classId);
2830 
2831  if (oidCacheId > 0)
2832  {
2833  tuple = SearchSysCacheCopy1(oidCacheId, ObjectIdGetDatum(objectId));
2834  if (!HeapTupleIsValid(tuple)) /* should not happen */
2835  return NULL;
2836  }
2837  else
2838  {
2839  Oid oidIndexId = get_object_oid_index(classId);
2840  SysScanDesc scan;
2841  ScanKeyData skey;
2842 
2843  Assert(OidIsValid(oidIndexId));
2844 
2845  ScanKeyInit(&skey,
2846  oidcol,
2847  BTEqualStrategyNumber, F_OIDEQ,
2848  ObjectIdGetDatum(objectId));
2849 
2850  scan = systable_beginscan(catalog, oidIndexId, true,
2851  NULL, 1, &skey);
2852  tuple = systable_getnext(scan);
2853  if (!HeapTupleIsValid(tuple))
2854  {
2855  systable_endscan(scan);
2856  return NULL;
2857  }
2858  tuple = heap_copytuple(tuple);
2859 
2860  systable_endscan(scan);
2861  }
2862 
2863  return tuple;
2864 }
#define OidIsValid(objectId)
Definition: c.h:762
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:777
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:86

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

Referenced by AlterObjectOwner_internal(), EventTriggerSQLDropAddObject(), getConstraintTypeDescription(), getObjectIdentityParts(), pg_event_trigger_ddl_commands(), 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 966 of file objectaddress.c.

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

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

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

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

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

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

Referenced by get_object_address().

◆ get_object_address_opcf()

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

Definition at line 1686 of file objectaddress.c.

1687 {
1688  Oid amoid;
1689  ObjectAddress address;
1690 
1691  /* XXX no missing_ok support here */
1692  amoid = get_index_am_oid(strVal(linitial(object)), false);
1693  object = list_copy_tail(object, 1);
1694 
1695  switch (objtype)
1696  {
1697  case OBJECT_OPCLASS:
1698  address.classId = OperatorClassRelationId;
1699  address.objectId = get_opclass_oid(amoid, object, missing_ok);
1700  address.objectSubId = 0;
1701  break;
1702  case OBJECT_OPFAMILY:
1703  address.classId = OperatorFamilyRelationId;
1704  address.objectId = get_opfamily_oid(amoid, object, missing_ok);
1705  address.objectSubId = 0;
1706  break;
1707  default:
1708  elog(ERROR, "unrecognized object type: %d", (int) objtype);
1709  /* placate compiler, which doesn't know elog won't return */
1710  address.classId = InvalidOid;
1711  address.objectId = InvalidOid;
1712  address.objectSubId = 0;
1713  }
1714 
1715  return address;
1716 }
Oid get_index_am_oid(const char *amname, bool missing_ok)
Definition: amcmds.c:163
List * list_copy_tail(const List *oldlist, int nskip)
Definition: list.c:1613
Oid get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
Definition: opclasscmds.c: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 1724 of file objectaddress.c.

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

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

Referenced by get_object_address().

◆ get_object_address_publication_rel()

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

Definition at line 1907 of file objectaddress.c.

1909 {
1910  ObjectAddress address;
1911  Relation relation;
1912  List *relname;
1913  char *pubname;
1914  Publication *pub;
1915 
1916  ObjectAddressSet(address, PublicationRelRelationId, InvalidOid);
1917 
1918  relname = linitial(object);
1920  AccessShareLock, missing_ok);
1921  if (!relation)
1922  return address;
1923 
1924  /* fetch publication name from input list */
1925  pubname = strVal(lsecond(object));
1926 
1927  /* Now look up the pg_publication tuple */
1928  pub = GetPublicationByName(pubname, missing_ok);
1929  if (!pub)
1930  {
1931  relation_close(relation, AccessShareLock);
1932  return address;
1933  }
1934 
1935  /* Find the publication relation mapping in syscache. */
1936  address.objectId =
1937  GetSysCacheOid2(PUBLICATIONRELMAP, Anum_pg_publication_rel_oid,
1939  ObjectIdGetDatum(pub->oid));
1940  if (!OidIsValid(address.objectId))
1941  {
1942  if (!missing_ok)
1943  ereport(ERROR,
1944  (errcode(ERRCODE_UNDEFINED_OBJECT),
1945  errmsg("publication relation \"%s\" in publication \"%s\" does not exist",
1946  RelationGetRelationName(relation), pubname)));
1947  relation_close(relation, AccessShareLock);
1948  return address;
1949  }
1950 
1951  *relp = relation;
1952  return address;
1953 }
#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
#define GetSysCacheOid2(cacheId, oidcol, key1, key2)
Definition: syscache.h:106

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

Referenced by get_object_address().

◆ get_object_address_publication_schema()

static ObjectAddress get_object_address_publication_schema ( List object,
bool  missing_ok 
)
static

Definition at line 1960 of file objectaddress.c.

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

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

Referenced by get_object_address().

◆ get_object_address_relobject()

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

Definition at line 1459 of file objectaddress.c.

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

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

1267 {
1268  if (rel)
1269  {
1270  object = lcons(makeString(rel->relname), object);
1271  if (rel->schemaname)
1272  object = lcons(makeString(rel->schemaname), object);
1273  if (rel->catalogname)
1274  object = lcons(makeString(rel->catalogname), object);
1275  }
1276 
1277  return get_object_address(objtype, (Node *) object,
1278  relp, lockmode, missing_ok);
1279 }
List * lcons(void *datum, List *list)
Definition: list.c:495
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
Definition: nodes.h:129
char * relname
Definition: primnodes.h:82
char * catalogname
Definition: primnodes.h:76
char * schemaname
Definition: primnodes.h:79
String * makeString(char *str)
Definition: value.c:63

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

Referenced by ExecAlterObjectDependsStmt().

◆ get_object_address_type()

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

Definition at line 1647 of file objectaddress.c.

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

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

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

Referenced by get_object_address().

◆ get_object_address_usermapping()

static ObjectAddress get_object_address_usermapping ( List object,
bool  missing_ok 
)
static

Definition at line 1836 of file objectaddress.c.

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

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

Referenced by get_object_address().

◆ get_object_attnum_acl()

AttrNumber get_object_attnum_acl ( Oid  class_id)

Definition at line 2728 of file objectaddress.c.

2729 {
2730  const ObjectPropertyType *prop = get_object_property_data(class_id);
2731 
2732  return prop->attnum_acl;
2733 }
static const ObjectPropertyType * get_object_property_data(Oid class_id)
AttrNumber attnum_acl

References ObjectPropertyType::attnum_acl, and get_object_property_data().

Referenced by AlterObjectOwner_internal(), ExecGrant_common(), object_aclmask_ext(), 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 2688 of file objectaddress.c.

2689 {
2690  const ObjectPropertyType *prop = get_object_property_data(class_id);
2691 
2692  return prop->name_catcache_id;
2693 }

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

2665 {
2666  const ObjectPropertyType *prop = get_object_property_data(class_id);
2667 
2668  return prop->class_descr;
2669 }
const char * class_descr

References ObjectPropertyType::class_descr, and get_object_property_data().

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

◆ get_object_namensp_unique()

bool get_object_namensp_unique ( Oid  class_id)

Definition at line 2761 of file objectaddress.c.

2762 {
2763  const ObjectPropertyType *prop = get_object_property_data(class_id);
2764 
2765  return prop->is_nsp_name_unique;
2766 }

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

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

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

Referenced by RemoveObjects().

◆ get_object_oid_index()

Oid get_object_oid_index ( Oid  class_id)

Definition at line 2672 of file objectaddress.c.

2673 {
2674  const ObjectPropertyType *prop = get_object_property_data(class_id);
2675 
2676  return prop->oid_index_oid;
2677 }

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

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

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

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

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

◆ get_relation_by_qualified_name()

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

Definition at line 1377 of file objectaddress.c.

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

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

Referenced by get_object_address().

◆ get_relkind_objtype()

ObjectType get_relkind_objtype ( char  relkind)

Definition at line 6106 of file objectaddress.c.

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

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(), RangeVarCallbackOwnsTable(), RangeVarGetAndCheckCreationNamespace(), renameatt_check(), TargetPrivilegesCheck(), transformTableLikeClause(), and truncate_check_perms().

◆ getConstraintTypeDescription()

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

Definition at line 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:182
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40

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

Referenced by getObjectTypeDescription().

◆ getObjectDescription()

char* getObjectDescription ( const ObjectAddress object,
bool  missing_ok 
)

Definition at line 2922 of file objectaddress.c.

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

References _, AccessShareLock, appendStringInfo(), Assert(), attname, BTEqualStrategyNumber, CollationIsVisible(), ConversionIsVisible(), StringInfoData::data, datname, elog, ERROR, ForeignDataWrapper::fdwname, format_operator(), format_operator_extended(), FORMAT_OPERATOR_INVALID_AS_NULL, FORMAT_PROC_INVALID_AS_NULL, format_procedure(), format_procedure_extended(), format_type_be(), format_type_extended(), FORMAT_TYPE_INVALID_AS_NULL, get_attname(), get_database_name(), get_extension_name(), get_language_name(), get_namespace_name(), get_publication_name(), get_subscription_name(), get_tablespace_name(), GetAttrDefaultColumnAddress(), GetForeignDataWrapperExtended(), GetForeignServer(), GetForeignServerExtended(), 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(), pfree(), proname, quote_qualified_identifier(), ReleaseSysCache(), ScanKeyInit(), SearchSysCache1(), ForeignServer::servername, StatisticsObjIsVisible(), subname, SysCacheGetAttrNotNull(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), table_open(), TextDatumGetCString, TSConfigIsVisible(), TSDictionaryIsVisible(), TSParserIsVisible(), TSTemplateIsVisible(), typname, and username.

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

◆ getObjectDescriptionOids()

char* getObjectDescriptionOids ( Oid  classid,
Oid  objid 
)

Definition at line 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 
5334  tup = SearchSysCache1(STATEXTOID,
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 
5361  tup = SearchSysCache1(TSPARSEROID,
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 
5415  tup = SearchSysCache1(TSTEMPLATEOID,
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 
5442  tup = SearchSysCache1(TSCONFIGOID,
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 
5597  tup = SearchSysCache1(USERMAPPINGOID,
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 
5740  tup = SearchSysCache1(EVENTTRIGGEROID,
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  char *parname;
5763 
5764  tup = SearchSysCache1(PARAMETERACLOID,
5765  ObjectIdGetDatum(object->objectId));
5766  if (!HeapTupleIsValid(tup))
5767  {
5768  if (!missing_ok)
5769  elog(ERROR, "cache lookup failed for parameter ACL %u",
5770  object->objectId);
5771  break;
5772  }
5773  nameDatum = SysCacheGetAttrNotNull(PARAMETERACLOID, tup,
5774  Anum_pg_parameter_acl_parname);
5775  parname = TextDatumGetCString(nameDatum);
5776  appendStringInfoString(&buffer, parname);
5777  if (objname)
5778  *objname = list_make1(parname);
5779  ReleaseSysCache(tup);
5780  break;
5781  }
5782 
5783  case OCLASS_POLICY:
5784  {
5785  Relation polDesc;
5786  HeapTuple tup;
5787  Form_pg_policy policy;
5788 
5789  polDesc = table_open(PolicyRelationId, AccessShareLock);
5790 
5791  tup = get_catalog_object_by_oid(polDesc, Anum_pg_policy_oid,
5792  object->objectId);
5793 
5794  if (!HeapTupleIsValid(tup))
5795  {
5796  if (!missing_ok)
5797  elog(ERROR, "could not find tuple for policy %u",
5798  object->objectId);
5799 
5800  table_close(polDesc, AccessShareLock);
5801  break;
5802  }
5803 
5804  policy = (Form_pg_policy) GETSTRUCT(tup);
5805 
5806  appendStringInfo(&buffer, "%s on ",
5807  quote_identifier(NameStr(policy->polname)));
5808  getRelationIdentity(&buffer, policy->polrelid, objname, false);
5809  if (objname)
5810  *objname = lappend(*objname, pstrdup(NameStr(policy->polname)));
5811 
5812  table_close(polDesc, AccessShareLock);
5813  break;
5814  }
5815 
5816  case OCLASS_PUBLICATION:
5817  {
5818  char *pubname;
5819 
5820  pubname = get_publication_name(object->objectId, missing_ok);
5821  if (pubname)
5822  {
5823  appendStringInfoString(&buffer,
5824  quote_identifier(pubname));
5825  if (objname)
5826  *objname = list_make1(pubname);
5827  }
5828  break;
5829  }
5830 
5832  {
5833  char *pubname;
5834  char *nspname;
5835 
5836  if (!getPublicationSchemaInfo(object, missing_ok, &pubname,
5837  &nspname))
5838  break;
5839  appendStringInfo(&buffer, "%s in publication %s",
5840  nspname, pubname);
5841 
5842  if (objargs)
5843  *objargs = list_make1(pubname);
5844  else
5845  pfree(pubname);
5846 
5847  if (objname)
5848  *objname = list_make1(nspname);
5849  else
5850  pfree(nspname);
5851 
5852  break;
5853  }
5854 
5856  {
5857  HeapTuple tup;
5858  char *pubname;
5859  Form_pg_publication_rel prform;
5860 
5861  tup = SearchSysCache1(PUBLICATIONREL,
5862  ObjectIdGetDatum(object->objectId));
5863  if (!HeapTupleIsValid(tup))
5864  {
5865  if (!missing_ok)
5866  elog(ERROR, "cache lookup failed for publication table %u",
5867  object->objectId);
5868  break;
5869  }
5870 
5871  prform = (Form_pg_publication_rel) GETSTRUCT(tup);
5872  pubname = get_publication_name(prform->prpubid, false);
5873 
5874  getRelationIdentity(&buffer, prform->prrelid, objname, false);
5875  appendStringInfo(&buffer, " in publication %s", pubname);
5876 
5877  if (objargs)
5878  *objargs = list_make1(pubname);
5879 
5880  ReleaseSysCache(tup);
5881  break;
5882  }
5883 
5884  case OCLASS_SUBSCRIPTION:
5885  {
5886  char *subname;
5887 
5888  subname = get_subscription_name(object->objectId, missing_ok);
5889  if (subname)
5890  {
5891  appendStringInfoString(&buffer,
5893  if (objname)
5894  *objname = list_make1(subname);
5895  }
5896  break;
5897  }
5898 
5899  case OCLASS_TRANSFORM:
5900  {
5901  Relation transformDesc;
5902  HeapTuple tup;
5903  Form_pg_transform transform;
5904  char *transformLang;
5905  char *transformType;
5906 
5907  transformDesc = table_open(TransformRelationId, AccessShareLock);
5908 
5909  tup = get_catalog_object_by_oid(transformDesc,
5910  Anum_pg_transform_oid,
5911  object->objectId);
5912 
5913  if (!HeapTupleIsValid(tup))
5914  {
5915  if (!missing_ok)
5916  elog(ERROR, "could not find tuple for transform %u",
5917  object->objectId);
5918 
5919  table_close(transformDesc, AccessShareLock);
5920  break;
5921  }
5922 
5923  transform = (Form_pg_transform) GETSTRUCT(tup);
5924 
5925  transformType = format_type_be_qualified(transform->trftype);
5926  transformLang = get_language_name(transform->trflang, false);
5927 
5928  appendStringInfo(&buffer, "for %s language %s",
5929  transformType,
5930  transformLang);
5931  if (objname)
5932  {
5933  *objname = list_make1(transformType);
5934  *objargs = list_make1(pstrdup(transformLang));
5935  }
5936 
5937  table_close(transformDesc, AccessShareLock);
5938  }
5939  break;
5940 
5941  /*
5942  * There's intentionally no default: case here; we want the
5943  * compiler to warn if a new OCLASS hasn't been handled above.
5944  */
5945  }
5946 
5947  if (!missing_ok)
5948  {
5949  /*
5950  * If a get_object_address() representation was requested, make sure
5951  * we are providing one. We don't check objargs, because many of the
5952  * cases above leave it as NIL.
5953  */
5954  if (objname && *objname == NIL)
5955  elog(ERROR, "requested object address for unsupported object class %d: text result \"%s\"",
5956  (int) getObjectClass(object), buffer.data);
5957  }
5958  else
5959  {
5960  /* an empty buffer is equivalent to no object found */
5961  if (buffer.len == 0)
5962  {
5963  Assert((objname == NULL || *objname == NIL) &&
5964  (objargs == NULL || *objargs == NIL));
5965  return NULL;
5966  }
5967  }
5968 
5969  return buffer.data;
5970 }
char * get_am_name(Oid amOid)
Definition: amcmds.c:192
#define FORMAT_TYPE_FORCE_QUALIFY
Definition: builtins.h:126
#define PointerIsValid(pointer)
Definition: c.h:750
char * format_type_be_qualified(Oid type_oid)
Definition: format_type.c:353
List * lappend(List *list, void *datum)
Definition: list.c:339
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3345
char * pstrdup(const char *in)
Definition: mcxt.c:1580
static void getOpFamilyIdentity(StringInfo buffer, Oid opfid, List **object, bool missing_ok)
static void getRelationIdentity(StringInfo buffer, Oid relid, List **object, bool missing_ok)
FormData_pg_language * Form_pg_language
Definition: pg_language.h:65
#define NIL
Definition: pg_list.h:68
#define list_make1(x1)
Definition: pg_list.h:212
#define list_make3(x1, x2, x3)
Definition: pg_list.h:216
#define list_make2(x1, x2)
Definition: pg_list.h:214
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
void format_operator_parts(Oid operator_oid, List **objnames, List **objargs, bool missing_ok)
Definition: regproc.c:806
void format_procedure_parts(Oid procedure_oid, List **objnames, List **objargs, bool missing_ok)
Definition: regproc.c:398
#define FORMAT_OPERATOR_FORCE_QUALIFY
Definition: regproc.h:25
#define FORMAT_PROC_FORCE_QUALIFY
Definition: