Difference between Bit and Boolean datatypes in Po

2020-07-09 08:53发布

问题:

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?

回答1:

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.