Add interval division/multiplication regression tests.

Michael Glaesemann
This commit is contained in:
Bruce Momjian 2006-09-06 02:05:41 +00:00
parent 433caead84
commit 6ca4ea8a80
2 changed files with 101 additions and 0 deletions

View File

@ -208,6 +208,72 @@ SELECT '' AS fortyfive, r1.*, r2.*
| 34 years | 6 years
(45 rows)
-- Test multiplication and division with intervals.
-- Floating point arithmetic rounding errors can lead to unexpected results,
-- though the code attempts to do the right thing and round up to days and
-- minutes to avoid results such as '3 days 24:00 hours' or '14:20:60'.
-- Note that it is expected for some day components to be greater than 29 and
-- some time components be greater than 23:59:59 due to how intervals are
-- stored internally.
CREATE TABLE INTERVAL_MULDIV_TBL (span interval);
COPY INTERVAL_MULDIV_TBL FROM STDIN;
SELECT span * 0.3 AS product
FROM INTERVAL_MULDIV_TBL;
product
------------------------------------
1 year 12 days 122:24:00
-1 years -12 days +93:36:00
-3 days -14:24:00
2 mons 13 days 01:22:28.80
-10 mons +120 days 37:28:21.6567
1 mon 6 days
4 mons 6 days
24 years 11 mons 320 days 16:48:00
(8 rows)
SELECT span * 8.2 AS product
FROM INTERVAL_MULDIV_TBL;
product
---------------------------------------------
28 years 104 days 2961:36:00
-28 years -104 days +2942:24:00
-98 days -09:36:00
6 years 1 mon -197 days +93:34:27.20
-24 years -7 mons +3946 days 640:15:11.9498
2 years 8 mons 24 days
9 years 6 mons 24 days
682 years 7 mons 8215 days 19:12:00
(8 rows)
SELECT span / 10 AS quotient
FROM INTERVAL_MULDIV_TBL;
quotient
----------------------------------
4 mons 4 days 40:48:00
-4 mons -4 days +31:12:00
-1 days -04:48:00
25 days -15:32:30.40
-3 mons +30 days 12:29:27.2189
12 days
1 mon 12 days
8 years 3 mons 126 days 21:36:00
(8 rows)
SELECT span / 100 AS quotient
FROM INTERVAL_MULDIV_TBL;
quotient
-------------------------
12 days 13:40:48
-12 days -06:28:48
-02:52:48
2 days 10:26:44.96
-6 days +01:14:56.72189
1 day 04:48:00
4 days 04:48:00
9 mons 39 days 16:33:36
(8 rows)
DROP TABLE INTERVAL_MULDIV_TBL;
SET DATESTYLE = 'postgres';
SELECT '' AS ten, * FROM INTERVAL_TBL;
ten | f1

View File

@ -59,6 +59,41 @@ SELECT '' AS fortyfive, r1.*, r2.*
WHERE r1.f1 > r2.f1
ORDER BY r1.f1, r2.f1;
-- Test multiplication and division with intervals.
-- Floating point arithmetic rounding errors can lead to unexpected results,
-- though the code attempts to do the right thing and round up to days and
-- minutes to avoid results such as '3 days 24:00 hours' or '14:20:60'.
-- Note that it is expected for some day components to be greater than 29 and
-- some time components be greater than 23:59:59 due to how intervals are
-- stored internally.
CREATE TABLE INTERVAL_MULDIV_TBL (span interval);
COPY INTERVAL_MULDIV_TBL FROM STDIN;
41 mon 12 days 360:00
-41 mon -12 days +360:00
-12 days
9 mon -27 days 12:34:56
-3 years 482 days 76:54:32.189
4 mon
14 mon
999 mon 999 days
\.
SELECT span * 0.3 AS product
FROM INTERVAL_MULDIV_TBL;
SELECT span * 8.2 AS product
FROM INTERVAL_MULDIV_TBL;
SELECT span / 10 AS quotient
FROM INTERVAL_MULDIV_TBL;
SELECT span / 100 AS quotient
FROM INTERVAL_MULDIV_TBL;
DROP TABLE INTERVAL_MULDIV_TBL;
SET DATESTYLE = 'postgres';
SELECT '' AS ten, * FROM INTERVAL_TBL;