Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
6ca4ea8a
Commit
6ca4ea8a
authored
Sep 06, 2006
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add interval division/multiplication regression tests.
Michael Glaesemann
parent
433caead
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
0 deletions
+101
-0
src/test/regress/expected/interval.out
src/test/regress/expected/interval.out
+66
-0
src/test/regress/sql/interval.sql
src/test/regress/sql/interval.sql
+35
-0
No files found.
src/test/regress/expected/interval.out
View file @
6ca4ea8a
...
...
@@ -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
...
...
src/test/regress/sql/interval.sql
View file @
6ca4ea8a
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment