Challenge - 5 Problems
Range Types Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
Output of int4range containment check
What is the output of this query?
SELECT int4range(1, 5) @> 3 AS contains_three;PostgreSQL
SELECT int4range(1, 5) @> 3 AS contains_three;
Attempts:
2 left
💡 Hint
The operator @> checks if the range contains the value.
✗ Incorrect
The range int4range(1,5) includes integers from 1 up to but not including 5. Since 3 is within this range, the result is true.
❓ query_result
intermediate2:00remaining
Result of daterange union operation
What is the result of this query?
SELECT daterange('2023-01-01', '2023-01-10') + daterange('2023-01-05', '2023-01-15') AS union_range;PostgreSQL
SELECT daterange('2023-01-01', '2023-01-10') + daterange('2023-01-05', '2023-01-15') AS union_range;
Attempts:
2 left
💡 Hint
The + operator merges overlapping or adjacent ranges.
✗ Incorrect
The two dateranges overlap between 2023-01-05 and 2023-01-10, so their union is a single continuous range from 2023-01-01 to 2023-01-15 (excluding the end).
📝 Syntax
advanced1:30remaining
Identify the syntax error in int4range creation
Which option contains a syntax error when creating an int4range?
Query example:
Query example:
SELECT int4range(...);Attempts:
2 left
💡 Hint
The lower bound must be less than or equal to the upper bound.
✗ Incorrect
int4range(5, 1) is invalid because the lower bound (5) is greater than the upper bound (1), causing a runtime error.
🔧 Debug
advanced2:00remaining
Why does this daterange overlap query return no rows?
Given a table events(date_range daterange), why does this query return no rows?
SELECT * FROM events WHERE daterange('2023-01-01', '2023-01-10') && daterange('2023-01-10', '2023-01-20');Attempts:
2 left
💡 Hint
Remember how half-open ranges treat their boundaries.
✗ Incorrect
By default, dateranges are half-open [start, end), so the first range ends at 2023-01-10 but does not include it, and the second starts at 2023-01-10. They do not overlap, so the && operator returns false.
🧠 Conceptual
expert2:30remaining
Choosing the correct range type for a date interval with inclusive end
You want to store a date interval that includes both the start and end dates (inclusive). Which range type and bounds option should you use in PostgreSQL?
Attempts:
2 left
💡 Hint
Check how bounds affect inclusion of start and end in ranges.
✗ Incorrect
The daterange type with bounds '[]' includes both the start and end dates, making it suitable for fully inclusive date intervals.