Reputation: 251
I am new to PostgreSQL. I have doubt while creating table in the database. Can anyone clarify me the difference between bit
and boolean
datatypes?
Upvotes: 25
Views: 18357
Reputation:
A bit
only stores the numbers 0
and 1
(or null
).
A boolean
only stores true
and false
(or null
). A number (0, 1) is not a boolean. A boolean value can be used anywhere a boolean expression is expected. So you can e.g. do this:
where is_active
A bit column needs to be compared to something:
where a_bit_column = 0
(the result of a_bit_column = 0
is a boolean)
Contrary to the what some DBMS think, the expression where 0
or where 1
is not valid boolean expression.
Upvotes: 37