Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6ca4ea8

Browse files
committed
Add interval division/multiplication regression tests.
Michael Glaesemann
1 parent433caea commit6ca4ea8

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

‎src/test/regress/expected/interval.out

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,72 @@ SELECT '' AS fortyfive, r1.*, r2.*
208208
| 34 years | 6 years
209209
(45 rows)
210210

211+
-- Test multiplication and division with intervals.
212+
-- Floating point arithmetic rounding errors can lead to unexpected results,
213+
-- though the code attempts to do the right thing and round up to days and
214+
-- minutes to avoid results such as '3 days 24:00 hours' or '14:20:60'.
215+
-- Note that it is expected for some day components to be greater than 29 and
216+
-- some time components be greater than 23:59:59 due to how intervals are
217+
-- stored internally.
218+
CREATE TABLE INTERVAL_MULDIV_TBL (span interval);
219+
COPY INTERVAL_MULDIV_TBL FROM STDIN;
220+
SELECT span * 0.3 AS product
221+
FROM INTERVAL_MULDIV_TBL;
222+
product
223+
------------------------------------
224+
1 year 12 days 122:24:00
225+
-1 years -12 days +93:36:00
226+
-3 days -14:24:00
227+
2 mons 13 days 01:22:28.80
228+
-10 mons +120 days 37:28:21.6567
229+
1 mon 6 days
230+
4 mons 6 days
231+
24 years 11 mons 320 days 16:48:00
232+
(8 rows)
233+
234+
SELECT span * 8.2 AS product
235+
FROM INTERVAL_MULDIV_TBL;
236+
product
237+
---------------------------------------------
238+
28 years 104 days 2961:36:00
239+
-28 years -104 days +2942:24:00
240+
-98 days -09:36:00
241+
6 years 1 mon -197 days +93:34:27.20
242+
-24 years -7 mons +3946 days 640:15:11.9498
243+
2 years 8 mons 24 days
244+
9 years 6 mons 24 days
245+
682 years 7 mons 8215 days 19:12:00
246+
(8 rows)
247+
248+
SELECT span / 10 AS quotient
249+
FROM INTERVAL_MULDIV_TBL;
250+
quotient
251+
----------------------------------
252+
4 mons 4 days 40:48:00
253+
-4 mons -4 days +31:12:00
254+
-1 days -04:48:00
255+
25 days -15:32:30.40
256+
-3 mons +30 days 12:29:27.2189
257+
12 days
258+
1 mon 12 days
259+
8 years 3 mons 126 days 21:36:00
260+
(8 rows)
261+
262+
SELECT span / 100 AS quotient
263+
FROM INTERVAL_MULDIV_TBL;
264+
quotient
265+
-------------------------
266+
12 days 13:40:48
267+
-12 days -06:28:48
268+
-02:52:48
269+
2 days 10:26:44.96
270+
-6 days +01:14:56.72189
271+
1 day 04:48:00
272+
4 days 04:48:00
273+
9 mons 39 days 16:33:36
274+
(8 rows)
275+
276+
DROP TABLE INTERVAL_MULDIV_TBL;
211277
SET DATESTYLE = 'postgres';
212278
SELECT '' AS ten, * FROM INTERVAL_TBL;
213279
ten | f1

‎src/test/regress/sql/interval.sql

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,41 @@ SELECT '' AS fortyfive, r1.*, r2.*
5959
WHEREr1.f1>r2.f1
6060
ORDER BYr1.f1,r2.f1;
6161

62+
63+
-- Test multiplication and division with intervals.
64+
-- Floating point arithmetic rounding errors can lead to unexpected results,
65+
-- though the code attempts to do the right thing and round up to days and
66+
-- minutes to avoid results such as '3 days 24:00 hours' or '14:20:60'.
67+
-- Note that it is expected for some day components to be greater than 29 and
68+
-- some time components be greater than 23:59:59 due to how intervals are
69+
-- stored internally.
70+
71+
CREATETABLEINTERVAL_MULDIV_TBL (span interval);
72+
COPY INTERVAL_MULDIV_TBLFROM STDIN;
73+
41 mon12 days360:00
74+
-41 mon-12 days+360:00
75+
-12 days
76+
9 mon-27 days12:34:56
77+
-3 years482 days76:54:32.189
78+
4 mon
79+
14 mon
80+
999 mon999 days
81+
\.
82+
83+
SELECT span*0.3AS product
84+
FROM INTERVAL_MULDIV_TBL;
85+
86+
SELECT span*8.2AS product
87+
FROM INTERVAL_MULDIV_TBL;
88+
89+
SELECT span/10AS quotient
90+
FROM INTERVAL_MULDIV_TBL;
91+
92+
SELECT span/100AS quotient
93+
FROM INTERVAL_MULDIV_TBL;
94+
95+
DROPTABLE INTERVAL_MULDIV_TBL;
96+
6297
SET DATESTYLE='postgres';
6398

6499
SELECT''AS ten,*FROM INTERVAL_TBL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp