PostgreSQL provides the SQL99 type boolean. boolean can have one of only two states: "true" or "false". A third state, "unknown", is represented by the SQL NULL state.
Valid literal values for the "true" state are:
TRUE |
't' |
'true' |
'y' |
'yes' |
'1' |
FALSE |
'f' |
'false' |
'n' |
'no' |
'0' |
Example 2-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 |
Example 2-2 shows that boolean values are output using the letters t and f.
Values of the boolean type cannot be cast directly to other types (for example., 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 the Section called Conditional Expressions in Chapter 1. |
boolean uses 1 byte of storage.