Created
January 12, 2018 16:25
-
-
Save ddrscott/44c6007a167fce6e6797208b0cffb67b to your computer and use it in GitHub Desktop.
Demonstration of OVERLAPS keyword vs checking date range with `>=` and `<=`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| t1.*, | |
| (start_date, end_date) overlaps (range_start, range_end) as overlaps_func, | |
| (start_date <= range_end) AND (end_date >= range_start) as overlap_bool | |
| FROM generate_series('2016-12-01'::date, '2017-03-10'::date, '1 day'::interval) as gs(date) | |
| JOIN LATERAL ( | |
| SELECT | |
| '2017-01-01'::date start_date, | |
| '2017-01-15'::date end_date, | |
| (gs.date::date - '30 day'::interval)::date range_start, | |
| gs.date::date range_end | |
| ) AS t1 ON true | |
| ORDER BY 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment