Casting smallint to boolean in PostgreSQL
I was trying:
ALTER TABLE mytable ALTER COLUMN mycol TYPE bool USING mycol::bool;
using the same approach as "Ispirer SQLWays Migrations"'s answer (cast smallint to int and then to boolean) worked:
ALTER TABLE mytable ALTER COLUMN mycol TYPE bool USING mycol::int::bool;
CREATE OR REPLACE FUNCTION boolean1(i smallint) RETURNS boolean AS $$
BEGIN
RETURN (i::smallint)::int::bool;
END;
$$ LANGUAGE plpgsql;
CREATE CAST (smallint AS boolean) WITH FUNCTION boolean1(smallint) AS ASSIGNMENT;