diff options
Diffstat (limited to 'src/backend/commands/alter.c')
-rw-r--r-- | src/backend/commands/alter.c | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c index 78b54b4a418..59aacef7ea9 100644 --- a/src/backend/commands/alter.c +++ b/src/backend/commands/alter.c @@ -299,8 +299,10 @@ AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name) /* * Executes an ALTER OBJECT / RENAME TO statement. Based on the object * type, the function appropriate to that type is executed. + * + * Return value is the address of the renamed object. */ -Oid +ObjectAddress ExecRenameStmt(RenameStmt *stmt) { switch (stmt->renameType) @@ -378,39 +380,54 @@ ExecRenameStmt(RenameStmt *stmt) stmt->newname); heap_close(catalog, RowExclusiveLock); - return address.objectId; + return address; } default: elog(ERROR, "unrecognized rename stmt type: %d", (int) stmt->renameType); - return InvalidOid; /* keep compiler happy */ + return InvalidObjectAddress; /* keep compiler happy */ } } /* * Executes an ALTER OBJECT / SET SCHEMA statement. Based on the object * type, the function appropriate to that type is executed. + * + * Return value is that of the altered object. + * + * oldSchemaAddr is an output argument which, if not NULL, is set to the object + * address of the original schema. */ -Oid -ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt) +ObjectAddress +ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt, + ObjectAddress *oldSchemaAddr) { + ObjectAddress address; + Oid oldNspOid; + switch (stmt->objectType) { case OBJECT_EXTENSION: - return AlterExtensionNamespace(stmt->object, stmt->newschema); + address = AlterExtensionNamespace(stmt->object, stmt->newschema, + oldSchemaAddr ? &oldNspOid : NULL); + break; case OBJECT_FOREIGN_TABLE: case OBJECT_SEQUENCE: case OBJECT_TABLE: case OBJECT_VIEW: case OBJECT_MATVIEW: - return AlterTableNamespace(stmt); + address = AlterTableNamespace(stmt, + oldSchemaAddr ? &oldNspOid : NULL); + break; case OBJECT_DOMAIN: case OBJECT_TYPE: - return AlterTypeNamespace(stmt->object, stmt->newschema, - stmt->objectType); + address = AlterTypeNamespace(stmt->object, stmt->newschema, + stmt->objectType, + oldSchemaAddr ? &oldNspOid : NULL); + break; /* generic code path */ case OBJECT_AGGREGATE: @@ -442,19 +459,22 @@ ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt) catalog = heap_open(classId, RowExclusiveLock); nspOid = LookupCreationNamespace(stmt->newschema); - AlterObjectNamespace_internal(catalog, address.objectId, - nspOid); + oldNspOid = AlterObjectNamespace_internal(catalog, address.objectId, + nspOid); heap_close(catalog, RowExclusiveLock); - - return address.objectId; } break; default: elog(ERROR, "unrecognized AlterObjectSchemaStmt type: %d", (int) stmt->objectType); - return InvalidOid; /* keep compiler happy */ + return InvalidObjectAddress; /* keep compiler happy */ } + + if (oldSchemaAddr) + ObjectAddressSet(*oldSchemaAddr, NamespaceRelationId, oldNspOid); + + return address; } /* @@ -676,7 +696,7 @@ AlterObjectNamespace_internal(Relation rel, Oid objid, Oid nspOid) * Executes an ALTER OBJECT / OWNER TO statement. Based on the object * type, the function appropriate to that type is executed. */ -Oid +ObjectAddress ExecAlterOwnerStmt(AlterOwnerStmt *stmt) { Oid newowner = get_role_oid(stmt->newowner, false); @@ -747,15 +767,14 @@ ExecAlterOwnerStmt(AlterOwnerStmt *stmt) AlterObjectOwner_internal(catalog, address.objectId, newowner); heap_close(catalog, RowExclusiveLock); - return address.objectId; + return address; } break; default: elog(ERROR, "unrecognized AlterOwnerStmt type: %d", (int) stmt->objectType); - - return InvalidOid; /* keep compiler happy */ + return InvalidObjectAddress; /* keep compiler happy */ } } |