PostgreSQL中的位和布尔数据类型之间的区别 [英] Difference between Bit and Boolean datatypes in PostgreSQL
问题描述
我是PostgreSQL的新手。我在数据库中创建表时有疑问。谁能澄清我 bit
和 boolean
数据类型之间的区别吗?
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?
推荐答案
位
仅存储数字 0
和 1
(或 null
)。
A bit
only stores the numbers 0
and 1
(or null
).
A boolean
仅存储 true
和 false
(或 null
)。数字(0,1)不是是布尔值。布尔值可以在需要布尔 expression 的任何地方使用。所以你可以为此:
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
( a_bit_column = 0
的结果是布尔值)
与某些DBMS的想法相反,表达式其中0
或其中1
是不是有效的布尔表达式。
Contrary to the what some DBMS think, the expression where 0
or where 1
is not valid boolean expression.
这篇关于PostgreSQL中的位和布尔数据类型之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!