0
0
PostgreSQLquery~5 mins

Boolean column filtering patterns in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a Boolean column in a database?
A Boolean column stores values that can only be true or false. It helps to represent yes/no or on/off states in data.
Click to reveal answer
beginner
How do you filter rows where a Boolean column is true in PostgreSQL?
Use WHERE column_name = TRUE or simply WHERE column_name to get rows where the Boolean column is true.
Click to reveal answer
beginner
How do you filter rows where a Boolean column is false in PostgreSQL?
Use WHERE column_name = FALSE or WHERE NOT column_name to get rows where the Boolean column is false.
Click to reveal answer
intermediate
What happens if you filter a Boolean column with WHERE column_name IS NULL?
It returns rows where the Boolean column has no value (NULL). This is different from true or false and means the value is unknown or missing.
Click to reveal answer
intermediate
Why might you use WHERE column_name IS NOT TRUE instead of WHERE column_name = FALSE?
Because IS NOT TRUE includes both false and NULL values, while = FALSE only includes false. This helps catch unknown or missing data too.
Click to reveal answer
Which SQL clause filters rows where a Boolean column named 'active' is true?
AWHERE active = TRUE
BWHERE active = FALSE
CWHERE active IS NULL
DWHERE active
How do you select rows where a Boolean column 'subscribed' is false?
AWHERE subscribed = TRUE
BWHERE subscribed IS NULL
CWHERE NOT subscribed
DWHERE subscribed = NULL
What does WHERE flag IS NULL return?
ARows where flag is true
BRows where flag is false
CAll rows
DRows where flag has no value
Which clause includes rows where a Boolean column is false or NULL?
AWHERE column_name IS NOT TRUE
BWHERE column_name = FALSE
CWHERE column_name = TRUE
DWHERE column_name IS NULL
What is the simplest way to filter rows where a Boolean column 'enabled' is true?
AWHERE enabled
BWHERE enabled IS NULL
CWHERE NOT enabled
DWHERE enabled = TRUE
Explain how to filter rows based on a Boolean column in PostgreSQL for true, false, and NULL values.
Think about how true, false, and unknown values are stored and checked.
You got /3 concepts.
    Describe why you might use 'IS NOT TRUE' instead of '= FALSE' when filtering Boolean columns.
    Consider how NULL values behave in Boolean filtering.
    You got /3 concepts.