sql >> Base de Datos >  >> RDS >> PostgreSQL

Postgres Alter Column Integer a Boolean

Prueba esto:

ALTER TABLE mytabe ALTER COLUMN mycolumn DROP DEFAULT;
ALTER TABLE mytabe ALTER mycolumn TYPE bool USING CASE WHEN mycolumn=0 THEN FALSE ELSE TRUE END;
ALTER TABLE mytabe ALTER COLUMN mycolumn SET DEFAULT FALSE;

Primero debe eliminar la restricción (ya que no es un valor booleano) y, en segundo lugar, su CASE la declaración era sintácticamente incorrecta.