PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 catalog, Oid objectId, Oid new_ownerId)
 

Function Documentation

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

Definition at line 552 of file alter.c.

References AccessExclusiveLock, AlterObjectNamespace_internal(), AlterTableNamespaceInternal(), AlterTypeNamespace_oid(), ObjectAddress::classId, getObjectClass(), heap_close, heap_open(), InvalidOid, NoLock, ObjectAddress::objectId, ObjectAddress::objectSubId, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONVERSION, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_PROC, OCLASS_TSCONFIG, OCLASS_TSDICT, OCLASS_TSPARSER, OCLASS_TSTEMPLATE, OCLASS_TYPE, relation_close(), relation_open(), RelationGetNamespace, and RowExclusiveLock.

Referenced by AlterExtensionNamespace().

554 {
555  Oid oldNspOid = InvalidOid;
556  ObjectAddress dep;
557 
558  dep.classId = classId;
559  dep.objectId = objid;
560  dep.objectSubId = 0;
561 
562  switch (getObjectClass(&dep))
563  {
564  case OCLASS_CLASS:
565  {
566  Relation rel;
567 
568  rel = relation_open(objid, AccessExclusiveLock);
569  oldNspOid = RelationGetNamespace(rel);
570 
571  AlterTableNamespaceInternal(rel, oldNspOid, nspOid, objsMoved);
572 
573  relation_close(rel, NoLock);
574  break;
575  }
576 
577  case OCLASS_TYPE:
578  oldNspOid = AlterTypeNamespace_oid(objid, nspOid, objsMoved);
579  break;
580 
581  case OCLASS_COLLATION:
582  case OCLASS_CONVERSION:
583  case OCLASS_OPERATOR:
584  case OCLASS_OPCLASS:
585  case OCLASS_OPFAMILY:
586  case OCLASS_PROC:
587  case OCLASS_TSPARSER:
588  case OCLASS_TSDICT:
589  case OCLASS_TSTEMPLATE:
590  case OCLASS_TSCONFIG:
591  {
592  Relation catalog;
593 
594  catalog = heap_open(classId, RowExclusiveLock);
595 
596  oldNspOid = AlterObjectNamespace_internal(catalog, objid,
597  nspOid);
598 
599  heap_close(catalog, RowExclusiveLock);
600  }
601  break;
602 
603  default:
604  break;
605  }
606 
607  return oldNspOid;
608 }
static Oid AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid)
Definition: alter.c:622
void relation_close(Relation relation, LOCKMODE lockmode)
Definition: heapam.c:1260
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2325
void AlterTableNamespaceInternal(Relation rel, Oid oldNspOid, Oid nspOid, ObjectAddresses *objsMoved)
Definition: tablecmds.c:12484
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
Oid AlterTypeNamespace_oid(Oid typeOid, Oid nspOid, ObjectAddresses *objsMoved)
Definition: typecmds.c:3453
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define InvalidOid
Definition: postgres_ext.h:36
#define AccessExclusiveLock
Definition: lockdefs.h:46
Relation relation_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1114
#define RelationGetNamespace(relation)
Definition: rel.h:444
void AlterObjectOwner_internal ( Relation  catalog,
Oid  objectId,
Oid  new_ownerId 
)

Definition at line 865 of file alter.c.

References ACL_CREATE, ACL_KIND_NAMESPACE, aclcheck_error(), ACLCHECK_NOT_OWNER, ACLCHECK_OK, aclnewowner(), Assert, CatalogTupleUpdate(), changeDependencyOnOwner(), check_is_member_of_role(), DatumGetAclP, DatumGetName, DatumGetObjectId, elog, ERROR, get_catalog_object_by_oid(), get_namespace_name(), get_object_aclkind(), get_object_attnum_acl(), get_object_attnum_name(), get_object_attnum_namespace(), get_object_attnum_owner(), GetUserId(), has_privs_of_role(), heap_getattr, heap_modify_tuple(), HeapTupleGetOid, InvalidAttrNumber, InvalidOid, InvokeObjectPostAlterHook, LargeObjectMetadataRelationId, LargeObjectRelationId, NAMEDATALEN, NameStr, NULL, ObjectIdGetDatum, OidIsValid, palloc0(), pfree(), pg_namespace_aclcheck(), PointerGetDatum, RelationGetDescr, RelationGetNumberOfAttributes, RelationGetRelationName, RelationGetRelid, snprintf(), superuser(), HeapTupleData::t_self, and values.

Referenced by ExecAlterOwnerStmt(), and shdepReassignOwned().

866 {
867  Oid classId = RelationGetRelid(rel);
868  AttrNumber Anum_owner = get_object_attnum_owner(classId);
869  AttrNumber Anum_namespace = get_object_attnum_namespace(classId);
870  AttrNumber Anum_acl = get_object_attnum_acl(classId);
871  AttrNumber Anum_name = get_object_attnum_name(classId);
872  HeapTuple oldtup;
873  Datum datum;
874  bool isnull;
875  Oid old_ownerId;
876  Oid namespaceId = InvalidOid;
877 
878  oldtup = get_catalog_object_by_oid(rel, objectId);
879  if (oldtup == NULL)
880  elog(ERROR, "cache lookup failed for object %u of catalog \"%s\"",
881  objectId, RelationGetRelationName(rel));
882 
883  datum = heap_getattr(oldtup, Anum_owner,
884  RelationGetDescr(rel), &isnull);
885  Assert(!isnull);
886  old_ownerId = DatumGetObjectId(datum);
887 
888  if (Anum_namespace != InvalidAttrNumber)
889  {
890  datum = heap_getattr(oldtup, Anum_namespace,
891  RelationGetDescr(rel), &isnull);
892  Assert(!isnull);
893  namespaceId = DatumGetObjectId(datum);
894  }
895 
896  if (old_ownerId != new_ownerId)
897  {
898  AttrNumber nattrs;
899  HeapTuple newtup;
900  Datum *values;
901  bool *nulls;
902  bool *replaces;
903 
904  /* Superusers can bypass permission checks */
905  if (!superuser())
906  {
907  AclObjectKind aclkind = get_object_aclkind(classId);
908 
909  /* must be owner */
910  if (!has_privs_of_role(GetUserId(), old_ownerId))
911  {
912  char *objname;
913  char namebuf[NAMEDATALEN];
914 
915  if (Anum_name != InvalidAttrNumber)
916  {
917  datum = heap_getattr(oldtup, Anum_name,
918  RelationGetDescr(rel), &isnull);
919  Assert(!isnull);
920  objname = NameStr(*DatumGetName(datum));
921  }
922  else
923  {
924  snprintf(namebuf, sizeof(namebuf), "%u",
925  HeapTupleGetOid(oldtup));
926  objname = namebuf;
927  }
928  aclcheck_error(ACLCHECK_NOT_OWNER, aclkind, objname);
929  }
930  /* Must be able to become new owner */
931  check_is_member_of_role(GetUserId(), new_ownerId);
932 
933  /* New owner must have CREATE privilege on namespace */
934  if (OidIsValid(namespaceId))
935  {
936  AclResult aclresult;
937 
938  aclresult = pg_namespace_aclcheck(namespaceId, new_ownerId,
939  ACL_CREATE);
940  if (aclresult != ACLCHECK_OK)
942  get_namespace_name(namespaceId));
943  }
944  }
945 
946  /* Build a modified tuple */
947  nattrs = RelationGetNumberOfAttributes(rel);
948  values = palloc0(nattrs * sizeof(Datum));
949  nulls = palloc0(nattrs * sizeof(bool));
950  replaces = palloc0(nattrs * sizeof(bool));
951  values[Anum_owner - 1] = ObjectIdGetDatum(new_ownerId);
952  replaces[Anum_owner - 1] = true;
953 
954  /*
955  * Determine the modified ACL for the new owner. This is only
956  * necessary when the ACL is non-null.
957  */
958  if (Anum_acl != InvalidAttrNumber)
959  {
960  datum = heap_getattr(oldtup,
961  Anum_acl, RelationGetDescr(rel), &isnull);
962  if (!isnull)
963  {
964  Acl *newAcl;
965 
966  newAcl = aclnewowner(DatumGetAclP(datum),
967  old_ownerId, new_ownerId);
968  values[Anum_acl - 1] = PointerGetDatum(newAcl);
969  replaces[Anum_acl - 1] = true;
970  }
971  }
972 
973  newtup = heap_modify_tuple(oldtup, RelationGetDescr(rel),
974  values, nulls, replaces);
975 
976  /* Perform actual update */
977  CatalogTupleUpdate(rel, &newtup->t_self, newtup);
978 
979  /* Update owner dependency reference */
980  if (classId == LargeObjectMetadataRelationId)
981  classId = LargeObjectRelationId;
982  changeDependencyOnOwner(classId, HeapTupleGetOid(newtup), new_ownerId);
983 
984  /* Release memory */
985  pfree(values);
986  pfree(nulls);
987  pfree(replaces);
988  }
989 
990  InvokeObjectPostAlterHook(classId, objectId, 0);
991 }
AttrNumber get_object_attnum_owner(Oid class_id)
#define RelationGetDescr(relation)
Definition: rel.h:429
Oid GetUserId(void)
Definition: miscinit.c:283
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:423
#define DatumGetAclP(X)
Definition: acl.h:113
#define PointerGetDatum(X)
Definition: postgres.h:562
#define DatumGetObjectId(X)
Definition: postgres.h:506
bool has_privs_of_role(Oid member, Oid role)
Definition: acl.c:4813
bool superuser(void)
Definition: superuser.c:47
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
AttrNumber get_object_attnum_namespace(Oid class_id)
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:538
AclResult pg_namespace_aclcheck(Oid nsp_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4484
#define NAMEDATALEN
#define DatumGetName(X)
Definition: postgres.h:591
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
Definition: pg_shdepend.c:304
void pfree(void *pointer)
Definition: mcxt.c:950
AclObjectKind get_object_aclkind(Oid class_id)
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
#define ERROR
Definition: elog.h:43
#define ACL_CREATE
Definition: parsenodes.h:82
ItemPointerData t_self
Definition: htup.h:65
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3038
AttrNumber get_object_attnum_acl(Oid class_id)
void aclcheck_error(AclResult aclerr, AclObjectKind objectkind, const char *objectname)
Definition: aclchk.c:3399
#define RelationGetRelationName(relation)
Definition: rel.h:437
void check_is_member_of_role(Oid member, Oid role)
Definition: acl.c:4859
#define InvokeObjectPostAlterHook(classId, objectId, subId)
Definition: objectaccess.h:163
#define heap_getattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:769
AttrNumber get_object_attnum_name(Oid class_id)
void * palloc0(Size size)
Definition: mcxt.c:878
AclResult
Definition: acl.h:170
uintptr_t Datum
Definition: postgres.h:372
#define InvalidOid
Definition: postgres_ext.h:36
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define LargeObjectMetadataRelationId
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:210
HeapTuple get_catalog_object_by_oid(Relation catalog, Oid objectId)
#define InvalidAttrNumber
Definition: attnum.h:23
static Datum values[MAXATTR]
Definition: bootstrap.c:163
#define NameStr(name)
Definition: c.h:499
#define elog
Definition: elog.h:219
AclObjectKind
Definition: acl.h:179
#define HeapTupleGetOid(tuple)
Definition: htup_details.h:695
HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *replValues, bool *replIsnull, bool *doReplace)
Definition: heaptuple.c:793
#define LargeObjectRelationId
Acl * aclnewowner(const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
Definition: acl.c:1035
int16 AttrNumber
Definition: attnum.h:21
#define RelationGetRelid(relation)
Definition: rel.h:417
ObjectAddress ExecAlterObjectDependsStmt ( AlterObjectDependsStmt stmt,
ObjectAddress refAddress 
)

Definition at line 423 of file alter.c.

References AccessExclusiveLock, Assert, DEPENDENCY_AUTO_EXTENSION, AlterObjectDependsStmt::extname, get_object_address(), get_object_address_rv(), heap_close, NoLock, NULL, AlterObjectDependsStmt::object, OBJECT_EXTENSION, AlterObjectDependsStmt::objectType, recordDependencyOn(), and AlterObjectDependsStmt::relation.

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

424 {
425  ObjectAddress address;
426  ObjectAddress refAddr;
427  Relation rel;
428 
429  address =
430  get_object_address_rv(stmt->objectType, stmt->relation, (List *) stmt->object,
431  &rel, AccessExclusiveLock, false);
432 
433  /*
434  * If a relation was involved, it would have been opened and locked. We
435  * don't need the relation here, but we'll retain the lock until commit.
436  */
437  if (rel)
438  heap_close(rel, NoLock);
439 
440  refAddr = get_object_address(OBJECT_EXTENSION, (Node *) stmt->extname,
441  &rel, AccessExclusiveLock, false);
442  Assert(rel == NULL);
443  if (refAddress)
444  *refAddress = refAddr;
445 
446  recordDependencyOn(&address, &refAddr, DEPENDENCY_AUTO_EXTENSION);
447 
448  return address;
449 }
Definition: nodes.h:509
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:44
#define heap_close(r, l)
Definition: heapam.h:97
#define NoLock
Definition: lockdefs.h:34
ObjectAddress get_object_address_rv(ObjectType objtype, RangeVar *rel, List *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
#define AccessExclusiveLock
Definition: lockdefs.h:46
Definition: pg_list.h:45
ObjectAddress ExecAlterObjectSchemaStmt ( AlterObjectSchemaStmt stmt,
ObjectAddress oldSchemaAddr 
)

Definition at line 461 of file alter.c.

References AccessExclusiveLock, AlterExtensionNamespace(), AlterObjectNamespace_internal(), AlterTableNamespace(), AlterTypeNamespace(), Assert, castNode, ObjectAddress::classId, elog, ERROR, get_object_address(), heap_close, heap_open(), InvalidObjectAddress, LookupCreationNamespace(), NamespaceRelationId, AlterObjectSchemaStmt::newschema, NULL, 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_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_TABLE, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_VIEW, ObjectAddressSet, ObjectAddress::objectId, AlterObjectSchemaStmt::objectType, RowExclusiveLock, and strVal.

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

463 {
464  ObjectAddress address;
465  Oid oldNspOid;
466 
467  switch (stmt->objectType)
468  {
469  case OBJECT_EXTENSION:
470  address = AlterExtensionNamespace(strVal((Value *) stmt->object), stmt->newschema,
471  oldSchemaAddr ? &oldNspOid : NULL);
472  break;
473 
475  case OBJECT_SEQUENCE:
476  case OBJECT_TABLE:
477  case OBJECT_VIEW:
478  case OBJECT_MATVIEW:
479  address = AlterTableNamespace(stmt,
480  oldSchemaAddr ? &oldNspOid : NULL);
481  break;
482 
483  case OBJECT_DOMAIN:
484  case OBJECT_TYPE:
485  address = AlterTypeNamespace(castNode(List, stmt->object), stmt->newschema,
486  stmt->objectType,
487  oldSchemaAddr ? &oldNspOid : NULL);
488  break;
489 
490  /* generic code path */
491  case OBJECT_AGGREGATE:
492  case OBJECT_COLLATION:
493  case OBJECT_CONVERSION:
494  case OBJECT_FUNCTION:
495  case OBJECT_OPERATOR:
496  case OBJECT_OPCLASS:
497  case OBJECT_OPFAMILY:
500  case OBJECT_TSDICTIONARY:
501  case OBJECT_TSPARSER:
502  case OBJECT_TSTEMPLATE:
503  {
504  Relation catalog;
505  Relation relation;
506  Oid classId;
507  Oid nspOid;
508 
509  address = get_object_address(stmt->objectType,
510  stmt->object,
511  &relation,
513  false);
514  Assert(relation == NULL);
515  classId = address.classId;
516  catalog = heap_open(classId, RowExclusiveLock);
517  nspOid = LookupCreationNamespace(stmt->newschema);
518 
519  oldNspOid = AlterObjectNamespace_internal(catalog, address.objectId,
520  nspOid);
521  heap_close(catalog, RowExclusiveLock);
522  }
523  break;
524 
525  default:
526  elog(ERROR, "unrecognized AlterObjectSchemaStmt type: %d",
527  (int) stmt->objectType);
528  return InvalidObjectAddress; /* keep compiler happy */
529  }
530 
531  if (oldSchemaAddr)
532  ObjectAddressSet(*oldSchemaAddr, NamespaceRelationId, oldNspOid);
533 
534  return address;
535 }
#define NamespaceRelationId
Definition: pg_namespace.h:34
#define castNode(_type_, nodeptr)
Definition: nodes.h:578
Oid LookupCreationNamespace(const char *nspname)
Definition: namespace.c:2786
ObjectAddress AlterTypeNamespace(List *names, const char *newschema, ObjectType objecttype, Oid *oldschema)
Definition: typecmds.c:3416
#define strVal(v)
Definition: value.h:54
static Oid AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid)
Definition: alter.c:622
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
ObjectAddress AlterTableNamespace(AlterObjectSchemaStmt *stmt, Oid *oldschema)
Definition: tablecmds.c:12413
#define ERROR
Definition: elog.h:43
#define RowExclusiveLock
Definition: lockdefs.h:38
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
Definition: value.h:42
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
#define AccessExclusiveLock
Definition: lockdefs.h:46
const ObjectAddress InvalidObjectAddress
#define elog
Definition: elog.h:219
Definition: pg_list.h:45
ObjectAddress AlterExtensionNamespace(const char *extensionName, const char *newschema, Oid *oldschema)
Definition: extension.c:2677
ObjectAddress ExecAlterOwnerStmt ( AlterOwnerStmt stmt)

Definition at line 766 of file alter.c.

References AccessExclusiveLock, AlterDatabaseOwner(), AlterEventTriggerOwner(), AlterForeignDataWrapperOwner(), AlterForeignServerOwner(), AlterObjectOwner_internal(), AlterPublicationOwner(), AlterSchemaOwner(), AlterSubscriptionOwner(), AlterTypeOwner(), Assert, castNode, ObjectAddress::classId, elog, ERROR, get_object_address(), get_rolespec_oid(), heap_close, heap_open(), InvalidObjectAddress, LargeObjectMetadataRelationId, LargeObjectRelationId, AlterOwnerStmt::newowner, NULL, 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_PUBLICATION, OBJECT_SCHEMA, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABLESPACE, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TYPE, ObjectAddress::objectId, AlterOwnerStmt::objectType, RowExclusiveLock, and strVal.

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

767 {
768  Oid newowner = get_rolespec_oid(stmt->newowner, false);
769 
770  switch (stmt->objectType)
771  {
772  case OBJECT_DATABASE:
773  return AlterDatabaseOwner(strVal((Value *) stmt->object), newowner);
774 
775  case OBJECT_SCHEMA:
776  return AlterSchemaOwner(strVal((Value *) stmt->object), newowner);
777 
778  case OBJECT_TYPE:
779  case OBJECT_DOMAIN: /* same as TYPE */
780  return AlterTypeOwner(castNode(List, stmt->object), newowner, stmt->objectType);
781  break;
782 
783  case OBJECT_FDW:
785  newowner);
786 
788  return AlterForeignServerOwner(strVal((Value *) stmt->object),
789  newowner);
790 
792  return AlterEventTriggerOwner(strVal((Value *) stmt->object),
793  newowner);
794 
795  case OBJECT_PUBLICATION:
796  return AlterPublicationOwner(strVal((Value *) stmt->object),
797  newowner);
798 
799  case OBJECT_SUBSCRIPTION:
800  return AlterSubscriptionOwner(strVal((Value *) stmt->object),
801  newowner);
802 
803  /* Generic cases */
804  case OBJECT_AGGREGATE:
805  case OBJECT_COLLATION:
806  case OBJECT_CONVERSION:
807  case OBJECT_FUNCTION:
808  case OBJECT_LANGUAGE:
809  case OBJECT_LARGEOBJECT:
810  case OBJECT_OPERATOR:
811  case OBJECT_OPCLASS:
812  case OBJECT_OPFAMILY:
814  case OBJECT_TABLESPACE:
815  case OBJECT_TSDICTIONARY:
817  {
818  Relation catalog;
819  Relation relation;
820  Oid classId;
821  ObjectAddress address;
822 
823  address = get_object_address(stmt->objectType,
824  stmt->object,
825  &relation,
827  false);
828  Assert(relation == NULL);
829  classId = address.classId;
830 
831  /*
832  * XXX - get_object_address returns Oid of pg_largeobject
833  * catalog for OBJECT_LARGEOBJECT because of historical
834  * reasons. Fix up it here.
835  */
836  if (classId == LargeObjectRelationId)
838 
839  catalog = heap_open(classId, RowExclusiveLock);
840 
841  AlterObjectOwner_internal(catalog, address.objectId, newowner);
842  heap_close(catalog, RowExclusiveLock);
843 
844  return address;
845  }
846  break;
847 
848  default:
849  elog(ERROR, "unrecognized AlterOwnerStmt type: %d",
850  (int) stmt->objectType);
851  return InvalidObjectAddress; /* keep compiler happy */
852  }
853 }
RoleSpec * newowner
Definition: parsenodes.h:2813
#define castNode(_type_, nodeptr)
Definition: nodes.h:578
ObjectType objectType
Definition: parsenodes.h:2810
#define strVal(v)
Definition: value.h:54
#define heap_close(r, l)
Definition: heapam.h:97
unsigned int Oid
Definition: postgres_ext.h:31
ObjectAddress AlterEventTriggerOwner(const char *name, Oid newOwnerId)
ObjectAddress AlterTypeOwner(List *names, Oid newOwnerId, ObjectType objecttype)
Definition: typecmds.c:3212
#define ERROR
Definition: elog.h:43
ObjectAddress AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId)
Definition: foreigncmds.c:277
void AlterObjectOwner_internal(Relation rel, Oid objectId, Oid new_ownerId)
Definition: alter.c:865
#define RowExclusiveLock
Definition: lockdefs.h:38
ObjectAddress AlterSubscriptionOwner(const char *name, Oid newOwnerId)
Oid get_rolespec_oid(const RoleSpec *role, bool missing_ok)
Definition: acl.c:5129
ObjectAddress AlterPublicationOwner(const char *name, Oid newOwnerId)
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
#define NULL
Definition: c.h:229
ObjectAddress AlterSchemaOwner(const char *name, Oid newOwnerId)
Definition: schemacmds.c:321
#define Assert(condition)
Definition: c.h:675
Definition: value.h:42
ObjectAddress AlterForeignServerOwner(const char *name, Oid newOwnerId)
Definition: foreigncmds.c:414
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
#define LargeObjectMetadataRelationId
ObjectAddress AlterDatabaseOwner(const char *dbname, Oid newOwnerId)
Definition: dbcommands.c:1601
#define AccessExclusiveLock
Definition: lockdefs.h:46
const ObjectAddress InvalidObjectAddress
#define elog
Definition: elog.h:219
#define LargeObjectRelationId
Definition: pg_list.h:45
ObjectAddress ExecRenameStmt ( RenameStmt stmt)

Definition at line 325 of file alter.c.

References AccessExclusiveLock, AlterObjectRename_internal(), Assert, ObjectAddress::classId, elog, ERROR, get_object_address(), heap_close, heap_open(), InvalidObjectAddress, RenameStmt::newname, NULL, 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_PUBLICATION, OBJECT_ROLE, 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(), RenameStmt::renameType, RenameType(), RowExclusiveLock, and RenameStmt::subname.

Referenced by ProcessUtilitySlow(), and standard_ProcessUtility().

326 {
327  switch (stmt->renameType)
328  {
331  return RenameConstraint(stmt);
332 
333  case OBJECT_DATABASE:
334  return RenameDatabase(stmt->subname, stmt->newname);
335 
336  case OBJECT_ROLE:
337  return RenameRole(stmt->subname, stmt->newname);
338 
339  case OBJECT_SCHEMA:
340  return RenameSchema(stmt->subname, stmt->newname);
341 
342  case OBJECT_TABLESPACE:
343  return RenameTableSpace(stmt->subname, stmt->newname);
344 
345  case OBJECT_TABLE:
346  case OBJECT_SEQUENCE:
347  case OBJECT_VIEW:
348  case OBJECT_MATVIEW:
349  case OBJECT_INDEX:
351  return RenameRelation(stmt);
352 
353  case OBJECT_COLUMN:
354  case OBJECT_ATTRIBUTE:
355  return renameatt(stmt);
356 
357  case OBJECT_RULE:
358  return RenameRewriteRule(stmt->relation, stmt->subname,
359  stmt->newname);
360 
361  case OBJECT_TRIGGER:
362  return renametrig(stmt);
363 
364  case OBJECT_POLICY:
365  return rename_policy(stmt);
366 
367  case OBJECT_DOMAIN:
368  case OBJECT_TYPE:
369  return RenameType(stmt);
370 
371  case OBJECT_AGGREGATE:
372  case OBJECT_COLLATION:
373  case OBJECT_CONVERSION:
375  case OBJECT_FDW:
377  case OBJECT_FUNCTION:
378  case OBJECT_OPCLASS:
379  case OBJECT_OPFAMILY:
380  case OBJECT_LANGUAGE:
383  case OBJECT_TSDICTIONARY:
384  case OBJECT_TSPARSER:
385  case OBJECT_TSTEMPLATE:
386  case OBJECT_PUBLICATION:
387  case OBJECT_SUBSCRIPTION:
388  {
389  ObjectAddress address;
390  Relation catalog;
391  Relation relation;
392 
393  address = get_object_address(stmt->renameType,
394  stmt->object,
395  &relation,
396  AccessExclusiveLock, false);
397  Assert(relation == NULL);
398 
399  catalog = heap_open(address.classId, RowExclusiveLock);
401  address.objectId,
402  stmt->newname);
403  heap_close(catalog, RowExclusiveLock);
404 
405  return address;
406  }
407 
408  default:
409  elog(ERROR, "unrecognized rename stmt type: %d",
410  (int) stmt->renameType);
411  return InvalidObjectAddress; /* keep compiler happy */
412  }
413 }
ObjectAddress RenameSchema(const char *oldname, const char *newname)
Definition: schemacmds.c:242
ObjectAddress RenameType(RenameStmt *stmt)
Definition: typecmds.c:3134
char * subname
Definition: parsenodes.h:2769
ObjectType renameType
Definition: parsenodes.h:2765
ObjectAddress RenameRelation(RenameStmt *stmt)
Definition: tablecmds.c:2874
#define heap_close(r, l)
Definition: heapam.h:97
char * newname
Definition: parsenodes.h:2771
ObjectAddress RenameDatabase(const char *oldname, const char *newname)
Definition: dbcommands.c:977
#define ERROR
Definition: elog.h:43
ObjectAddress rename_policy(RenameStmt *stmt)
Definition: policy.c:1201
#define RowExclusiveLock
Definition: lockdefs.h:38
Node * object
Definition: parsenodes.h:2768
ObjectAddress renametrig(RenameStmt *stmt)
Definition: trigger.c:1371
ObjectAddress renameatt(RenameStmt *stmt)
Definition: tablecmds.c:2686
ObjectAddress RenameConstraint(RenameStmt *stmt)
Definition: tablecmds.c:2823
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1284
RangeVar * relation
Definition: parsenodes.h:2767
ObjectAddress RenameRole(const char *oldname, const char *newname)
Definition: user.c:1131
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
ObjectAddress get_object_address(ObjectType objtype, Node *object, Relation *relp, LOCKMODE lockmode, bool missing_ok)
static void AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
Definition: alter.c:166
ObjectAddress RenameRewriteRule(RangeVar *relation, const char *oldName, const char *newName)
ObjectAddress RenameTableSpace(const char *oldname, const char *newname)
Definition: tablespace.c:910
#define AccessExclusiveLock
Definition: lockdefs.h:46
const ObjectAddress InvalidObjectAddress
#define elog
Definition: elog.h:219