0
0
PostgreSQLquery~20 mins

Boolean type behavior in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Boolean Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Boolean comparison in WHERE clause
Given the table users with a boolean column is_active, what rows will be returned by this query?
SELECT * FROM users WHERE is_active = TRUE;
PostgreSQL
CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT, is_active BOOLEAN);
INSERT INTO users (name, is_active) VALUES ('Alice', TRUE), ('Bob', FALSE), ('Carol', NULL);
AOnly rows where is_active is TRUE (e.g., Alice)
BRows where is_active is TRUE or NULL (Alice and Carol)
CAll rows regardless of is_active value
DOnly rows where is_active is FALSE (Bob)
Attempts:
2 left
💡 Hint
Remember that in SQL, NULL means unknown and does not equal TRUE or FALSE.
query_result
intermediate
1:30remaining
Boolean logic with NULL values
What is the result of this query?
SELECT TRUE AND NULL AS result;
AFALSE
BNULL
CTRUE
DSyntax error
Attempts:
2 left
💡 Hint
Think about how SQL treats unknown values in boolean logic.
📝 Syntax
advanced
1:30remaining
Correct boolean literal usage in PostgreSQL
Which option uses the correct boolean literal in PostgreSQL to insert a TRUE value?
AINSERT INTO flags (flag) VALUES ('true');
BINSERT INTO flags (flag) VALUES ('yes');
CINSERT INTO flags (flag) VALUES (1);
DINSERT INTO flags (flag) VALUES (TRUE);
Attempts:
2 left
💡 Hint
PostgreSQL accepts boolean literals TRUE and FALSE without quotes.
query_result
advanced
1:30remaining
Boolean expression evaluation in SELECT
What is the output of this query?
SELECT
  CASE WHEN FALSE OR NULL THEN 'Yes' ELSE 'No' END AS answer;
A'Yes'
BNULL
C'No'
DSyntax error
Attempts:
2 left
💡 Hint
Remember how OR works with NULL in SQL's three-valued logic.
🧠 Conceptual
expert
2:30remaining
Behavior of boolean aggregates with NULLs
Consider a table checks with a boolean column passed containing TRUE, FALSE, and NULL values. What does the aggregate function bool_and(passed) return if any row has FALSE, but some rows have NULL?
AFALSE
BTRUE
CNULL
DError
Attempts:
2 left
💡 Hint
bool_and returns TRUE only if all non-null inputs are TRUE.