Recall & Review
beginner
What is the
interval type used for in PostgreSQL?The
interval type stores a duration of time, like days, hours, minutes, or seconds, representing a span between two points in time.Click to reveal answer
beginner
How do you create an interval of 3 days in PostgreSQL?
You can write
INTERVAL '3 days' to represent a duration of three days.Click to reveal answer
beginner
Can you add an interval to a timestamp in PostgreSQL? Give an example.
Yes. For example,
SELECT timestamp '2024-06-01 10:00' + INTERVAL '2 hours'; adds 2 hours to the timestamp.Click to reveal answer
intermediate
What units can you use inside an interval literal in PostgreSQL?
You can use units like years, months, days, hours, minutes, seconds, and combinations like '1 year 2 months 3 days'.
Click to reveal answer
advanced
How does PostgreSQL store intervals internally?
PostgreSQL stores intervals as three parts: months, days, and microseconds, allowing flexible representation of durations.
Click to reveal answer
Which of these is a valid interval literal in PostgreSQL?
✗ Incorrect
The correct syntax is INTERVAL followed by a quoted string with the duration, like INTERVAL '5 hours 30 minutes'.
What does
SELECT INTERVAL '1 day' + INTERVAL '2 hours'; return?✗ Incorrect
Adding two intervals results in a combined interval representing the total duration.
How do you subtract 30 minutes from a timestamp in PostgreSQL?
✗ Incorrect
You subtract an interval literal from a timestamp to reduce the time by that duration.
Which part is NOT stored separately inside a PostgreSQL interval?
✗ Incorrect
Years are converted into months internally; PostgreSQL stores months, days, and microseconds separately.
What happens if you add an interval to a date in PostgreSQL?
✗ Incorrect
Adding an interval to a date shifts the date by that duration, returning a new date.
Explain what the PostgreSQL interval type is and how you can use it with timestamps.
Think about how you tell time differences or add time in real life.
You got /4 concepts.
Describe the internal storage structure of PostgreSQL intervals and why it matters.
Consider how different units of time are handled inside the database.
You got /4 concepts.