postgres change column type from boolean to integer

Posted by gjergj.sheldija on December 3, 2012

postgres change column type from boolean to integer

ALTER TABLE table_name ALTER column_name SET DEFAULT null;
 
ALTER TABLE table_name
ALTER column_name TYPE INTEGER
USING
CASE
	WHEN false THEN 0 ELSE 1
END;
 
ALTER TABLE table_name ALTER column_name SET DEFAULT 0;
COMMIT;