@@ -694,20 +694,66 @@ SELECT '' as "54", d1 as timestamp,
694
694
--
695
695
-- abstime, reltime arithmetic
696
696
--
697
- SELECT '' AS four, f1 AS abstime,
698
- date_part('year', f1) AS year, date_part('month', f1) AS month,
699
- date_part('day',f1) AS day, date_part('hour', f1) AS hour,
700
- date_part('minute', f1) AS minute, date_part('second', f1) AS second
701
- FROM ABSTIME_TBL
702
- WHERE isfinite(f1) and f1 <> abstime 'current'
703
- ORDER BY abstime;
704
- four | abstime | year | month | day | hour | minute | second
705
- ------+------------------------------+------+-------+-----+------+--------+--------
706
- | Sat May 10 23:59:12 1947 PDT | 1947 | 5 | 10 | 23 | 59 | 12
707
- | epoch | 1969 | 12 | 31 | 16 | 0 | 0
708
- | Sun Jan 14 03:14:21 1973 PST | 1973 | 1 | 14 | 3 | 14 | 21
709
- | Mon May 01 00:30:30 1995 PDT | 1995 | 5 | 1 | 0 | 30 | 30
710
- (4 rows)
697
+ SELECT '' AS ten, ABSTIME_TBL.f1 AS abstime, RELTIME_TBL.f1 AS reltime
698
+ WHERE (ABSTIME_TBL.f1 + RELTIME_TBL.f1)
699
+ < abstime 'Jan 14 14:00:00 1971'
700
+ ORDER BY abstime, reltime;
701
+ ten | abstime | reltime
702
+ -----+------------------------------+---------------
703
+ | Sat May 10 23:59:12 1947 PDT | @ 14 secs ago
704
+ | Sat May 10 23:59:12 1947 PDT | @ 1 min
705
+ | Sat May 10 23:59:12 1947 PDT | @ 5 hours
706
+ | Sat May 10 23:59:12 1947 PDT | @ 10 days
707
+ | Sat May 10 23:59:12 1947 PDT | @ 3 mons
708
+ | epoch | @ 14 secs ago
709
+ | epoch | @ 1 min
710
+ | epoch | @ 5 hours
711
+ | epoch | @ 10 days
712
+ | epoch | @ 3 mons
713
+ (10 rows)
714
+
715
+ -- these four queries should return the same answer
716
+ -- the "infinity" and "-infinity" tuples in ABSTIME_TBL cannot be added and
717
+ -- therefore, should not show up in the results.
718
+ SELECT '' AS three, ABSTIME_TBL.*
719
+ WHERE (ABSTIME_TBL.f1 + reltime '@ 3 year') -- +3 years
720
+ < abstime 'Jan 14 14:00:00 1977';
721
+ three | f1
722
+ -------+------------------------------
723
+ | Sun Jan 14 03:14:21 1973 PST
724
+ | epoch
725
+ | Sat May 10 23:59:12 1947 PDT
726
+ (3 rows)
727
+
728
+ SELECT '' AS three, ABSTIME_TBL.*
729
+ WHERE (ABSTIME_TBL.f1 + reltime '@ 3 year ago') -- -3 years
730
+ < abstime 'Jan 14 14:00:00 1971';
731
+ three | f1
732
+ -------+------------------------------
733
+ | Sun Jan 14 03:14:21 1973 PST
734
+ | epoch
735
+ | Sat May 10 23:59:12 1947 PDT
736
+ (3 rows)
737
+
738
+ SELECT '' AS three, ABSTIME_TBL.*
739
+ WHERE (ABSTIME_TBL.f1 - reltime '@ 3 year') -- -(+3) years
740
+ < abstime 'Jan 14 14:00:00 1971';
741
+ three | f1
742
+ -------+------------------------------
743
+ | Sun Jan 14 03:14:21 1973 PST
744
+ | epoch
745
+ | Sat May 10 23:59:12 1947 PDT
746
+ (3 rows)
747
+
748
+ SELECT '' AS three, ABSTIME_TBL.*
749
+ WHERE (ABSTIME_TBL.f1 - reltime '@ 3 year ago') -- -(-3) years
750
+ < abstime 'Jan 14 14:00:00 1977';
751
+ three | f1
752
+ -------+------------------------------
753
+ | Sun Jan 14 03:14:21 1973 PST
754
+ | epoch
755
+ | Sat May 10 23:59:12 1947 PDT
756
+ (3 rows)
711
757
712
758
--
713
759
-- Conversions
0 commit comments