interval
Learning Focus
Use this lesson to represent durations with interval and perform safe time arithmetic.
interval Overview
Intervals represent durations such as "7 days" or "2 hours".
SELECT now() + interval '2 hours';
SELECT now() - interval '30 days';
Example
CREATE TABLE subscriptions (
subscription_id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
period interval NOT NULL
);
What's Next
- Continue to Choosing Appropriate Data Types
- Or return to Date and Time Data Types Overview