PostgreSQL | Data Types | Boolean Data Type
This page explains how to use the boolean data type among the data types available in PostgreSQL. The only logical data type is boolean.
Using the Boolean Data Type
Only one data type is provided as a logical data type.
| Type | Size | Range | Alias |
|---|---|---|---|
| boolean | 1 byte | true or false state | bool |
The boolean type contains one of the values that represent true or false. In PostgreSQL, the following values can be used to represent true.
Values that represent true:
TRUE
't'
'true'
'y'
'yes'
'on'
'1'
Values that represent false:
FALSE
'f'
'false'
'n'
'no'
'off'
'0'
You can use any of these values when storing values in a boolean column, but it is best to use TRUE and FALSE for readability whenever possible.
Create the following table for practice.
devkuma=# create table booltest (flag boolean);
CREATE TABLE
devkuma=#
Then add data to the table. Insert several values that represent true and false.
devkuma=# insert into booltest values (TRUE), ('no'), ('0'), ('yes'), (FALSE);
INSERT 0 5
devkuma=#
Retrieve the data from the booltest table.
devkuma=# select * from booltest;
flag
------
t
f
f
t
f
(5 rows)
devkuma=#
When you retrieve values of the boolean type, t or f is displayed by default.
–
This page explained how to use the boolean data type among the data types available in PostgreSQL.