8.6. Boolean Type
8.6.布尔值
PostgreSQL provides the standard SQL type boolean; see Table 8.19. The boolean type can have several states: “true”, “false”, and a third state, “unknown”, which is represented by the SQL null value.
PostgreSQL提供标准SQL中的布尔类型:参见表8.19。boolean类型可以有以下几种状态:“true”, “false”和“unknown”,“unknown”表示SQL中的空值。
Valid literal values for the “true” state are:
“true”状态的可用值为:
TRUE
't'
'true'
'y'
'yes'
'on'
'1'
For the “false” state, the following values can be used:
“false”状态的可用值为:
FALSE
'f'
'false'
'n'
'no'
'off'
'0'
Leading or trailing whitespace is ignored, and case does not matter. The key words TRUE and FALSE are the preferred (SQL-compliant) usage.
会忽略首空格或尾空格,且大小写不敏感。当然,最好使用关键词TRUE和FALSE(符合SQL标准)。
Example 8.2 shows that boolean values are output using the letters t and f.
示例8.2显示布尔值输出时使用字母t和f。
Example 8.2. Using the boolean Type
CREATE TABLE test1 (a boolean, b text);
INSERT INTO test1 VALUES (TRUE, 'sic est');
INSERT INTO test1 VALUES (FALSE, 'non est');
SELECT * FROM test1;
a | b
---+---------
t | sic est
f | non est
SELECT * FROM test1 WHERE a;
a | b
---+---------
t | sic est