0
0
PostgreSQLquery~5 mins

Boolean type behavior in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What values can a PostgreSQL Boolean type store?
A PostgreSQL Boolean type can store three values: true, false, and NULL (unknown).
Click to reveal answer
beginner
How does PostgreSQL interpret the string 't' when cast to Boolean?
PostgreSQL interprets the string 't' as true when cast to Boolean.
Click to reveal answer
intermediate
What happens when you use a Boolean column in a WHERE clause in PostgreSQL?
The WHERE clause treats true as passing the condition, false as failing, and NULL as unknown, so rows with NULL in that column are excluded unless explicitly handled.
Click to reveal answer
intermediate
Can you use Boolean values in arithmetic operations in PostgreSQL?
No, Boolean values cannot be directly used in arithmetic operations. You must cast them to integers (true = 1, false = 0) first.
Click to reveal answer
beginner
How do you explicitly cast a Boolean to text in PostgreSQL?
Use the CAST operator or :: syntax, for example: SELECT true::text; returns 't'.
Click to reveal answer
Which of these is NOT a valid Boolean literal in PostgreSQL?
A'xyz'
B'true'
C'f'
D'false'
What does the expression SELECT NULL::boolean; return?
AError
Bfalse
Ctrue
DNULL
In a WHERE clause, what happens to rows where the Boolean column is NULL?
AThey are excluded
BThey are included
CThey cause an error
DThey are converted to false
How can you convert a Boolean true to integer 1 in PostgreSQL?
Atrue * 1
Btrue + 1
CCAST(true AS integer)
Dtrue::text
Which of these is the correct way to cast Boolean false to text?
ACAST(false AS integer)
Bfalse::text
CCAST(false AS boolean)
Dfalse + ''
Explain how PostgreSQL handles Boolean values and their behavior in queries.
Think about how true, false, and NULL affect filtering and casting.
You got /4 concepts.
    Describe how to convert Boolean values to other types in PostgreSQL and why it might be necessary.
    Consider when you want to display or calculate with Boolean values.
    You got /4 concepts.