Search⌘ K

Boolean

Explore the Boolean data type in PostgreSQL, its three-valued logic with true, false, and null, and how to work with Boolean operators and aggregates. Understand the nuances of comparisons and learn to use functions such as bool_and and bool_or for practical database queries.

We'll cover the following...

The boolean data type was the topic of the “Three-Valued Logic” chapter earlier, with the SQL boolean truth table that includes the values true, false, and null, and it’s important enough to warrant another inclusion here:

   a   │   b   │  a=b  │      op       │  result  
═══════╪═══════╪═══════╪═══════════════╪══════════
 true  │ true  │ true  │ true = true   │ is true
 true  │ false │ false │ true = false  │ is false
 true  │ ¤     │ ¤     │ true = null   │ is null
 false │ true  │ false │ false = true  │ is false
 false │ false │ true  │ false = false │ is true
 false │ ¤     │ ¤     │ false = null  │ is null
 ¤     │ true  │ ¤     │ null = true   │ is null
 ¤     │ false │ ¤
...