0
0
PostgreSQLquery~10 mins

Interval type for durations 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 declare a column that stores time durations using the interval type.

PostgreSQL
CREATE TABLE events (duration [1]);
Drag options to blanks, or click blank then click option'
AINTERVAL
BVARCHAR(10)
CINTEGER
DDATE
Attempts:
3 left
💡 Hint
Common Mistakes
Using DATE or TIMESTAMP instead of INTERVAL for durations.
Using INTEGER which stores numbers but not time intervals.
2fill in blank
medium

Complete the code to add 3 hours to the current timestamp using interval.

PostgreSQL
SELECT NOW() + [1] '3 hours';
Drag options to blanks, or click blank then click option'
ATIMESTAMP
BTIME
CINTERVAL
DDATE
Attempts:
3 left
💡 Hint
Common Mistakes
Using DATE or TIME which are not durations.
Forgetting to specify INTERVAL before the string.
3fill in blank
hard

Fix the error in the query that tries to subtract 30 minutes from a timestamp.

PostgreSQL
SELECT CURRENT_TIMESTAMP - [1] '30 minutes';
Drag options to blanks, or click blank then click option'
AINTERVAL
BTIME
CTIMESTAMP
DDATE
Attempts:
3 left
💡 Hint
Common Mistakes
Using TIMESTAMP or DATE which represent points in time, not durations.
Omitting the INTERVAL keyword.
4fill in blank
hard

Fill both blanks to create an interval of 2 days and 5 hours.

PostgreSQL
SELECT [2] '[1]';
Drag options to blanks, or click blank then click option'
A2 days 5 hours
B'2 days 5 hours'
CINTERVAL
DDAYS
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes inside the string literal again.
Using DAYS instead of INTERVAL keyword.
5fill in blank
hard

Fill all three blanks to calculate the total duration in minutes from 1 hour, 30 minutes, and 45 seconds.

PostgreSQL
SELECT EXTRACT(EPOCH FROM ([1] + [2] + [3])) / 60 AS total_minutes;
Drag options to blanks, or click blank then click option'
AINTERVAL '1 hour'
BINTERVAL '30 minutes'
CINTERVAL '45 seconds'
DINTERVAL '1 day'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong interval values or missing INTERVAL keyword.
Not dividing by 60 to convert seconds to minutes.