/**************************************************************************************/
/* File:        demo02                                                                */
/* Project:     TimeDB 2.0 : Spans, Intervals and Events                              */
/* Author:      Andreas Steiner                                                       */
/* Date:        29-06-1998                                                            */
/* Results:                                                                           */
/**************************************************************************************/

create table timeTable(s interval, i period, e date);

insert into timeTable 
  values (interval 3 year 2 month, period [1989-1991), date '1970-01-01');
insert into timeTable 
  values (interval 2 month 3 minute, period [1989-1991), date '1989-06-12');
insert into timeTable 
  values (interval 2 second, period [1989-1991), date '1989-06-12');
  
  
select * from timeTable;


/* Operations including spans, events and intervals : */

select a1.s + a2.s
from timeTable a1, timeTable a2;

select a1.s - a2.s
from timeTable a1, timeTable a2;

select 2 * a1.s
from timeTable a1;

select a1.s / 2
from timeTable a1;

select a1.e + a2.s
from timeTable a1, timeTable a2;

select a1.e - a2.s
from timeTable a1, timeTable a2;


/* Comparison operations including spans, events and intervals : */
 
select *
from   timeTable a1, timeTable a2
where  a1.i = a2.i;

select *
from   timeTable a1, timeTable a2
where  a1.i precedes a2.i;

select *
from   timeTable a1, timeTable a2
where  a1.i overlaps a2.i;

select *
from   timeTable a1, timeTable a2
where  a1.i meets a2.i;

select *
from   timeTable a1, timeTable a2
where  a1.i contains a2.i;


select *
from   timeTable a1, timeTable a2
where  a1.i contains a2.e;

select *
from   timeTable a1, timeTable a2
where  a1.i precedes a2.e;


select *
from   timeTable a1, timeTable a2
where  a1.e = a2.e;

select *
from   timeTable a1, timeTable a2
where  a1.e precedes a2.e;

select *
from   timeTable a1, timeTable a2
where  a1.e precedes a2.i;


drop table timeTable;
