PostgreSQL Source Code  git master
alter.h File Reference
Include dependency graph for alter.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ObjectAddress ExecRenameStmt (RenameStmt *stmt)
 
ObjectAddress ExecAlterObjectDependsStmt (AlterObjectDependsStmt *stmt, ObjectAddress *refAddress)
 
ObjectAddress ExecAlterObjectSchemaStmt (AlterObjectSchemaStmt *stmt, ObjectAddress *oldSchemaAddr)
 
Oid AlterObjectNamespace_oid (Oid classId, Oid objid, Oid nspOid, ObjectAddresses *objsMoved)
 
ObjectAddress ExecAlterOwnerStmt (AlterOwnerStmt *stmt)
 
void AlterObjectOwner_internal (Relation rel, Oid objectId, Oid new_ownerId)
 

Function Documentation

◆ AlterObjectNamespace_oid()

Oid AlterObjectNamespace_oid ( Oid  classId,
Oid  objid,
Oid  nspOid,
ObjectAddresses objsMoved 
)

Definition at line 593 of file alter.c.

595 {
596  Oid oldNspOid = InvalidOid;
597  ObjectAddress dep;
598 
599  dep.classId = classId;
600  dep.objectId = objid;
601  dep.objectSubId = 0;
602 
603  switch (getObjectClass(&dep))
604  {
605  case OCLASS_CLASS:
606  {
607  Relation rel;
608 
609  rel = relation_open(objid, AccessExclusiveLock);
610  oldNspOid = RelationGetNamespace(rel);
611 
612  AlterTableNamespaceInternal(rel, oldNspOid, nspOid, objsMoved);
613 
614  relation_close(rel, NoLock);
615  break;
616  }
617 
618  case OCLASS_TYPE:
619  oldNspOid = AlterTypeNamespace_oid(objid, nspOid, objsMoved);
620  break;
621 
622  case OCLASS_PROC:
623  case OCLASS_COLLATION:
624  case OCLASS_CONVERSION:
625  case OCLASS_OPERATOR:
626  case OCLASS_OPCLASS:
627  case OCLASS_OPFAMILY:
629  case OCLASS_TSPARSER:
630  case OCLASS_TSDICT:
631  case OCLASS_TSTEMPLATE:
632  case OCLASS_TSCONFIG:
633  {
634  Relation catalog;
635 
636  catalog = table_open(classId, RowExclusiveLock);
637 
638  oldNspOid = AlterObjectNamespace_internal(catalog, objid,
639  nspOid);
640 
641  table_close(catalog, RowExclusiveLock);
642  }
643  break;
644 
645  case OCLASS_CAST:
646  case OCLASS_CONSTRAINT:
647  case OCLASS_DEFAULT:
648  case OCLASS_LANGUAGE:
649  case OCLASS_LARGEOBJECT:
650  case OCLASS_AM:
651  case OCLASS_AMOP:
652  case OCLASS_AMPROC:
653  case OCLASS_REWRITE:
654  case OCLASS_TRIGGER:
655  case OCLASS_SCHEMA:
656  case OCLASS_ROLE:
658  case OCLASS_DATABASE:
659  case OCLASS_TBLSPACE:
660  case OCLASS_FDW:
662  case OCLASS_USER_MAPPING:
663  case OCLASS_DEFACL:
664  case OCLASS_EXTENSION:
667  case OCLASS_POLICY:
668  case OCLASS_PUBLICATION:
671  case OCLASS_SUBSCRIPTION:
672  case OCLASS_TRANSFORM:
673  /* ignore object types that don't have schema-qualified names */
674  break;
675 
676  /*
677  * There's intentionally no default: case here; we want the
678  * compiler to warn if a new OCLASS hasn't been handled above.
679  */
680  }
681 
682  return oldNspOid;
683 }
static Oid AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid)
Definition: alter.c:697
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2836
@ OCLASS_OPERATOR
Definition: dependency.h:100
@ OCLASS_PARAMETER_ACL
Definition: dependency.h:124
@ OCLASS_LARGEOBJECT
Definition: dependency.h:99
@ OCLASS_FDW
Definition: dependency.h:118
@ OCLASS_OPFAMILY
Definition: dependency.h:102
@ OCLASS_DEFACL
Definition: dependency.h:121
@ OCLASS_TSPARSER
Definition: dependency.h:110
@ OCLASS_TRIGGER
Definition: dependency.h:107
@ OCLASS_DEFAULT
Definition: dependency.h:97
@ OCLASS_TSTEMPLATE
Definition: dependency.h:112
@ OCLASS_AMPROC
Definition: dependency.h:105
@ OCLASS_TBLSPACE
Definition: dependency.h:117
@ OCLASS_TSCONFIG
Definition: dependency.h:113
@ OCLASS_TYPE
Definition: dependency.h:92
@ OCLASS_LANGUAGE
Definition: dependency.h:98
@ OCLASS_CAST
Definition: dependency.h:93
@ OCLASS_SUBSCRIPTION
Definition: dependency.h:129
@ OCLASS_PUBLICATION_NAMESPACE
Definition: dependency.h:127
@ OCLASS_EXTENSION
Definition: dependency.h:122
@ OCLASS_COLLATION
Definition: dependency.h:94
@ OCLASS_FOREIGN_SERVER
Definition: dependency.h:119
@ OCLASS_REWRITE
Definition: dependency.h:106
@ OCLASS_STATISTIC_EXT
Definition: dependency.h:109
@ OCLASS_PROC
Definition: dependency.h:91
@ OCLASS_OPCLASS
Definition: dependency.h:101
@ OCLASS_CONVERSION
Definition: dependency.h:96
@ OCLASS_DATABASE
Definition: dependency.h:116
@ OCLASS_ROLE_MEMBERSHIP
Definition: dependency.h:115
@ OCLASS_SCHEMA
Definition: dependency.h:108
@ OCLASS_EVENT_TRIGGER
Definition: dependency.h:123
@ OCLASS_CLASS
Definition: dependency.h:90
@ OCLASS_TRANSFORM
Definition: dependency.h:130
@ OCLASS_ROLE
Definition: dependency.h:114
@ OCLASS_CONSTRAINT
Definition: dependency.h:95
@ OCLASS_POLICY
Definition: dependency.h:125
@ OCLASS_USER_MAPPING
Definition: dependency.h:120
@ OCLASS_PUBLICATION_REL
Definition: dependency.h:128
@ OCLASS_AM
Definition: dependency.h:103
@ OCLASS_TSDICT
Definition: dependency.h:111
@ OCLASS_PUBLICATION
Definition: dependency.h:126
@ OCLASS_AMOP
Definition: dependency.h:104
#define NoLock
Definition: lockdefs.h:34
#define AccessExclusiveLock
Definition: lockdefs.h:43
#define RowExclusiveLock
Definition: lockdefs.h:38
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
#define RelationGetNamespace(relation)
Definition: rel.h:542
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:206
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:48
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40
void AlterTableNamespaceInternal(Relation rel, Oid oldNspOid, Oid nspOid, ObjectAddresses *objsMoved)
Definition: tablecmds.c:16381
Oid AlterTypeNamespace_oid(Oid typeOid, Oid nspOid, ObjectAddresses *objsMoved)
Definition: typecmds.c:3914

References AccessExclusiveLock, AlterObjectNamespace_internal(), AlterTableNamespaceInternal(), AlterTypeNamespace_oid(), ObjectAddress::classId, getObjectClass(), InvalidOid, NoLock, ObjectAddress::objectId, 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, relation_close(), relation_open(), RelationGetNamespace, RowExclusiveLock, table_close(), and table_open().

Referenced by AlterExtensionNamespace().

◆ AlterObjectOwner_internal()

void AlterObjectOwner_internal ( Relation  rel,
Oid  objectId,
Oid  new_ownerId 
)

Definition at line 941 of file alter.c.

942 {
943  Oid classId = RelationGetRelid(rel);
944  AttrNumber Anum_oid = get_object_attnum_oid(classId);
945  AttrNumber Anum_owner = get_object_attnum_owner(classId);
946  AttrNumber Anum_namespace = get_object_attnum_namespace(classId);
947  AttrNumber Anum_acl = get_object_attnum_acl(classId);
948  AttrNumber Anum_name = get_object_attnum_name(classId);
949  HeapTuple oldtup;
950  Datum datum;
951  bool isnull;
952  Oid old_ownerId;
953  Oid namespaceId = InvalidOid;
954 
955  oldtup = get_catalog_object_by_oid(rel, Anum_oid, objectId);
956  if (oldtup == NULL)
957  elog(ERROR, "cache lookup failed for object %u of catalog \"%s\"",
958  objectId, RelationGetRelationName(rel));
959 
960  datum = heap_getattr(oldtup, Anum_owner,
961  RelationGetDescr(rel), &isnull);
962  Assert(!isnull);
963  old_ownerId = DatumGetObjectId(datum);
964 
965  if (Anum_namespace != InvalidAttrNumber)
966  {
967  datum = heap_getattr(oldtup, Anum_namespace,
968  RelationGetDescr(rel), &isnull);
969  Assert(!isnull);
970  namespaceId = DatumGetObjectId(datum);
971  }
972 
973  if (old_ownerId != new_ownerId)
974  {
975  AttrNumber nattrs;
976  HeapTuple newtup;
977  Datum *values;
978  bool *nulls;
979  bool *replaces;
980 
981  /* Superusers can bypass permission checks */
982  if (!superuser())
983  {
984  /* must be owner */
985  if (!has_privs_of_role(GetUserId(), old_ownerId))
986  {
987  char *objname;
988  char namebuf[NAMEDATALEN];
989 
990  if (Anum_name != InvalidAttrNumber)
991  {
992  datum = heap_getattr(oldtup, Anum_name,
993  RelationGetDescr(rel), &isnull);
994  Assert(!isnull);
995  objname = NameStr(*DatumGetName(datum));
996  }
997  else
998  {
999  snprintf(namebuf, sizeof(namebuf), "%u", objectId);
1000  objname = namebuf;
1001  }
1003  objname);
1004  }
1005  /* Must be able to become new owner */
1006  check_can_set_role(GetUserId(), new_ownerId);
1007 
1008  /* New owner must have CREATE privilege on namespace */
1009  if (OidIsValid(namespaceId))
1010  {
1011  AclResult aclresult;
1012 
1013  aclresult = object_aclcheck(NamespaceRelationId, namespaceId, new_ownerId,
1014  ACL_CREATE);
1015  if (aclresult != ACLCHECK_OK)
1016  aclcheck_error(aclresult, OBJECT_SCHEMA,
1017  get_namespace_name(namespaceId));
1018  }
1019  }
1020 
1021  /* Build a modified tuple */
1022  nattrs = RelationGetNumberOfAttributes(rel);
1023  values = palloc0(nattrs * sizeof(Datum));
1024  nulls = palloc0(nattrs * sizeof(bool));
1025  replaces = palloc0(nattrs * sizeof(bool));
1026  values[Anum_owner - 1] = ObjectIdGetDatum(new_ownerId);
1027  replaces[Anum_owner - 1] = true;
1028 
1029  /*
1030  * Determine the modified ACL for the new owner. This is only
1031  * necessary when the ACL is non-null.
1032  */
1033  if (Anum_acl != InvalidAttrNumber)
1034  {
1035  datum = heap_getattr(oldtup,
1036  Anum_acl, RelationGetDescr(rel), &isnull);
1037  if (!isnull)
1038  {
1039  Acl *newAcl;
1040 
1041  newAcl = aclnewowner(DatumGetAclP(datum),
1042  old_ownerId, new_ownerId);
1043  values[Anum_acl - 1] = PointerGetDatum(newAcl);
1044  replaces[Anum_acl - 1] = true;
1045  }
1046  }
1047 
1048  newtup = heap_modify_tuple(oldtup, RelationGetDescr(rel),
1049  values, nulls, replaces);
1050 
1051  /* Perform actual update */
1052  CatalogTupleUpdate(rel, &newtup->t_self, newtup);
1053 
1054  /* Update owner dependency reference */
1055  if (classId == LargeObjectMetadataRelationId)
1056  classId = LargeObjectRelationId;
1057  changeDependencyOnOwner(classId, objectId, new_ownerId);
1058 
1059  /* Release memory */
1060  pfree(values);
1061  pfree(nulls);
1062  pfree(replaces);
1063  }
1064 
1065  InvokeObjectPostAlterHook(classId, objectId, 0);
1066 }
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4969
Acl * aclnewowner(const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
Definition: acl.c:1090
void check_can_set_role(Oid member, Oid role)
Definition: acl.c:5026
AclResult
Definition: acl.h:182
@ ACLCHECK_OK
Definition: acl.h:183
@ ACLCHECK_NOT_OWNER
Definition: acl.h:185
#define DatumGetAclP(X)
Definition: acl.h:120
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:2679
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition: aclchk.c:3783
int16 AttrNumber
Definition: attnum.h:21
#define InvalidAttrNumber
Definition: attnum.h:23
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define NameStr(name)
Definition: c.h:730
#define OidIsValid(objectId)
Definition: c.h:759
#define ERROR
Definition: elog.h:39
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
Definition: heaptuple.c:1113
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: htup_details.h:792
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:301
Assert(fmt[strlen(fmt) - 1] !='\n')
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3331
void pfree(void *pointer)
Definition: mcxt.c:1436
void * palloc0(Size size)
Definition: mcxt.c:1241
Oid GetUserId(void)
Definition: miscinit.c:502
#define InvokeObjectPostAlterHook(classId, objectId, subId)
Definition: objectaccess.h:197
AttrNumber get_object_attnum_owner(Oid class_id)
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
AttrNumber get_object_attnum_oid(Oid class_id)
AttrNumber get_object_attnum_namespace(Oid class_id)
AttrNumber get_object_attnum_name(Oid class_id)
AttrNumber get_object_attnum_acl(Oid class_id)
ObjectType get_object_type(Oid class_id, Oid object_id)
@ OBJECT_SCHEMA
Definition: parsenodes.h:2005
#define ACL_CREATE
Definition: parsenodes.h:92
#define NAMEDATALEN
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
Definition: pg_shdepend.c:313
#define snprintf
Definition: port.h:238
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
static Name DatumGetName(Datum X)
Definition: postgres.h:360
uintptr_t Datum
Definition: postgres.h:64
static Oid DatumGetObjectId(Datum X)
Definition: postgres.h:242
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
#define RelationGetRelid(relation)
Definition: rel.h:501
#define RelationGetDescr(relation)
Definition: rel.h:527
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:507
#define RelationGetRelationName(relation)
Definition: rel.h:535
ItemPointerData t_self
Definition: htup.h:65
bool superuser(void)
Definition: superuser.c:46

References ACL_CREATE, aclcheck_error(), ACLCHECK_NOT_OWNER, ACLCHECK_OK, aclnewowner(), Assert(), CatalogTupleUpdate(), changeDependencyOnOwner(), check_can_set_role(), DatumGetAclP, DatumGetName(), DatumGetObjectId(), elog(), ERROR, get_catalog_object_by_oid(), get_namespace_name(), get_object_attnum_acl(), get_object_attnum_name(), get_object_attnum_namespace(), get_object_attnum_oid(), get_object_attnum_owner(), get_object_type(), GetUserId(), has_privs_of_role(), heap_getattr(), heap_modify_tuple(), InvalidAttrNumber, InvalidOid, InvokeObjectPostAlterHook, NAMEDATALEN, NameStr, object_aclcheck(), OBJECT_SCHEMA, ObjectIdGetDatum(), OidIsValid, palloc0(), pfree(), PointerGetDatum(), RelationGetDescr, RelationGetNumberOfAttributes, RelationGetRelationName, RelationGetRelid, snprintf, superuser(), HeapTupleData::t_self, and values.

Referenced by ExecAlterOwnerStmt(), and shdepReassignOwned().

◆ ExecAlterObjectDependsStmt()

ObjectAddress ExecAlterObjectDependsStmt ( AlterObjectDependsStmt stmt,
ObjectAddress refAddress 
)

Definition at line 435 of file alter.c.

436 {
437  ObjectAddress address;
438  ObjectAddress refAddr;
439  Relation rel;
440 
441  address =
442  get_object_address_rv(stmt->objectType, stmt->relation, (List *) stmt->object,
443  &rel, AccessExclusiveLock, false);
444 
445  /*
446  * Verify that the user is entitled to run the command.
447  *
448  * We don't check any privileges on the extension, because that's not
449  * needed. The object owner is stipulating, by running this command, that
450  * the extension owner can drop the object whenever they feel like it,
451  * which is not considered a problem.
452  */
454  stmt->objectType, address, stmt->object, rel);
455 
456  /*
457  * If a relation was involved, it would have been opened and locked. We
458  * don't need the relation here, but we'll retain the lock until commit.
459  */
460  if (rel)
461  table_close(rel, NoLock);
462 
463  refAddr = get_object_address(OBJECT_EXTENSION, (Node *) stmt->extname,
464  &rel, AccessExclusiveLock, false);
465  Assert(rel == NULL);
466  if (refAddress)
467  *refAddress = refAddr;
468 
469  if (stmt->remove)
470  {
473  refAddr.classId, refAddr.objectId);
474  }
475  else
476  {
477  List *currexts;
478 
479  /* Avoid duplicates */
480  currexts = getAutoExtensionsOfObject(address.classId,
481  address.objectId);
482  if (!list_member_oid(currexts, refAddr.objectId))
483  recordDependencyOn(&address, &refAddr, DEPENDENCY_AUTO_EXTENSION);
484  }
485 
486  return address;
487 }
@ DEPENDENCY_AUTO_EXTENSION
Definition: dependency.h:39
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:721
ObjectAddress get_object_address_rv(ObjectType objtype, RangeVar *rel, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
void check_object_ownership(Oid roleid, ObjectType objtype, ObjectAddress address, Node *object, Relation relation)
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
@ OBJECT_EXTENSION
Definition: parsenodes.h:1984
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:44
List * getAutoExtensionsOfObject(Oid classId, Oid objectId)
Definition: pg_depend.c:777
long deleteDependencyRecordsForSpecific(Oid classId, Oid objectId, char deptype, Oid refclassId, Oid refobjectId)
Definition: pg_depend.c:397
Definition: pg_list.h:54
Definition: nodes.h:129

References AccessExclusiveLock, Assert(), check_object_ownership(), ObjectAddress::classId, deleteDependencyRecordsForSpecific(), DEPENDENCY_AUTO_EXTENSION, AlterObjectDependsStmt::extname, get_object_address(), get_object_address_rv(), getAutoExtensionsOfObject(), GetUserId(), list_member_oid(), NoLock, AlterObjectDependsStmt::object, OBJECT_EXTENSION, ObjectAddress::objectId, AlterObjectDependsStmt::objectType, recordDependencyOn(), AlterObjectDependsStmt::relation, AlterObjectDependsStmt::remove, and table_close().

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

◆ ExecAlterObjectSchemaStmt()

ObjectAddress ExecAlterObjectSchemaStmt ( AlterObjectSchemaStmt stmt,
ObjectAddress oldSchemaAddr 
)

Definition at line 499 of file alter.c.

501 {
502  ObjectAddress address;
503  Oid oldNspOid;
504 
505  switch (stmt->objectType)
506  {
507  case OBJECT_EXTENSION:
508  address = AlterExtensionNamespace(strVal(stmt->object), stmt->newschema,
509  oldSchemaAddr ? &oldNspOid : NULL);
510  break;
511 
513  case OBJECT_SEQUENCE:
514  case OBJECT_TABLE:
515  case OBJECT_VIEW:
516  case OBJECT_MATVIEW:
517  address = AlterTableNamespace(stmt,
518  oldSchemaAddr ? &oldNspOid : NULL);
519  break;
520 
521  case OBJECT_DOMAIN:
522  case OBJECT_TYPE:
523  address = AlterTypeNamespace(castNode(List, stmt->object), stmt->newschema,
524  stmt->objectType,
525  oldSchemaAddr ? &oldNspOid : NULL);
526  break;
527 
528  /* generic code path */
529  case OBJECT_AGGREGATE:
530  case OBJECT_COLLATION:
531  case OBJECT_CONVERSION:
532  case OBJECT_FUNCTION:
533  case OBJECT_OPERATOR:
534  case OBJECT_OPCLASS:
535  case OBJECT_OPFAMILY:
536  case OBJECT_PROCEDURE:
537  case OBJECT_ROUTINE:
540  case OBJECT_TSDICTIONARY:
541  case OBJECT_TSPARSER:
542  case OBJECT_TSTEMPLATE:
543  {
544  Relation catalog;
545  Relation relation;
546  Oid classId;
547  Oid nspOid;
548 
549  address = get_object_address(stmt->objectType,
550  stmt->object,
551  &relation,
553  false);
554  Assert(relation == NULL);
555  classId = address.classId;
556  catalog = table_open(classId, RowExclusiveLock);
557  nspOid = LookupCreationNamespace(stmt->newschema);
558 
559  oldNspOid = AlterObjectNamespace_internal(catalog, address.objectId,
560  nspOid);
561  table_close(catalog, RowExclusiveLock);
562  }
563  break;
564 
565  default:
566  elog(ERROR, "unrecognized AlterObjectSchemaStmt type: %d",
567  (int) stmt->objectType);
568  return InvalidObjectAddress; /* keep compiler happy */
569  }
570 
571  if (oldSchemaAddr)
572  ObjectAddressSet(*oldSchemaAddr, NamespaceRelationId, oldNspOid);
573 
574  return address;
575 }
ObjectAddress AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *oldschema)
Definition: extension.c:2708
Oid LookupCreationNamespace(const char *nspname)
Definition: namespace.c:2979
#define castNode(_type_, nodeptr)
Definition: nodes.h:197
const ObjectAddress InvalidObjectAddress
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
@ OBJECT_TSPARSER
Definition: parsenodes.h:2016
@ OBJECT_COLLATION
Definition: parsenodes.h:1976
@ OBJECT_OPCLASS
Definition: parsenodes.h:1993
@ OBJECT_AGGREGATE
Definition: parsenodes.h:1970
@ OBJECT_MATVIEW
Definition: parsenodes.h:1992
@ OBJECT_OPERATOR
Definition: parsenodes.h:1994
@ OBJECT_FOREIGN_TABLE
Definition: parsenodes.h:1987
@ OBJECT_TSCONFIGURATION
Definition: parsenodes.h:2014
@ OBJECT_OPFAMILY
Definition: parsenodes.h:1995
@ OBJECT_DOMAIN
Definition: parsenodes.h:1981
@ OBJECT_ROUTINE
Definition: parsenodes.h:2003
@ OBJECT_PROCEDURE
Definition: parsenodes.h:1998
@ OBJECT_SEQUENCE
Definition: parsenodes.h:2006
@ OBJECT_TSTEMPLATE
Definition: parsenodes.h:2017
@ OBJECT_TSDICTIONARY
Definition: parsenodes.h:2015
@ OBJECT_CONVERSION
Definition: parsenodes.h:1977
@ OBJECT_TABLE
Definition: parsenodes.h:2010
@ OBJECT_VIEW
Definition: parsenodes.h:2020
@ OBJECT_TYPE
Definition: parsenodes.h:2018
@ OBJECT_FUNCTION
Definition: parsenodes.h:1988
@ OBJECT_STATISTIC_EXT
Definition: parsenodes.h:2008
ObjectAddress AlterTableNamespace(AlterObjectSchemaStmt *stmt, Oid *oldschema)
Definition: tablecmds.c:16310
ObjectAddress AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype, Oid *oldschema)
Definition: typecmds.c:3877
#define strVal(v)
Definition: value.h:82

References AccessExclusiveLock, AlterExtensionNamespace(), AlterObjectNamespace_internal(), AlterTableNamespace(), AlterTypeNamespace(), Assert(), castNode, ObjectAddress::classId, elog(), ERROR, get_object_address(), InvalidObjectAddress, LookupCreationNamespace(), AlterObjectSchemaStmt::newschema, AlterObjectSchemaStmt::object, OBJECT_AGGREGATE, OBJECT_COLLATION, OBJECT_CONVERSION, OBJECT_DOMAIN, OBJECT_EXTENSION, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_PROCEDURE, OBJECT_ROUTINE, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_TABLE, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_VIEW, ObjectAddressSet, ObjectAddress::objectId, AlterObjectSchemaStmt::objectType, RowExclusiveLock, strVal, table_close(), and table_open().

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

◆ ExecAlterOwnerStmt()

ObjectAddress ExecAlterOwnerStmt ( AlterOwnerStmt stmt)

Definition at line 840 of file alter.c.

841 {
842  Oid newowner = get_rolespec_oid(stmt->newowner, false);
843 
844  switch (stmt->objectType)
845  {
846  case OBJECT_DATABASE:
847  return AlterDatabaseOwner(strVal(stmt->object), newowner);
848 
849  case OBJECT_SCHEMA:
850  return AlterSchemaOwner(strVal(stmt->object), newowner);
851 
852  case OBJECT_TYPE:
853  case OBJECT_DOMAIN: /* same as TYPE */
854  return AlterTypeOwner(castNode(List, stmt->object), newowner, stmt->objectType);
855  break;
856 
857  case OBJECT_FDW:
859  newowner);
860 
862  return AlterForeignServerOwner(strVal(stmt->object),
863  newowner);
864 
866  return AlterEventTriggerOwner(strVal(stmt->object),
867  newowner);
868 
869  case OBJECT_PUBLICATION:
870  return AlterPublicationOwner(strVal(stmt->object),
871  newowner);
872 
873  case OBJECT_SUBSCRIPTION:
874  return AlterSubscriptionOwner(strVal(stmt->object),
875  newowner);
876 
877  /* Generic cases */
878  case OBJECT_AGGREGATE:
879  case OBJECT_COLLATION:
880  case OBJECT_CONVERSION:
881  case OBJECT_FUNCTION:
882  case OBJECT_LANGUAGE:
883  case OBJECT_LARGEOBJECT:
884  case OBJECT_OPERATOR:
885  case OBJECT_OPCLASS:
886  case OBJECT_OPFAMILY:
887  case OBJECT_PROCEDURE:
888  case OBJECT_ROUTINE:
890  case OBJECT_TABLESPACE:
891  case OBJECT_TSDICTIONARY:
893  {
894  Relation catalog;
895  Relation relation;
896  Oid classId;
897  ObjectAddress address;
898 
899  address = get_object_address(stmt->objectType,
900  stmt->object,
901  &relation,
903  false);
904  Assert(relation == NULL);
905  classId = address.classId;
906 
907  /*
908  * XXX - get_object_address returns Oid of pg_largeobject
909  * catalog for OBJECT_LARGEOBJECT because of historical
910  * reasons. Fix up it here.
911  */
912  if (classId == LargeObjectRelationId)
913  classId = LargeObjectMetadataRelationId;
914 
915  catalog = table_open(classId, RowExclusiveLock);
916 
917  AlterObjectOwner_internal(catalog, address.objectId, newowner);
918  table_close(catalog, RowExclusiveLock);
919 
920  return address;
921  }
922  break;
923 
924  default:
925  elog(ERROR, "unrecognized AlterOwnerStmt type: %d",
926  (int) stmt->objectType);
927  return InvalidObjectAddress; /* keep compiler happy */
928  }
929 }
Oid get_rolespec_oid(const RoleSpec *role, bool missing_ok)
Definition: acl.c:5289
void AlterObjectOwner_internal(Relation rel, Oid objectId, Oid new_ownerId)
Definition: alter.c:941
ObjectAddress AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
Definition: dbcommands.c:2445
ObjectAddress AlterEventTriggerOwner(const char *name, Oid newOwnerId)
ObjectAddress AlterForeignServerOwner(const char *name, Oid newOwnerId)
Definition: foreigncmds.c:415
ObjectAddress AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId)
Definition: foreigncmds.c:275
@ OBJECT_EVENT_TRIGGER
Definition: parsenodes.h:1983
@ OBJECT_FDW
Definition: parsenodes.h:1985
@ OBJECT_TABLESPACE
Definition: parsenodes.h:2011
@ OBJECT_LARGEOBJECT
Definition: parsenodes.h:1991
@ OBJECT_DATABASE
Definition: parsenodes.h:1978
@ OBJECT_LANGUAGE
Definition: parsenodes.h:1990
@ OBJECT_FOREIGN_SERVER
Definition: parsenodes.h:1986
@ OBJECT_PUBLICATION
Definition: parsenodes.h:1999
@ OBJECT_SUBSCRIPTION
Definition: parsenodes.h:2007
ObjectAddress AlterPublicationOwner(const char *name, Oid newOwnerId)
ObjectAddress AlterSchemaOwner(const char *name, Oid newOwnerId)
Definition: schemacmds.c:312
RoleSpec * newowner
Definition: parsenodes.h:3292
ObjectType objectType
Definition: parsenodes.h:3289
ObjectAddress AlterSubscriptionOwner(const char *name, Oid newOwnerId)
ObjectAddress AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
Definition: typecmds.c:3674

References AccessExclusiveLock, AlterDatabaseOwner(), AlterEventTriggerOwner(), AlterForeignDataWrapperOwner(), AlterForeignServerOwner(), AlterObjectOwner_internal(), AlterPublicationOwner(), AlterSchemaOwner(), AlterSubscriptionOwner(), AlterTypeOwner(), Assert(), castNode, ObjectAddress::classId, elog(), ERROR, get_object_address(), get_rolespec_oid(), InvalidObjectAddress, AlterOwnerStmt::newowner, AlterOwnerStmt::object, OBJECT_AGGREGATE, OBJECT_COLLATION, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DOMAIN, OBJECT_EVENT_TRIGGER, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FUNCTION, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_ROUTINE, OBJECT_SCHEMA, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABLESPACE, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TYPE, ObjectAddress::objectId, AlterOwnerStmt::objectType, RowExclusiveLock, strVal, table_close(), and table_open().

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

◆ ExecRenameStmt()

ObjectAddress ExecRenameStmt ( RenameStmt stmt)

Definition at line 335 of file alter.c.

336 {
337  switch (stmt->renameType)
338  {
341  return RenameConstraint(stmt);
342 
343  case OBJECT_DATABASE:
344  return RenameDatabase(stmt->subname, stmt->newname);
345 
346  case OBJECT_ROLE:
347  return RenameRole(stmt->subname, stmt->newname);
348 
349  case OBJECT_SCHEMA:
350  return RenameSchema(stmt->subname, stmt->newname);
351 
352  case OBJECT_TABLESPACE:
353  return RenameTableSpace(stmt->subname, stmt->newname);
354 
355  case OBJECT_TABLE:
356  case OBJECT_SEQUENCE:
357  case OBJECT_VIEW:
358  case OBJECT_MATVIEW:
359  case OBJECT_INDEX:
361  return RenameRelation(stmt);
362 
363  case OBJECT_COLUMN:
364  case OBJECT_ATTRIBUTE:
365  return renameatt(stmt);
366 
367  case OBJECT_RULE:
368  return RenameRewriteRule(stmt->relation, stmt->subname,
369  stmt->newname);
370 
371  case OBJECT_TRIGGER:
372  return renametrig(stmt);
373 
374  case OBJECT_POLICY:
375  return rename_policy(stmt);
376 
377  case OBJECT_DOMAIN:
378  case OBJECT_TYPE:
379  return RenameType(stmt);
380 
381  case OBJECT_AGGREGATE:
382  case OBJECT_COLLATION:
383  case OBJECT_CONVERSION:
385  case OBJECT_FDW:
387  case OBJECT_FUNCTION:
388  case OBJECT_OPCLASS:
389  case OBJECT_OPFAMILY:
390  case OBJECT_LANGUAGE:
391  case OBJECT_PROCEDURE:
392  case OBJECT_ROUTINE:
395  case OBJECT_TSDICTIONARY:
396  case OBJECT_TSPARSER:
397  case OBJECT_TSTEMPLATE:
398  case OBJECT_PUBLICATION:
399  case OBJECT_SUBSCRIPTION:
400  {
401  ObjectAddress address;
402  Relation catalog;
403  Relation relation;
404 
405  address = get_object_address(stmt->renameType,
406  stmt->object,
407  &relation,
408  AccessExclusiveLock, false);
409  Assert(relation == NULL);
410 
411  catalog = table_open(address.classId, RowExclusiveLock);
413  address.objectId,
414  stmt->newname);
415  table_close(catalog, RowExclusiveLock);
416 
417  return address;
418  }
419 
420  default:
421  elog(ERROR, "unrecognized rename stmt type: %d",
422  (int) stmt->renameType);
423  return InvalidObjectAddress; /* keep compiler happy */
424  }
425 }
static void AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
Definition: alter.c:167
ObjectAddress RenameTableSpace(const char *oldname, const char *newname)
Definition: tablespace.c:936
ObjectAddress RenameDatabase(const char *oldname, const char *newname)
Definition: dbcommands.c:1713
@ OBJECT_POLICY
Definition: parsenodes.h:1997
@ OBJECT_COLUMN
Definition: parsenodes.h:1975
@ OBJECT_ROLE
Definition: parsenodes.h:2002
@ OBJECT_INDEX
Definition: parsenodes.h:1989
@ OBJECT_ATTRIBUTE
Definition: parsenodes.h:1973
@ OBJECT_RULE
Definition: parsenodes.h:2004
@ OBJECT_TABCONSTRAINT
Definition: parsenodes.h:2009
@ OBJECT_DOMCONSTRAINT
Definition: parsenodes.h:1982
@ OBJECT_TRIGGER
Definition: parsenodes.h:2013
ObjectAddress rename_policy(RenameStmt *stmt)
Definition: policy.c:1099
ObjectAddress RenameRewriteRule(RangeVar *relation, const char *oldName, const char *newName)
ObjectAddress RenameSchema(const char *oldname, const char *newname)
Definition: schemacmds.c:231
RangeVar * relation
Definition: parsenodes.h:3245
ObjectType renameType
Definition: parsenodes.h:3243
char * newname
Definition: parsenodes.h:3249
char * subname
Definition: parsenodes.h:3247
Node * object
Definition: parsenodes.h:3246
ObjectAddress RenameRelation(RenameStmt *stmt)
Definition: tablecmds.c:3811
ObjectAddress renameatt(RenameStmt *stmt)
Definition: tablecmds.c:3617
ObjectAddress RenameConstraint(RenameStmt *stmt)
Definition: tablecmds.c:3761
ObjectAddress renametrig(RenameStmt *stmt)
Definition: trigger.c:1473
ObjectAddress RenameType(RenameStmt *stmt)
Definition: typecmds.c:3597
ObjectAddress RenameRole(const char *oldname, const char *newname)
Definition: user.c:1299

References AccessExclusiveLock, AlterObjectRename_internal(), Assert(), ObjectAddress::classId, elog(), ERROR, get_object_address(), InvalidObjectAddress, RenameStmt::newname, RenameStmt::object, OBJECT_AGGREGATE, OBJECT_ATTRIBUTE, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPFAMILY, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PUBLICATION, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_VIEW, ObjectAddress::objectId, RenameStmt::relation, rename_policy(), renameatt(), RenameConstraint(), RenameDatabase(), RenameRelation(), RenameRewriteRule(), RenameRole(), RenameSchema(), RenameTableSpace(), renametrig(), RenameType(), RenameStmt::renameType, RowExclusiveLock, RenameStmt::subname, table_close(), and table_open().

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().