164 Star 224 Fork 1.2K

openGauss / docs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
布尔类型.md 4.43 KB
一键复制 编辑 原始数据 按行查看 历史
gongsiyi 提交于 2020-09-29 16:17 . 修改布尔类型

布尔类型

表 1 布尔类型

名称

描述

存储空间

取值

BOOLEAN

布尔类型

1字节。

  • true:真
  • false:假
  • null:未知(unknown)

“真”值的有效文本值是:

TRUE、't'、'true'、'y'、'yes'、'1'、'TRUE'、true、整数范围内12^63-1、整数范围内-1-2^63。

“假”值的有效文本值是:

FALSE、'f'、'false'、'n'、'no'、'0'、'FALSE'、false、0。

使用TRUE和FALSE是比较规范的用法(也是SQL兼容的用法)。

示例

显示用字母t和f输出Boolean值。

--创建表。
postgres=# CREATE TABLE bool_type_t1  
(
    BT_COL1 BOOLEAN,
    BT_COL2 TEXT
);

--插入数据。
postgres=# INSERT INTO bool_type_t1 VALUES (TRUE, 'sic est');

postgres=# INSERT INTO bool_type_t1 VALUES (FALSE, 'non est');

--查看数据。
postgres=# SELECT * FROM bool_type_t1;
 bt_col1 | bt_col2 
---------+---------
 t       | sic est
 f       | non est
(2 rows)

postgres=# SELECT * FROM bool_type_t1 WHERE bt_col1 = 't';
 bt_col1 | bt_col2 
---------+---------
 t       | sic est
(1 row)

--删除表。
postgres=# DROP TABLE bool_type_t1;
1
https://gitee.com/opengauss/docs.git
git@gitee.com:opengauss/docs.git
opengauss
docs
docs
2.0.0

搜索帮助