I have two timestamps in the table:
usage_from | usage_till
---------------------+--------------------
2013-10-09 23:08:17 | 2013-10-09 23:16:00
2013-10-09 23:08:17 | 2013-10-09 23:08:19
2013-10-09 23:08:17 | 2013-10-10 18:58:22
2013-10-09 23:08:17 | 2013-10-09 23:15:05
2013-10-09 23:08:17 | 2013-10-09 23:09:00
2013-10-09 23:08:17 | 2013-10-09 23:08:20
2013-10-09 23:08:17 | 2013-10-09 23:32:04
2013-10-09 23:08:17 | 2013-10-10 02:02:03
2013-10-09 23:08:17 | 2013-10-10 07:31:00
2013-10-09 23:08:17 | 2013-10-10 22:41:04
This I need to split into as below:
usage_from | usage_till
---------------------+-----------------------
2013-10-09 23:08:17 | 2013-10-09 23:16:00
2013-10-09 23:08:17 | 2013-10-09 23:08:19
2013-10-09 23:08:17 | 2013-10-10 02:00:00
2013-10-10 02:00:00 | 2013-10-10 18:58:22 -- splitted
2013-10-09 23:08:17 | 2013-10-09 23:15:05
2013-10-09 23:08:17 | 2013-10-09 23:09:00
2013-10-09 23:08:17 | 2013-10-09 23:08:20
2013-10-09 23:08:17 | 2013-10-09 23:32:04
2013-10-09 23:08:17 | 2013-10-10 02:00:00
2013-10-10 02:00:00 | 2013-10-10 02:02:03 -- splitted
2013-10-09 23:08:17 | 2013-10-10 02:00:00
2013-10-10 02:00:00 | 2013-10-10 07:31:00 -- splitted
2013-10-09 23:08:17 | 2013-10-10 02:00:00
2013-10-10 02:00:00 | 2013-10-10 22:41:04 -- splitted
Here in the above example I have split the timestamp at 02:00:00.
After many trials I could split it as below, but couldn't split as different row.
usage_from | usage_till | end_time_1 | end_time_2
---------------------+---------------------+---------------------+---------------------
2013-10-09 23:08:17 | 2013-10-09 23:16:00 | 2013-10-09 23:16:00 | 2013-10-11 02:00:00
2013-10-09 23:08:17 | 2013-10-09 23:08:19 | 2013-10-09 23:08:19 | 2013-10-11 02:00:00
2013-10-09 23:08:17 | 2013-10-10 18:58:22 | 2013-10-10 02:00:00 | 2013-10-10 18:58:22
2013-10-09 23:08:17 | 2013-10-09 23:15:05 | 2013-10-09 23:15:05 | 2013-10-11 02:00:00
2013-10-09 23:08:17 | 2013-10-09 23:09:00 | 2013-10-09 23:09:00 | 2013-10-11 02:00:00
2013-10-09 23:08:17 | 2013-10-09 23:08:20 | 2013-10-09 23:08:20 | 2013-10-11 02:00:00
2013-10-09 23:08:17 | 2013-10-09 23:32:04 | 2013-10-09 23:32:04 | 2013-10-11 02:00:00
2013-10-09 23:08:17 | 2013-10-10 02:02:03 | 2013-10-10 02:00:00 | 2013-10-10 02:02:03
2013-10-09 23:08:17 | 2013-10-10 07:31:00 | 2013-10-10 02:00:00 | 2013-10-10 07:31:00
2013-10-09 23:08:17 | 2013-10-10 22:41:04 | 2013-10-10 02:00:00 | 2013-10-10 22:41:04
Any idea how to do this? I have been struggling for the last few days.
I'm using Redshift 1.0.757 (based on PostgreSQL 8.02).