CREATE CAST requires ownership of the source or target data type. Built-in types like boolean and smallint are owned by the PostgreSQL system, so running CREATE CAST on them triggers ERROR: must be owner of type xxx or type xxx. To work around this, temporarily transfer ownership of the type to your account, then run the statement.
Prerequisites
Before you begin, ensure that you have:
-
A major engine version of PostgreSQL 10 or later
-
A minor engine version of 20210531 or later — see Update the minor engine version if you need to upgrade
Solution
-
Connect to the database using a privileged account. To create one if you don't have one, see Create an account.
-
Transfer ownership of the source data type to your current account:
ALTER TYPE bool OWNER TO <your_role>;Replace
<your_role>with the name of the privileged account you used to connect. -
Run the
CREATE CASTstatement:CREATE CAST (boolean AS smallint) WITH INOUT AS IMPLICIT;