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.