Boolean

Learn and explore the use of the boolean data type with the coding example.

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 │ ¤     │ null = false  │ is null
 ¤     │ ¤     │ ¤     │ null = null   │ is null
(9 rows)

Aggregates

We can have tuple attributes as booleans too, and PostgreSQL includes specific aggregates for them:

Get hands-on with 1400+ tech skills courses.