Challenge - 5 Problems
EXTRACT Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
Extracting the year from a timestamp
What is the output of this query?
SELECT EXTRACT(YEAR FROM TIMESTAMP '2023-11-15 08:30:00');
PostgreSQL
SELECT EXTRACT(YEAR FROM TIMESTAMP '2023-11-15 08:30:00');
Attempts:
2 left
💡 Hint
EXTRACT gets a specific part of the date/time, like year, month, or day.
✗ Incorrect
The EXTRACT function returns the specified part of the date/time. Here, YEAR returns 2023 from the timestamp.
❓ query_result
intermediate1:30remaining
Extracting the month from a date
What does this query return?
SELECT EXTRACT(MONTH FROM DATE '2024-02-29');
PostgreSQL
SELECT EXTRACT(MONTH FROM DATE '2024-02-29');
Attempts:
2 left
💡 Hint
MONTH extracts the month number from the date.
✗ Incorrect
The EXTRACT function with MONTH returns the month number, which is 2 for February.
📝 Syntax
advanced2:00remaining
Identify the syntax error in EXTRACT usage
Which option contains a syntax error when using EXTRACT in PostgreSQL?
Attempts:
2 left
💡 Hint
Check the syntax: EXTRACT expects the part and source separated by FROM.
✗ Incorrect
Option A uses a comma instead of FROM, which is invalid syntax for EXTRACT.
❓ query_result
advanced1:30remaining
Extracting fractional seconds from a timestamp
What is the output of this query?
SELECT EXTRACT(SECOND FROM TIMESTAMP '2023-07-20 14:23:45.678');
PostgreSQL
SELECT EXTRACT(SECOND FROM TIMESTAMP '2023-07-20 14:23:45.678');
Attempts:
2 left
💡 Hint
EXTRACT(SECOND) returns seconds including fractional part.
✗ Incorrect
The EXTRACT function returns seconds with decimals, so 45.678 is correct.
🧠 Conceptual
expert2:30remaining
Understanding EXTRACT with time zone aware timestamps
Given the timestamp with time zone '2023-12-31 23:00:00+02', what does this query return?
SELECT EXTRACT(HOUR FROM TIMESTAMPTZ '2023-12-31 23:00:00+02');
PostgreSQL
SELECT EXTRACT(HOUR FROM TIMESTAMPTZ '2023-12-31 23:00:00+02');
Attempts:
2 left
💡 Hint
EXTRACT returns the hour part in the local time of the timestamp, ignoring time zone offset.
✗ Incorrect
EXTRACT(HOUR) returns the hour part as stored, which is 23, not adjusted to UTC.