ALTER … OWNER TO
The ALTER … OWNER TO statement transfers ownership of a view or a schema to another role. Transfer ownership when a role leaves, or when a different role must manage an object.
Syntax
ALTER TABLE [schema_name.]view_name OWNER TO { role_name | CURRENT_USER | CURRENT_ROLE };
ALTER SCHEMA schema_name OWNER TO { role_name | CURRENT_USER | CURRENT_ROLE };
-
view_name: Name of the view. UseALTER TABLEto change the owner of a view. Redpanda SQL has noALTER VIEWstatement. Theschema_name.prefix is optional. If you omit it, Redpanda SQL finds the view through the search path. -
schema_name: Name of the Redpanda SQL schema, such aspublic. See SQL Schemas. -
role_name: Name of the role that becomes the new owner. The role must exist. -
CURRENT_USERorCURRENT_ROLE: Makes the role that runs the statement the new owner.
The ALTER TABLE … OWNER TO statement does not accept the catalog=> form. You cannot change the owner of a table in a Redpanda catalog or an Iceberg catalog with this statement. If the statement names a catalog connection, such as default_redpanda_catalog, it fails with relation "<catalog-name>" does not exist.
Behavior
-
The statement changes only the owner. It does not change the object’s privileges for other roles.
-
If the role is already the owner, the statement does nothing.
-
A view runs its query with the privileges of its owner. See CREATE VIEW permissions. When you change the owner of a view, the view reads data with the privileges of the new owner. The new owner must be able to read each table that the view reads. If not, queries of the view fail for every user.
-
You cannot drop a role that owns objects. DROP USER fails with
role "<role_name>" cannot be dropped because some objects depend on it. The error lists the objects that the role owns. To drop the role, first transfer ownership of its views and schemas or drop them, drop any catalog connections and storage definitions it owns, and revoke its grants. -
In Redpanda Cloud, when a user loses access to Redpanda SQL, the user’s role and the objects that the role owns remain.
Permissions
The current owner of the object or a superuser can change its owner. Other roles receive the error must be owner to alter owner.
In Redpanda Cloud, a user with the SQL: Manage permission is a superuser. See Manage access to Redpanda SQL.
Examples
Change the owner of the large_orders view in the public schema:
ALTER TABLE public.large_orders OWNER TO "alice@example.com";
As a superuser, take ownership of the analytics schema:
ALTER SCHEMA analytics OWNER TO CURRENT_USER;
Before you drop the user bob@example.com, transfer ownership of the views and schemas that the user owns. This example transfers the view large_orders to alice@example.com:
ALTER TABLE large_orders OWNER TO "alice@example.com";
Then drop any catalog connections and storage definitions that the user owns, and revoke the user’s grants. To drop the user, see DROP USER.