0
0
PostgreSQLquery~5 mins

EXTRACT function for date parts in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AThe day of the week from the timestamp
BThe day of the month from the timestamp
CThe total number of days since 1970
DThe hour part of the timestamp
Which of these is a valid EXTRACT syntax in PostgreSQL?
AEXTRACT(YEAR FROM timestamp)
BEXTRACT(YEAR, timestamp)
CEXTRACT timestamp YEAR
DEXTRACT FROM timestamp YEAR
What will EXTRACT(HOUR FROM TIMESTAMP '2024-06-01 15:30:00') return?
A2024
B30
C6
D15
Can EXTRACT be used on a DATE type in PostgreSQL?
ANo, only on TIME
BNo, only on TIMESTAMP
CYes, it works on DATE and TIMESTAMP types
DYes, but only for YEAR and MONTH
What is the return type of EXTRACT function?
ADouble precision (numeric)
BInteger
CBoolean
DText
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.