SHARE
TWEET

Split timestamp ranges

Abelisto Aug 5th, 2016 (edited) 88 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;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top