PHP Manual

PEAR Manual

Smarty Manual

PostgreSQL

MySQL Manual

Perl Manual

8.6. boolean type

postgresql 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:

true
't'
'true'
'y'
'yes'
'1'

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 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

example 8-2 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 section 9.13.

boolean uses 1 byte of storage.