How to Alter Boolean column to Integer column in PostgreSQL
I faced a situation where I had to change a column type from Boolean to Integer. And I wanted to rename the column name. For example, we have table that has a boolean column "bDeleted". I have to remane "dDeleted" to "iDeleted" and all boolean values need to convert into 0 and 1. Then you have to run below PostgreSQL queries.
ALTER TABLE users ALTER "bDeleted" SET DEFAULT null;
ALTER TABLE users
ALTER "bDeleted" TYPE INTEGER
WHEN 'f' THEN 0 ELSE 1
ALTER TABLE users RENAME "bDeleted" TO "iDeleted";
ALTER TABLE users ALTER "iDeleted" SET DEFAULT 0;