Boolean Type
8.6. Boolean Type
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.
Table 8-19. Boolean Data Type
Name | Storage Size | Description |
---|---|---|
boolean | 1 byte | state of true or false |
Valid literal values for the "true" state are:
TRUE |
't' |
'true' |
'y' |
'yes' |
'on' |
'1' |
FALSE |
'f' |
'false' |
'n' |
'no' |
'off' |
'0' |
TRUE
and FALSE
are the preferred (SQL-compliant) usage. Example 8-2 shows that boolean
values are output using the letters t
and 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
© 1996–2017 The PostgreSQL Global Development Group
Licensed under the PostgreSQL License.
https://www.postgresql.org/docs/9.4/static/datatype-boolean.html