PostgreSQL中的位和布尔数据类型之间的区别 [英] Difference between Bit and Boolean datatypes in PostgreSQL

查看:148
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆