1997-04-05 13:08:30 +02:00
|
|
|
CREATE TABLE TINTERVAL_TBL (f1 tinterval);
|
|
|
|
|
|
|
|
INSERT INTO TINTERVAL_TBL (f1)
|
|
|
|
VALUES ('["-infinity" "infinity"]');
|
|
|
|
|
|
|
|
INSERT INTO TINTERVAL_TBL (f1)
|
1997-06-01 04:30:25 +02:00
|
|
|
VALUES ('["May 10, 1947 23:59:12" "Jan 14, 1973 03:14:21"]');
|
1997-04-05 13:08:30 +02:00
|
|
|
|
|
|
|
INSERT INTO TINTERVAL_TBL (f1)
|
|
|
|
VALUES ('["Sep 4, 1983 23:59:12" "Oct 4, 1983 23:59:12"]');
|
|
|
|
|
|
|
|
INSERT INTO TINTERVAL_TBL (f1)
|
|
|
|
VALUES ('["epoch" "Mon May 1 00:30:30 1995"]');
|
|
|
|
|
|
|
|
INSERT INTO TINTERVAL_TBL (f1)
|
|
|
|
VALUES ('["Feb 15 1990 12:15:03" "current"]');
|
|
|
|
|
|
|
|
|
|
|
|
-- badly formatted tintervals
|
|
|
|
INSERT INTO TINTERVAL_TBL (f1)
|
|
|
|
VALUES ('["bad time specifications" ""]');
|
|
|
|
|
|
|
|
INSERT INTO TINTERVAL_TBL (f1)
|
|
|
|
VALUES ('["" "infinity"]');
|
|
|
|
|
|
|
|
-- test tinterval operators
|
|
|
|
|
|
|
|
SELECT '' AS seven, TINTERVAL_TBL.*;
|
|
|
|
|
|
|
|
-- length ==
|
|
|
|
SELECT '' AS one, t.*
|
|
|
|
FROM TINTERVAL_TBL t
|
|
|
|
WHERE t.f1 #= '@ 1 months';
|
|
|
|
|
|
|
|
-- length <>
|
|
|
|
SELECT '' AS three, t.*
|
|
|
|
FROM TINTERVAL_TBL t
|
|
|
|
WHERE t.f1 #<> '@ 1 months';
|
|
|
|
|
|
|
|
-- length <
|
|
|
|
SELECT '' AS zero, t.*
|
|
|
|
FROM TINTERVAL_TBL t
|
|
|
|
WHERE t.f1 #< '@ 1 month';
|
|
|
|
|
|
|
|
-- length <=
|
|
|
|
SELECT '' AS one, t.*
|
|
|
|
FROM TINTERVAL_TBL t
|
|
|
|
WHERE t.f1 #<= '@ 1 month';
|
|
|
|
|
|
|
|
-- length >
|
|
|
|
SELECT '' AS three, t.*
|
|
|
|
FROM TINTERVAL_TBL t
|
|
|
|
WHERE t.f1 #> '@ 1 year';
|
|
|
|
|
|
|
|
-- length >=
|
|
|
|
SELECT '' AS three, t.*
|
|
|
|
FROM TINTERVAL_TBL t
|
|
|
|
WHERE t.f1 #>= '@ 3 years';
|
|
|
|
|
|
|
|
-- overlaps
|
|
|
|
SELECT '' AS three, t1.*
|
|
|
|
FROM TINTERVAL_TBL t1
|
|
|
|
WHERE t1.f1 &&
|
|
|
|
'["Aug 15 14:23:19 1983" "Sep 16 14:23:19 1983"]'::tinterval;
|
|
|
|
|
1997-05-11 17:42:09 +02:00
|
|
|
SET geqo TO 'off';
|
|
|
|
|
|
|
|
SELECT '' AS five, t1.f1, t2.f1
|
1997-04-05 13:08:30 +02:00
|
|
|
FROM TINTERVAL_TBL t1, TINTERVAL_TBL t2
|
|
|
|
WHERE t1.f1 && t2.f1 and
|
1997-05-11 17:42:09 +02:00
|
|
|
t1.f1 = t2.f1
|
|
|
|
ORDER BY t1.f1, t2.f1;
|
1997-04-05 13:08:30 +02:00
|
|
|
|
1997-05-11 17:42:09 +02:00
|
|
|
SELECT '' AS fourteen, t1.f1 AS interval1, t2.f1 AS interval2
|
1997-04-05 13:08:30 +02:00
|
|
|
FROM TINTERVAL_TBL t1, TINTERVAL_TBL t2
|
1997-05-11 17:42:09 +02:00
|
|
|
WHERE t1.f1 && t2.f1 and not t1.f1 = t2.f1
|
|
|
|
ORDER BY interval1, interval2;
|
1997-04-05 13:08:30 +02:00
|
|
|
|
|
|
|
-- contains
|
1997-05-11 17:42:09 +02:00
|
|
|
SELECT '' AS five, t1.f1
|
1997-04-05 13:08:30 +02:00
|
|
|
FROM TINTERVAL_TBL t1
|
|
|
|
WHERE not t1.f1 <<
|
1997-05-11 17:42:09 +02:00
|
|
|
'["Aug 15 14:23:19 1980" "Sep 16 14:23:19 1990"]'::tinterval
|
|
|
|
ORDER BY t1.f1;
|
1997-04-05 13:08:30 +02:00
|
|
|
|
|
|
|
-- make time interval
|
1997-05-11 17:42:09 +02:00
|
|
|
SELECT '' AS three, t1.f1
|
1997-04-05 13:08:30 +02:00
|
|
|
FROM TINTERVAL_TBL t1
|
|
|
|
WHERE t1.f1 &&
|
|
|
|
('Aug 15 14:23:19 1983'::abstime <#>
|
1997-05-11 17:42:09 +02:00
|
|
|
'Sep 16 14:23:19 1983'::abstime)
|
|
|
|
ORDER BY t1.f1;
|
|
|
|
|
|
|
|
RESET geqo;
|
1997-04-05 13:08:30 +02:00
|
|
|
|