Skip to content

Conversation

@Mytherin
Copy link
Collaborator

This PR implements the INTERVAL type that can be used to perform offsets on dates. Internally the interval is represented as follows:

struct interval_t {
	int32_t months;
	int32_t days;
	int64_t msecs;
};

Intervals can be constructed using either the postfix syntax:

SELECT INTERVAL '1' MONTH;
SELECT INTERVAL '1' DAY;

Or using a string:

SELECT INTERVAL '1 month 1 day';

Intervals can be used to do date math:

SELECT DATE '1992-01-01' + INTERVAL '1' MONTH;
-- 1992-02-01

Or timestamp math:

SELECT TIMESTAMP '1992-01-01 01:00:00' + INTERVAL '1 month 1 day 30 minutes 20 seconds';
-- 1992-02-02 01:30:20

Intervals can also be added to each other, or subtracted from each other.

SELECT INTERVAL '1' DAY + INTERVAL '1' SECOND;
-- 1 day 00:00:01

Intervals are now also created by the age function, or when subtracting two timestamps from each other.

@Mytherin Mytherin merged commit 7e42c8b into master Jul 24, 2020
@Mytherin Mytherin deleted the interval branch July 24, 2020 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants