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 (Oid classId, Oid objectId, Oid new_ownerId)
 

Function Documentation

◆ AlterObjectNamespace_oid()

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

Definition at line 608 of file alter.c.

610 {
611  Oid oldNspOid = InvalidOid;
612 
613  switch (classId)
614  {
615  case RelationRelationId:
616  {
617  Relation rel;
618 
619  rel = relation_open(objid, AccessExclusiveLock);
620  oldNspOid = RelationGetNamespace(rel);
621 
622  AlterTableNamespaceInternal(rel, oldNspOid, nspOid, objsMoved);
623 
624  relation_close(rel, NoLock);
625  break;
626  }
627 
628  case TypeRelationId:
629  oldNspOid = AlterTypeNamespace_oid(objid, nspOid, true, objsMoved);
630  break;
631 
632  case ProcedureRelationId:
633  case CollationRelationId:
634  case ConversionRelationId:
635  case OperatorRelationId:
636  case OperatorClassRelationId:
637  case OperatorFamilyRelationId:
638  case StatisticExtRelationId:
639  case TSParserRelationId:
640  case TSDictionaryRelationId:
641  case TSTemplateRelationId:
642  case TSConfigRelationId:
643  {
644  Relation catalog;
645 
646  catalog = table_open(classId, RowExclusiveLock);
647 
648  oldNspOid = AlterObjectNamespace_internal(catalog, objid,
649  nspOid);
650 
651  table_close(catalog, RowExclusiveLock);
652  }
653  break;
654 
655  default:
656  /* ignore object types that don't have schema-qualified names */
658  }
659 
660  return oldNspOid;
661 }
static Oid AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid)
Definition: alter.c:675
#define InvalidAttrNumber
Definition: attnum.h:23
#define Assert(condition)
Definition: c.h:812
#define NoLock
Definition: lockdefs.h:34
#define AccessExclusiveLock
Definition: lockdefs.h:43
#define RowExclusiveLock
Definition: lockdefs.h:38
AttrNumber get_object_attnum_namespace(Oid class_id)
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
#define RelationGetNamespace(relation)
Definition: rel.h:546
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: relation.c:205
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: relation.c:47
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:17780
Oid AlterTypeNamespace_oid(Oid typeOid, Oid nspOid, bool ignoreDependent, ObjectAddresses *objsMoved)
Definition: typecmds.c:4114

References AccessExclusiveLock, AlterObjectNamespace_internal(), AlterTableNamespaceInternal(), AlterTypeNamespace_oid(), Assert, get_object_attnum_namespace(), InvalidAttrNumber, InvalidOid, NoLock, relation_close(), relation_open(), RelationGetNamespace, RowExclusiveLock, table_close(), and table_open().

Referenced by AlterExtensionNamespace().

◆ AlterObjectOwner_internal()

void AlterObjectOwner_internal ( Oid  classId,
Oid  objectId,
Oid  new_ownerId 
)

Definition at line 909 of file alter.c.

910 {
911  /* For large objects, the catalog to modify is pg_largeobject_metadata */
912  Oid catalogId = (classId == LargeObjectRelationId) ? LargeObjectMetadataRelationId : classId;
913  AttrNumber Anum_oid = get_object_attnum_oid(catalogId);
914  AttrNumber Anum_owner = get_object_attnum_owner(catalogId);
915  AttrNumber Anum_namespace = get_object_attnum_namespace(catalogId);
916  AttrNumber Anum_acl = get_object_attnum_acl(catalogId);
917  AttrNumber Anum_name = get_object_attnum_name(catalogId);
918  Relation rel;
919  HeapTuple oldtup;
920  Datum datum;
921  bool isnull;
922  Oid old_ownerId;
923  Oid namespaceId = InvalidOid;
924 
925  rel = table_open(catalogId, RowExclusiveLock);
926 
927  oldtup = get_catalog_object_by_oid(rel, Anum_oid, objectId);
928  if (oldtup == NULL)
929  elog(ERROR, "cache lookup failed for object %u of catalog \"%s\"",
930  objectId, RelationGetRelationName(rel));
931 
932  datum = heap_getattr(oldtup, Anum_owner,
933  RelationGetDescr(rel), &isnull);
934  Assert(!isnull);
935  old_ownerId = DatumGetObjectId(datum);
936 
937  if (Anum_namespace != InvalidAttrNumber)
938  {
939  datum = heap_getattr(oldtup, Anum_namespace,
940  RelationGetDescr(rel), &isnull);
941  Assert(!isnull);
942  namespaceId = DatumGetObjectId(datum);
943  }
944 
945  if (old_ownerId != new_ownerId)
946  {
947  AttrNumber nattrs;
948  HeapTuple newtup;
949  Datum *values;
950  bool *nulls;
951  bool *replaces;
952 
953  /* Superusers can bypass permission checks */
954  if (!superuser())
955  {
956  /* must be owner */
957  if (!has_privs_of_role(GetUserId(), old_ownerId))
958  {
959  char *objname;
960  char namebuf[NAMEDATALEN];
961 
962  if (Anum_name != InvalidAttrNumber)
963  {
964  datum = heap_getattr(oldtup, Anum_name,
965  RelationGetDescr(rel), &isnull);
966  Assert(!isnull);
967  objname = NameStr(*DatumGetName(datum));
968  }
969  else
970  {
971  snprintf(namebuf, sizeof(namebuf), "%u", objectId);
972  objname = namebuf;
973  }
975  get_object_type(catalogId, objectId),
976  objname);
977  }
978  /* Must be able to become new owner */
979  check_can_set_role(GetUserId(), new_ownerId);
980 
981  /* New owner must have CREATE privilege on namespace */
982  if (OidIsValid(namespaceId))
983  {
984  AclResult aclresult;
985 
986  aclresult = object_aclcheck(NamespaceRelationId, namespaceId, new_ownerId,
987  ACL_CREATE);
988  if (aclresult != ACLCHECK_OK)
989  aclcheck_error(aclresult, OBJECT_SCHEMA,
990  get_namespace_name(namespaceId));
991  }
992  }
993 
994  /* Build a modified tuple */
995  nattrs = RelationGetNumberOfAttributes(rel);
996  values = palloc0(nattrs * sizeof(Datum));
997  nulls = palloc0(nattrs * sizeof(bool));
998  replaces = palloc0(nattrs * sizeof(bool));
999  values[Anum_owner - 1] = ObjectIdGetDatum(new_ownerId);
1000  replaces[Anum_owner - 1] = true;
1001 
1002  /*
1003  * Determine the modified ACL for the new owner. This is only
1004  * necessary when the ACL is non-null.
1005  */
1006  if (Anum_acl != InvalidAttrNumber)
1007  {
1008  datum = heap_getattr(oldtup,
1009  Anum_acl, RelationGetDescr(rel), &isnull);
1010  if (!isnull)
1011  {
1012  Acl *newAcl;
1013 
1014  newAcl = aclnewowner(DatumGetAclP(datum),
1015  old_ownerId, new_ownerId);
1016  values[Anum_acl - 1] = PointerGetDatum(newAcl);
1017  replaces[Anum_acl - 1] = true;
1018  }
1019  }
1020 
1021  newtup = heap_modify_tuple(oldtup, RelationGetDescr(rel),
1022  values, nulls, replaces);
1023 
1024  /* Perform actual update */
1025  CatalogTupleUpdate(rel, &newtup->t_self, newtup);
1026 
1027  /* Update owner dependency reference */
1028  changeDependencyOnOwner(classId, objectId, new_ownerId);
1029 
1030  /* Release memory */
1031  pfree(values);
1032  pfree(nulls);
1033  pfree(replaces);
1034  }
1035 
1036  /* Note the post-alter hook gets classId not catalogId */
1037  InvokeObjectPostAlterHook(classId, objectId, 0);
1038 
1040 }
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:5268
Acl * aclnewowner(const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
Definition: acl.c:1103
void check_can_set_role(Oid member, Oid role)
Definition: acl.c:5325
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:2622
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
Definition: aclchk.c:3810
int16 AttrNumber
Definition: attnum.h:21
static Datum values[MAXATTR]
Definition: bootstrap.c:151
#define NameStr(name)
Definition: c.h:700
#define OidIsValid(objectId)
Definition: c.h:729
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)
Definition: heaptuple.c:1209
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:313
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3366
void pfree(void *pointer)
Definition: mcxt.c:1521
void * palloc0(Size size)
Definition: mcxt.c:1347
Oid GetUserId(void)
Definition: miscinit.c:524
#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_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:2304
#define ACL_CREATE
Definition: parsenodes.h:85
#define NAMEDATALEN
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
Definition: pg_shdepend.c:316
#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 RelationGetDescr(relation)
Definition: rel.h:531
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:511
#define RelationGetRelationName(relation)
Definition: rel.h:539
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, RowExclusiveLock, snprintf, superuser(), HeapTupleData::t_self, table_close(), table_open(), and values.

Referenced by ExecAlterOwnerStmt(), and shdepReassignOwned_Owner().

◆ ExecAlterObjectDependsStmt()

ObjectAddress ExecAlterObjectDependsStmt ( AlterObjectDependsStmt stmt,
ObjectAddress refAddress 
)

Definition at line 454 of file alter.c.

455 {
456  ObjectAddress address;
457  ObjectAddress refAddr;
458  Relation rel;
459 
460  address =
461  get_object_address_rv(stmt->objectType, stmt->relation, (List *) stmt->object,
462  &rel, AccessExclusiveLock, false);
463 
464  /*
465  * Verify that the user is entitled to run the command.
466  *
467  * We don't check any privileges on the extension, because that's not
468  * needed. The object owner is stipulating, by running this command, that
469  * the extension owner can drop the object whenever they feel like it,
470  * which is not considered a problem.
471  */
473  stmt->objectType, address, stmt->object, rel);
474 
475  /*
476  * If a relation was involved, it would have been opened and locked. We
477  * don't need the relation here, but we'll retain the lock until commit.
478  */
479  if (rel)
480  table_close(rel, NoLock);
481 
482  refAddr = get_object_address(OBJECT_EXTENSION, (Node *) stmt->extname,
483  NULL, AccessExclusiveLock, false);
484  if (refAddress)
485  *refAddress = refAddr;
486 
487  if (stmt->remove)
488  {
491  refAddr.classId, refAddr.objectId);
492  }
493  else
494  {
495  List *currexts;
496 
497  /* Avoid duplicates */
498  currexts = getAutoExtensionsOfObject(address.classId,
499  address.objectId);
500  if (!list_member_oid(currexts, refAddr.objectId))
501  recordDependencyOn(&address, &refAddr, DEPENDENCY_AUTO_EXTENSION);
502  }
503 
504  return address;
505 }
@ DEPENDENCY_AUTO_EXTENSION
Definition: dependency.h:39
#define stmt
Definition: indent_codes.h:59
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:722
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:2283
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:45
List * getAutoExtensionsOfObject(Oid classId, Oid objectId)
Definition: pg_depend.c:778
long deleteDependencyRecordsForSpecific(Oid classId, Oid objectId, char deptype, Oid refclassId, Oid refobjectId)
Definition: pg_depend.c:398
Definition: pg_list.h:54
Definition: nodes.h:129

References AccessExclusiveLock, check_object_ownership(), ObjectAddress::classId, deleteDependencyRecordsForSpecific(), DEPENDENCY_AUTO_EXTENSION, get_object_address(), get_object_address_rv(), getAutoExtensionsOfObject(), GetUserId(), list_member_oid(), NoLock, OBJECT_EXTENSION, ObjectAddress::objectId, recordDependencyOn(), stmt, and table_close().

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

◆ ExecAlterObjectSchemaStmt()

ObjectAddress ExecAlterObjectSchemaStmt ( AlterObjectSchemaStmt stmt,
ObjectAddress oldSchemaAddr 
)

Definition at line 517 of file alter.c.

519 {
520  ObjectAddress address;
521  Oid oldNspOid;
522 
523  switch (stmt->objectType)
524  {
525  case OBJECT_EXTENSION:
526  address = AlterExtensionNamespace(strVal(stmt->object), stmt->newschema,
527  oldSchemaAddr ? &oldNspOid : NULL);
528  break;
529 
531  case OBJECT_SEQUENCE:
532  case OBJECT_TABLE:
533  case OBJECT_VIEW:
534  case OBJECT_MATVIEW:
535  address = AlterTableNamespace(stmt,
536  oldSchemaAddr ? &oldNspOid : NULL);
537  break;
538 
539  case OBJECT_DOMAIN:
540  case OBJECT_TYPE:
541  address = AlterTypeNamespace(castNode(List, stmt->object), stmt->newschema,
542  stmt->objectType,
543  oldSchemaAddr ? &oldNspOid : NULL);
544  break;
545 
546  /* generic code path */
547  case OBJECT_AGGREGATE:
548  case OBJECT_COLLATION:
549  case OBJECT_CONVERSION:
550  case OBJECT_FUNCTION:
551  case OBJECT_OPERATOR:
552  case OBJECT_OPCLASS:
553  case OBJECT_OPFAMILY:
554  case OBJECT_PROCEDURE:
555  case OBJECT_ROUTINE:
558  case OBJECT_TSDICTIONARY:
559  case OBJECT_TSPARSER:
560  case OBJECT_TSTEMPLATE:
561  {
562  Relation catalog;
563  Oid classId;
564  Oid nspOid;
565 
566  address = get_object_address(stmt->objectType,
567  stmt->object,
568  NULL,
570  false);
571  classId = address.classId;
572  catalog = table_open(classId, RowExclusiveLock);
573  nspOid = LookupCreationNamespace(stmt->newschema);
574 
575  oldNspOid = AlterObjectNamespace_internal(catalog, address.objectId,
576  nspOid);
577  table_close(catalog, RowExclusiveLock);
578  }
579  break;
580 
581  default:
582  elog(ERROR, "unrecognized AlterObjectSchemaStmt type: %d",
583  (int) stmt->objectType);
584  return InvalidObjectAddress; /* keep compiler happy */
585  }
586 
587  if (oldSchemaAddr)
588  ObjectAddressSet(*oldSchemaAddr, NamespaceRelationId, oldNspOid);
589 
590  return address;
591 }
ObjectAddress AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *oldschema)
Definition: extension.c:2883
Oid LookupCreationNamespace(const char *nspname)
Definition: namespace.c:3428
#define castNode(_type_, nodeptr)
Definition: nodes.h:176
const ObjectAddress InvalidObjectAddress
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
@ OBJECT_TSPARSER
Definition: parsenodes.h:2315
@ OBJECT_COLLATION
Definition: parsenodes.h:2275
@ OBJECT_OPCLASS
Definition: parsenodes.h:2292
@ OBJECT_AGGREGATE
Definition: parsenodes.h:2269
@ OBJECT_MATVIEW
Definition: parsenodes.h:2291
@ OBJECT_OPERATOR
Definition: parsenodes.h:2293
@ OBJECT_FOREIGN_TABLE
Definition: parsenodes.h:2286
@ OBJECT_TSCONFIGURATION
Definition: parsenodes.h:2313
@ OBJECT_OPFAMILY
Definition: parsenodes.h:2294
@ OBJECT_DOMAIN
Definition: parsenodes.h:2280
@ OBJECT_ROUTINE
Definition: parsenodes.h:2302
@ OBJECT_PROCEDURE
Definition: parsenodes.h:2297
@ OBJECT_SEQUENCE
Definition: parsenodes.h:2305
@ OBJECT_TSTEMPLATE
Definition: parsenodes.h:2316
@ OBJECT_TSDICTIONARY
Definition: parsenodes.h:2314
@ OBJECT_CONVERSION
Definition: parsenodes.h:2276
@ OBJECT_TABLE
Definition: parsenodes.h:2309
@ OBJECT_VIEW
Definition: parsenodes.h:2319
@ OBJECT_TYPE
Definition: parsenodes.h:2317
@ OBJECT_FUNCTION
Definition: parsenodes.h:2287
@ OBJECT_STATISTIC_EXT
Definition: parsenodes.h:2307
ObjectAddress AlterTableNamespace(AlterObjectSchemaStmt *stmt, Oid *oldschema)
Definition: tablecmds.c:17709
ObjectAddress AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype, Oid *oldschema)
Definition: typecmds.c:4065
#define strVal(v)
Definition: value.h:82

References AccessExclusiveLock, AlterExtensionNamespace(), AlterObjectNamespace_internal(), AlterTableNamespace(), AlterTypeNamespace(), castNode, ObjectAddress::classId, elog, ERROR, get_object_address(), InvalidObjectAddress, LookupCreationNamespace(), 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, RowExclusiveLock, stmt, strVal, table_close(), and table_open().

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

◆ ExecAlterOwnerStmt()

ObjectAddress ExecAlterOwnerStmt ( AlterOwnerStmt stmt)

Definition at line 820 of file alter.c.

821 {
822  Oid newowner = get_rolespec_oid(stmt->newowner, false);
823 
824  switch (stmt->objectType)
825  {
826  case OBJECT_DATABASE:
827  return AlterDatabaseOwner(strVal(stmt->object), newowner);
828 
829  case OBJECT_SCHEMA:
830  return AlterSchemaOwner(strVal(stmt->object), newowner);
831 
832  case OBJECT_TYPE:
833  case OBJECT_DOMAIN: /* same as TYPE */
834  return AlterTypeOwner(castNode(List, stmt->object), newowner, stmt->objectType);
835  break;
836 
837  case OBJECT_FDW:
838  return AlterForeignDataWrapperOwner(strVal(stmt->object),
839  newowner);
840 
842  return AlterForeignServerOwner(strVal(stmt->object),
843  newowner);
844 
846  return AlterEventTriggerOwner(strVal(stmt->object),
847  newowner);
848 
849  case OBJECT_PUBLICATION:
850  return AlterPublicationOwner(strVal(stmt->object),
851  newowner);
852 
853  case OBJECT_SUBSCRIPTION:
854  return AlterSubscriptionOwner(strVal(stmt->object),
855  newowner);
856 
857  /* Generic cases */
858  case OBJECT_AGGREGATE:
859  case OBJECT_COLLATION:
860  case OBJECT_CONVERSION:
861  case OBJECT_FUNCTION:
862  case OBJECT_LANGUAGE:
863  case OBJECT_LARGEOBJECT:
864  case OBJECT_OPERATOR:
865  case OBJECT_OPCLASS:
866  case OBJECT_OPFAMILY:
867  case OBJECT_PROCEDURE:
868  case OBJECT_ROUTINE:
870  case OBJECT_TABLESPACE:
871  case OBJECT_TSDICTIONARY:
873  {
874  ObjectAddress address;
875 
876  address = get_object_address(stmt->objectType,
877  stmt->object,
878  NULL,
880  false);
881 
882  AlterObjectOwner_internal(address.classId, address.objectId,
883  newowner);
884 
885  return address;
886  }
887  break;
888 
889  default:
890  elog(ERROR, "unrecognized AlterOwnerStmt type: %d",
891  (int) stmt->objectType);
892  return InvalidObjectAddress; /* keep compiler happy */
893  }
894 }
Oid get_rolespec_oid(const RoleSpec *role, bool missing_ok)
Definition: acl.c:5588
void AlterObjectOwner_internal(Oid classId, Oid objectId, Oid new_ownerId)
Definition: alter.c:909
ObjectAddress AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
Definition: dbcommands.c:2637
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:2282
@ OBJECT_FDW
Definition: parsenodes.h:2284
@ OBJECT_TABLESPACE
Definition: parsenodes.h:2310
@ OBJECT_LARGEOBJECT
Definition: parsenodes.h:2290
@ OBJECT_DATABASE
Definition: parsenodes.h:2277
@ OBJECT_LANGUAGE
Definition: parsenodes.h:2289
@ OBJECT_FOREIGN_SERVER
Definition: parsenodes.h:2285
@ OBJECT_PUBLICATION
Definition: parsenodes.h:2298
@ OBJECT_SUBSCRIPTION
Definition: parsenodes.h:2306
ObjectAddress AlterPublicationOwner(const char *name, Oid newOwnerId)
ObjectAddress AlterSchemaOwner(const char *name, Oid newOwnerId)
Definition: schemacmds.c:330
ObjectAddress AlterSubscriptionOwner(const char *name, Oid newOwnerId)
ObjectAddress AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
Definition: typecmds.c:3832

References AccessExclusiveLock, AlterDatabaseOwner(), AlterEventTriggerOwner(), AlterForeignDataWrapperOwner(), AlterForeignServerOwner(), AlterObjectOwner_internal(), AlterPublicationOwner(), AlterSchemaOwner(), AlterSubscriptionOwner(), AlterTypeOwner(), castNode, ObjectAddress::classId, elog, ERROR, get_object_address(), get_rolespec_oid(), InvalidObjectAddress, 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, stmt, and strVal.

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

◆ ExecRenameStmt()

ObjectAddress ExecRenameStmt ( RenameStmt stmt)

Definition at line 356 of file alter.c.

357 {
358  switch (stmt->renameType)
359  {
362  return RenameConstraint(stmt);
363 
364  case OBJECT_DATABASE:
365  return RenameDatabase(stmt->subname, stmt->newname);
366 
367  case OBJECT_ROLE:
368  return RenameRole(stmt->subname, stmt->newname);
369 
370  case OBJECT_SCHEMA:
371  return RenameSchema(stmt->subname, stmt->newname);
372 
373  case OBJECT_TABLESPACE:
374  return RenameTableSpace(stmt->subname, stmt->newname);
375 
376  case OBJECT_TABLE:
377  case OBJECT_SEQUENCE:
378  case OBJECT_VIEW:
379  case OBJECT_MATVIEW:
380  case OBJECT_INDEX:
382  return RenameRelation(stmt);
383 
384  case OBJECT_COLUMN:
385  case OBJECT_ATTRIBUTE:
386  return renameatt(stmt);
387 
388  case OBJECT_RULE:
389  return RenameRewriteRule(stmt->relation, stmt->subname,
390  stmt->newname);
391 
392  case OBJECT_TRIGGER:
393  return renametrig(stmt);
394 
395  case OBJECT_POLICY:
396  return rename_policy(stmt);
397 
398  case OBJECT_DOMAIN:
399  case OBJECT_TYPE:
400  return RenameType(stmt);
401 
402  case OBJECT_AGGREGATE:
403  case OBJECT_COLLATION:
404  case OBJECT_CONVERSION:
406  case OBJECT_FDW:
408  case OBJECT_FUNCTION:
409  case OBJECT_OPCLASS:
410  case OBJECT_OPFAMILY:
411  case OBJECT_LANGUAGE:
412  case OBJECT_PROCEDURE:
413  case OBJECT_ROUTINE:
416  case OBJECT_TSDICTIONARY:
417  case OBJECT_TSPARSER:
418  case OBJECT_TSTEMPLATE:
419  case OBJECT_PUBLICATION:
420  case OBJECT_SUBSCRIPTION:
421  {
422  ObjectAddress address;
423  Relation catalog;
424 
425  address = get_object_address(stmt->renameType,
426  stmt->object,
427  NULL,
428  AccessExclusiveLock, false);
429 
430  catalog = table_open(address.classId, RowExclusiveLock);
432  address.objectId,
433  stmt->newname);
434  table_close(catalog, RowExclusiveLock);
435 
436  return address;
437  }
438 
439  default:
440  elog(ERROR, "unrecognized rename stmt type: %d",
441  (int) stmt->renameType);
442  return InvalidObjectAddress; /* keep compiler happy */
443  }
444 }
static void AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
Definition: alter.c:164
ObjectAddress RenameTableSpace(const char *oldname, const char *newname)
Definition: tablespace.c:930
ObjectAddress RenameDatabase(const char *oldname, const char *newname)
Definition: dbcommands.c:1876
@ OBJECT_POLICY
Definition: parsenodes.h:2296
@ OBJECT_COLUMN
Definition: parsenodes.h:2274
@ OBJECT_ROLE
Definition: parsenodes.h:2301
@ OBJECT_INDEX
Definition: parsenodes.h:2288
@ OBJECT_ATTRIBUTE
Definition: parsenodes.h:2272
@ OBJECT_RULE
Definition: parsenodes.h:2303
@ OBJECT_TABCONSTRAINT
Definition: parsenodes.h:2308
@ OBJECT_DOMCONSTRAINT
Definition: parsenodes.h:2281
@ OBJECT_TRIGGER
Definition: parsenodes.h:2312
ObjectAddress rename_policy(RenameStmt *stmt)
Definition: policy.c:1096
ObjectAddress RenameRewriteRule(RangeVar *relation, const char *oldName, const char *newName)
ObjectAddress RenameSchema(const char *oldname, const char *newname)
Definition: schemacmds.c:249
ObjectAddress RenameRelation(RenameStmt *stmt)
Definition: tablecmds.c:4119
ObjectAddress renameatt(RenameStmt *stmt)
Definition: tablecmds.c:3922
ObjectAddress RenameConstraint(RenameStmt *stmt)
Definition: tablecmds.c:4069
ObjectAddress renametrig(RenameStmt *stmt)
Definition: trigger.c:1463
ObjectAddress RenameType(RenameStmt *stmt)
Definition: typecmds.c:3751
ObjectAddress RenameRole(const char *oldname, const char *newname)
Definition: user.c:1334

References AccessExclusiveLock, AlterObjectRename_internal(), ObjectAddress::classId, elog, ERROR, get_object_address(), InvalidObjectAddress, 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, rename_policy(), renameatt(), RenameConstraint(), RenameDatabase(), RenameRelation(), RenameRewriteRule(), RenameRole(), RenameSchema(), RenameTableSpace(), renametrig(), RenameType(), RowExclusiveLock, stmt, table_close(), and table_open().

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().