↑↓ select ↵ open ⌫ change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / Data Types / Boolean

boolean

logical Boolean (true/false)

Reading PostgreSQL 18.6.

PG10–20 core source inventory. Casts and operator classes show explicitly declared relationships; absent rows do not rule out coercions or indexing through other mechanisms.

Definition

SQL names and aliases: bool

logical Boolean (true/false)

boolean
Catalog name
pg_catalog.bool
Type OID
16
Type kind
Base type
Declared length
1 byte
Storage strategy
plain
Input function
boolin
Output function
boolout
Documented declaration
boolean
Storage Size
1 byte
Manual description
state of true or false

English manual

Read the complete manual section

Read the source definition

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

Boolean constants can be represented in SQL queries by the SQL key words TRUE, FALSE, and NULL.

The datatype input function for type boolean accepts these string representations for the “true” state:

true
yes
on
1

and these representations for the “false” state:

false
no
off
0

Unique prefixes of these strings are also accepted, for example t or n. Leading or trailing whitespace is ignored, and case does not matter.

The datatype output function for type boolean always emits either t or f, as shown in Example 8.2.

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

The key words TRUE and FALSE are the preferred (SQL-compliant) method for writing Boolean constants in SQL queries. But you can also use the string representations by following the generic string-literal constant syntax described in Section 4.1.2.7, for example 'yes'::boolean.

Note that the parser automatically understands that TRUE and FALSE are of type boolean, but this is not so for NULL because that can have any type. So in some contexts you might have to cast NULL to boolean explicitly, for example NULL::boolean. Conversely, the cast can be omitted from a string-literal Boolean value in contexts where the parser can deduce that the literal must be of type boolean.

Catalog attributes

Source bootstrap values for this build. See pg_type for field meanings. Header defaults are included; build-dependent constants remain symbolic. This is not a live-server measurement.

oid
16
descr
boolean, format 't'/'f'
typacl
_null_
typlen
1
typelem
0
typname
bool
typsend
boolsend
typtype
b
typalign
c
typarray
0
typbyval
t
typdelim
','
typinput
boolin
typmodin
-
typndims
0
typowner
POSTGRES
typrelid
0
typmodout
-
typoutput
boolout
typtypmod
-1
typanalyze
-
typdefault
_null_
typnotnull
f
typreceive
boolrecv
typstorage
p
typbasetype
0
typcategory
B
typcollation
0
typisdefined
t
typnamespace
pg_catalog
typsubscript
-
typdefaultbin
_null_
array_type_oid
1000
typispreferred
t
array_type_name
_bool

Catalog casts 6

Explicit pg_cast records involving this type. PostgreSQL also supports coercions outside pg_cast; an absent row does not prove that a conversion is impossible.

FromToContextMethodFunction
int4boolExplicitFunctionbool(int4)
boolint4ExplicitFunctionint4(bool)
booltextAssignmentFunctiontext(bool)
boolvarcharAssignmentFunctiontext(bool)
boolbpcharAssignmentFunctiontext(bool)
jsonbboolExplicitFunctionbool(jsonb)

Operator overloads 6

Each operand signature is a separate overload. Catalog implementation functions and result types belong to the same source build.

OperatorLeft operandRight operandResultMeaningImplementation
<boolboolboolless thanboollt
>boolboolboolgreater thanboolgt
<>boolboolboolnot equalboolne
=boolboolboolequalbooleq
<=boolboolboolless than or equalboolle
>=boolboolboolgreater than or equalboolge

Operator classes 2

Operator classes whose declared input type matches this type. Polymorphic classes, casts and expression indexes can provide additional index paths; this list is not an exhaustive yes/no index-support test.

ClassIndex methodInput typeFamilyDefaultStorage type
bool_opsbtreeboolbtree/bool_opsYesSame as input
bool_opshashboolhash/bool_opsYesSame as input

Version comparison

PostgreSQL 17.11 → 18.6. Source build identifiers and prose are excluded from attribute changes.

No catalog or structured attribute changes between these samples.

The documentation also differs between these builds; inspect the versioned manual definitions.

Documentation and source

Build
18.6 · https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2
Fingerprint
555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f

Related entries

All Data Types · Download this version as JSON · The first recorded sample does not establish when a type was introduced.