Friday, January 3, 2020

Unknown knowns: Postgres Boolean Column Default Value

I am new to Postgres and I was trying to default a boolean column to true or false. But kept getting an error:

ERROR:  column "ColumnName" is of type bit but default expression is of type boolean 
HINT:  You will need to rewrite or cast the expression.

I tried using values 1, true, TRUE, and 'TRUE'. None of these worked.

Solution

ALTER TABLE public."_TableName" ALTER COLUMN "ColumnName" SET DEFAULT '1';


According to what I can find online, the other values should have also worked. At first, I thought maybe DBeaver was causing the problems but I get the same error when I run the same command to the VM. I do not know why this does not work. Link 1 shows that TRUE should have at least worked.

Reference

1 - https://www.postgresqltutorial.com/postgresql-boolean/


No comments:

Post a Comment