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).
SELECT version()output.PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.757