Recall & Review
beginner
What does the EXTRACT function do in PostgreSQL?
The EXTRACT function retrieves a specific part (like year, month, day) from a date or timestamp value.
Click to reveal answer
beginner
Write the syntax to extract the year from a timestamp column named 'created_at'.
EXTRACT(YEAR FROM created_at)
Click to reveal answer
intermediate
Which date parts can you extract using the EXTRACT function? Name at least three.
You can extract YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, and more from date or timestamp values.
Click to reveal answer
intermediate
What type of value does EXTRACT return?
EXTRACT returns a numeric value representing the requested date part, usually as a double precision number.
Click to reveal answer
beginner
How would you extract the month from the current date in PostgreSQL?
Use EXTRACT(MONTH FROM CURRENT_DATE) to get the current month number.
Click to reveal answer
What does EXTRACT(DAY FROM timestamp) return?
✗ Incorrect
EXTRACT(DAY FROM timestamp) returns the day of the month as a number.
Which of these is a valid EXTRACT syntax in PostgreSQL?
✗ Incorrect
The correct syntax is EXTRACT(part FROM source), for example EXTRACT(YEAR FROM timestamp).
What will EXTRACT(HOUR FROM TIMESTAMP '2024-06-01 15:30:00') return?
✗ Incorrect
It returns 15, the hour part of the timestamp.
Can EXTRACT be used on a DATE type in PostgreSQL?
✗ Incorrect
EXTRACT works on both DATE and TIMESTAMP types.
What is the return type of EXTRACT function?
✗ Incorrect
EXTRACT returns a numeric value as double precision.
Explain how to use the EXTRACT function to get the month and day from a timestamp.
Think about the parts you want and the source date or timestamp.
You got /3 concepts.
List at least five different date parts you can extract using the EXTRACT function in PostgreSQL.
Consider parts of date and time.
You got /6 concepts.