Advertisement
Abelisto

Split timestamp ranges

Aug 5th, 2016
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. with
  2.   t(i,x,y) as (values (1,'2014-03-03'::timestamp, '2016-07-07'::timestamp),(2,'2015-05-05','2015-06-06')),
  3.   u as (
  4.     select
  5.       *,
  6.       generate_series(extract(year from x)::int, extract(year from y)::int) as z
  7.     from
  8.       t)
  9. select
  10.   *,
  11.   tsrange(x,y) * tsrange(make_timestamp(z,1,1,0,0,0), make_timestamp(z+1,1,1,0,0,0))
  12. from u;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement