1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
# name: test/sql/function/timestamp/age.test
# description: Test age function
# group: [timestamp]
# age without second timestamp compares to NOW()
statement ok
SELECT AGE(TIMESTAMP '1957-06-13') t
query T
SELECT AGE(TIMESTAMP '2001-04-10', TIMESTAMP '1957-06-13');
----
43 years 9 months 27 days
query T
SELECT age(TIMESTAMP '2014-04-25', TIMESTAMP '2014-04-17');
----
8 days
query T
SELECT age(TIMESTAMP '2014-04-25', TIMESTAMP '2014-01-01');
----
3 months 24 days
query T
SELECT age(TIMESTAMP '2019-06-11', TIMESTAMP '2019-06-11');
----
00:00:00
query T
SELECT age(TIMESTAMP '2019-06-11', TIMESTAMP '2019-06-11')::VARCHAR;
----
00:00:00
query T
SELECT age(timestamp '2019-06-11 12:00:00', timestamp '2019-07-11 11:00:00');
----
-29 days -23:00:00
statement ok
CREATE TABLE timestamp(t1 TIMESTAMP, t2 TIMESTAMP)
statement ok
INSERT INTO timestamp VALUES('2001-04-10', '1957-06-13')
statement ok
INSERT INTO timestamp VALUES('2014-04-25', '2014-04-17')
statement ok
INSERT INTO timestamp VALUES('2014-04-25','2014-01-01')
statement ok
INSERT INTO timestamp VALUES('2019-06-11', '2019-06-11')
statement ok
INSERT INTO timestamp VALUES(NULL, '2019-06-11')
statement ok
INSERT INTO timestamp VALUES('2019-06-11', NULL)
statement ok
INSERT INTO timestamp VALUES(NULL, NULL)
query T
SELECT AGE(t1, TIMESTAMP '1957-06-13') FROM timestamp;
----
43 years 9 months 27 days
56 years 10 months 12 days
56 years 10 months 12 days
61 years 11 months 28 days
NULL
61 years 11 months 28 days
NULL
query T
SELECT AGE(TIMESTAMP '2001-04-10', t2) FROM timestamp;
----
43 years 9 months 27 days
-13 years -7 days
-12 years -8 months -21 days
-18 years -2 months -1 day
-18 years -2 months -1 day
NULL
NULL
query T
SELECT AGE(t1, t2) FROM timestamp;
----
43 years 9 months 27 days
8 days
3 months 24 days
00:00:00
NULL
NULL
NULL
query T
SELECT t1 - t2 FROM timestamp;
----
16007 days
8 days
114 days
00:00:00
NULL
NULL
NULL
query T
SELECT AGE(t1, t2) FROM timestamp WHERE t1 > '2001-12-12';
----
8 days
3 months 24 days
00:00:00
NULL
query T
SELECT AGE(NULL, NULL);
----
NULL
query T
SELECT AGE(TIMESTAMP '1957-06-13', NULL);
----
NULL
query T
SELECT AGE(NULL, TIMESTAMP '1957-06-13');
----
NULL
# date can also be used with AGE
# hopefully the clock is not off by more than a century
query T
SELECT INTERVAL '1' DAY < AGE(DATE '1900-06-13');
----
1
query T
SELECT AGE(DATE '1900-01-01', DATE '1950-01-01');
----
-50 years
query I
select age(timestamp '1992-01-01 01:01:02.400', timestamp '1992-01-01 01:01:02.200');
----
00:00:00.2
query I
select age(timestamp '1992-01-01 01:01:02.200', timestamp '1992-01-01 01:01:02.400');
----
-00:00:00.2
query I
select age(timestamp '1992-01-01 01:01:01.400', timestamp '1992-01-01 01:01:02.200');
----
-00:00:00.8
#
# Infinities
#
foreach lspecial infinity -infinity
# Unary
query I
SELECT AGE('${lspecial}'::TIMESTAMP);
----
NULL
foreach rspecial infinity -infinity 2004-01-31T12:00:00.000050-08
query I
SELECT AGE('${lspecial}'::TIMESTAMP, '${rspecial}'::TIMESTAMP);
----
NULL
query I
SELECT AGE('${rspecial}'::TIMESTAMP, '${lspecial}'::TIMESTAMP);
----
NULL
endloop
endloop
|