Table 7-15. Boolean Type
Name | Aliases | Description |
---|
BOOLEAN | BIT | logical boolean (true/false) |
EnterpriseDB provides the
standard SQL type BOOLEAN.
BOOLEAN can have one of only two states:
"true" or "false". A third state,
"unknown", is represented by the
SQL null value.
Valid literal values for the "true" state are:
For the
"false" state, the following values can be
used:
FALSE |
'f' |
'false' |
'n' |
'no' |
'0' |
Using the key words
TRUE and
FALSE is preferred (and
SQL-compliant).
Example 7-1. 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
Example 7-1 shows that
BOOLEAN values are output using the letters
t and f.
Tip: Values of the BOOLEAN type cannot be cast directly
to other types (e.g., CAST
(boolval AS integer) does
not work). This can be accomplished using the
CASE expression: CASE WHEN
boolval THEN 'value if true' ELSE
'value if false' END. See also Section 8.10.
BOOLEAN uses 1 byte of storage.
Note: For more information on supported datatypes missing from the above chapter, please refer to PostgreSQL's documentation.