SET log_error_verbosity = verbose;
drop table if exists r;
--
-- Testing TIMESTAMP...
--
create table r 
(
	a int, 
	ts timestamp, 
	te timestamp
);
insert into r values 
(0, '2000-01-01', '2000-01-10'), 
(1, '2000-01-05', '2000-01-20');
select a, ts, te from (r normalize r as r2 on r.a = 0 with(ts,te,ts,te)) c;
 a |         ts          |         te          
---+---------------------+---------------------
 0 | 2000-01-01 00:00:00 | 2000-01-05 00:00:00
 0 | 2000-01-05 00:00:00 | 2000-01-10 00:00:00
 1 | 2000-01-05 00:00:00 | 2000-01-20 00:00:00
(3 rows)

select a, ts, te from (r align r as r2 on r.a = 0 with(ts,te,ts,te)) c;
 a |         ts          |         te          
---+---------------------+---------------------
 0 | 2000-01-01 00:00:00 | 2000-01-10 00:00:00
 0 | 2000-01-05 00:00:00 | 2000-01-10 00:00:00
 1 | 2000-01-05 00:00:00 | 2000-01-20 00:00:00
(3 rows)

--
-- Testing DOUBLE PRECISION...
--
drop table r;
create table r 
(
	a int, 
	ts double precision, 
	te double precision
);
insert into r values 
(0, 1.0, 1.1111), 
(1, 1.11109999, 2.0);
select a, ts, te from (r normalize r as r2 on r.a = 0 with(ts,te,ts,te)) c;
 a |     ts     |     te     
---+------------+------------
 0 |          1 | 1.11109999
 0 | 1.11109999 |     1.1111
 1 | 1.11109999 |          2
(3 rows)

select a, ts, te from (r align r as r2 on r.a = 0 with(ts,te,ts,te)) c;
 a |     ts     |   te   
---+------------+--------
 0 |          1 | 1.1111
 0 | 1.11109999 | 1.1111
 1 | 1.11109999 |      2
(3 rows)

-- NOT IMPLEMENTED YET! See documentation wiki...
--update r set ts='NaN' where a = 1; 
--select a, ts, te from (r normalize r as r2 on true with(ts,te,ts,te)) c;
--select a, ts, te from (r align r as r2 on true with(ts,te,ts,te)) c;
update r set ts='-Infinity' where a = 1; 
update r set te='Infinity' where a = 0; 
table r;
 a |    ts     |    te    
---+-----------+----------
 1 | -Infinity |        2
 0 |         1 | Infinity
(2 rows)

select a, ts, te from (r normalize r as r2 on true with(ts,te,ts,te)) c;
 a |    ts     |    te    
---+-----------+----------
 1 | -Infinity |        1
 1 |         1 |        2
 0 |         1 |        2
 0 |         2 | Infinity
(4 rows)

select a, ts, te from (r align r as r2 on true with(ts,te,ts,te)) c;
 a |    ts     |    te    
---+-----------+----------
 1 | -Infinity |        2
 1 |         1 |        2
 0 |         1 |        2
 0 |         1 | Infinity
(4 rows)

