0
0
PostgreSQLquery~10 mins

Range types (int4range, daterange) in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an integer range from 1 to 10 (excluding 10).

PostgreSQL
SELECT int4range(1, [1]);
Drag options to blanks, or click blank then click option'
A11
B9
C10
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 11 as upper bound will create a range up to 10 inclusive, which is not the default behavior.
Using 9 will exclude 9 and 10, which is too small.
2fill in blank
medium

Complete the code to create a date range from January 1, 2023 to January 10, 2023 (excluding the end date).

PostgreSQL
SELECT daterange('2023-01-01', [1]);
Drag options to blanks, or click blank then click option'
A'2023-01-09'
B'2023-01-10'
C'2023-01-11'
D'2023-01-01'
Attempts:
3 left
💡 Hint
Common Mistakes
Using January 9 as end date excludes January 9 itself.
Using January 11 includes January 10, which is beyond the intended range.
3fill in blank
hard

Fix the error in the code to check if the integer 5 is inside the range from 1 to 10.

PostgreSQL
SELECT 5 [1] int4range(1, 10);
Drag options to blanks, or click blank then click option'
A<@
BCONTAINS
C@>
DIN
Attempts:
3 left
💡 Hint
Common Mistakes
Using IN is invalid syntax for range containment.
Using CONTAINS is not a valid SQL operator.
Using @> reverses the operands.
4fill in blank
hard

Fill both blanks to create a range from 5 to 15 including 15.

PostgreSQL
SELECT int4range([1], [2], '];');
Drag options to blanks, or click blank then click option'
A5
B15
C16
D14
Attempts:
3 left
💡 Hint
Common Mistakes
Using 15 as upper bound excludes 15 even with '];' bounds.
Using 14 excludes 15.
5fill in blank
hard

Fill all three blanks to create a daterange from March 1, 2023 to March 31, 2023 including both dates.

PostgreSQL
SELECT daterange([1], [2], [3]);
Drag options to blanks, or click blank then click option'
A'2023-03-01'
B'2023-04-01'
C'[]'
D'[)'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '()' or '[)' excludes the end date.
Using March 31 as end date excludes March 31.