When you execute a CREATE CAST statement on an ApsaraDB RDS for PostgreSQL instance, the following error is returned:
ERROR: must be owner of type xxx or type xxxFor example, this error occurs with the following statement:
CREATE CAST(boolean AS smallint) WITH INOUT AS implicit;Cause
Creating a cast requires ownership of at least one of the involved data types. Built-in types such as boolean and smallint are owned by the system, so a regular database account cannot create casts between them. To resolve this, transfer ownership of the relevant type to your current role before running CREATE CAST.
Your RDS instance must meet the following requirements:
Major engine version: PostgreSQL 10 or later.
Minor engine version: 20210531 or later. For information about how to view and update the minor engine version, see Update the minor engine version.
Solution
The following steps use CREATE CAST(boolean AS smallint) as an example.
Connect to the database with a privileged account. For more information, see Create an account.
Change the owner of the data type to your current role:
ALTER type bool owner TO <your role>;Run the
CREATE CASTstatement again:CREATE CAST(boolean AS smallint) WITH INOUT AS implicit;