summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane2020-06-04 20:42:08 +0000
committerTom Lane2020-06-04 20:42:23 +0000
commita9632830bb05dc98ae24017cafc652e4a66d44a8 (patch)
tree04cfd1774c957b6998651324ef1d43b5677b26f8 /src/test
parentf5067049cde38cd0d6333a5e3bf1bed8d99e6f44 (diff)
Reject "23:59:60.nnn" in datetime input.
It's intentional that we don't allow values greater than 24 hours, while we do allow "24:00:00" as well as "23:59:60" as inputs. However, the range check was miscoded in such a way that it would accept "23:59:60.nnn" with a nonzero fraction. For time or timetz, the stored result would then be greater than "24:00:00" which would fail dump/reload, not to mention possibly confusing other operations. Fix by explicitly calculating the result and making sure it does not exceed 24 hours. (This calculation is redundant with what will happen later in tm2time or tm2timetz. Maybe someday somebody will find that annoying enough to justify refactoring to avoid the duplication; but that seems too invasive for a back-patched bug fix, and the cost is probably unmeasurable anyway.) Note that this change also rejects such input as the time portion of a timestamp(tz) value. Back-patch to v10. The bug is far older, but to change this pre-v10 we'd need to ensure that the logic behaves sanely with float timestamps, which is possibly nontrivial due to roundoff considerations. Doesn't really seem worth troubling with. Per report from Christoph Berg. Discussion: https://postgr.es/m/20200520125807.GB296739@msg.df7cb.de
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/time.out41
-rw-r--r--src/test/regress/expected/timetz.out41
-rw-r--r--src/test/regress/sql/time.sql10
-rw-r--r--src/test/regress/sql/timetz.sql10
4 files changed, 102 insertions, 0 deletions
diff --git a/src/test/regress/expected/time.out b/src/test/regress/expected/time.out
index 8e0afe69e01..780d7f54557 100644
--- a/src/test/regress/expected/time.out
+++ b/src/test/regress/expected/time.out
@@ -73,6 +73,47 @@ SELECT f1 AS "Eight" FROM TIME_TBL WHERE f1 >= '00:00';
15:36:39
(10 rows)
+-- Check edge cases
+SELECT '23:59:59.999999'::time;
+ time
+-----------------
+ 23:59:59.999999
+(1 row)
+
+SELECT '23:59:59.9999999'::time; -- rounds up
+ time
+----------
+ 24:00:00
+(1 row)
+
+SELECT '23:59:60'::time; -- rounds up
+ time
+----------
+ 24:00:00
+(1 row)
+
+SELECT '24:00:00'::time; -- allowed
+ time
+----------
+ 24:00:00
+(1 row)
+
+SELECT '24:00:00.01'::time; -- not allowed
+ERROR: date/time field value out of range: "24:00:00.01"
+LINE 1: SELECT '24:00:00.01'::time;
+ ^
+SELECT '23:59:60.01'::time; -- not allowed
+ERROR: date/time field value out of range: "23:59:60.01"
+LINE 1: SELECT '23:59:60.01'::time;
+ ^
+SELECT '24:01:00'::time; -- not allowed
+ERROR: date/time field value out of range: "24:01:00"
+LINE 1: SELECT '24:01:00'::time;
+ ^
+SELECT '25:00:00'::time; -- not allowed
+ERROR: date/time field value out of range: "25:00:00"
+LINE 1: SELECT '25:00:00'::time;
+ ^
--
-- TIME simple math
--
diff --git a/src/test/regress/expected/timetz.out b/src/test/regress/expected/timetz.out
index 482a3463b3c..6be408f5282 100644
--- a/src/test/regress/expected/timetz.out
+++ b/src/test/regress/expected/timetz.out
@@ -90,6 +90,47 @@ SELECT f1 AS "Ten" FROM TIMETZ_TBL WHERE f1 >= '00:00-07';
15:36:39-04
(12 rows)
+-- Check edge cases
+SELECT '23:59:59.999999'::timetz;
+ timetz
+--------------------
+ 23:59:59.999999-07
+(1 row)
+
+SELECT '23:59:59.9999999'::timetz; -- rounds up
+ timetz
+-------------
+ 24:00:00-07
+(1 row)
+
+SELECT '23:59:60'::timetz; -- rounds up
+ timetz
+-------------
+ 24:00:00-07
+(1 row)
+
+SELECT '24:00:00'::timetz; -- allowed
+ timetz
+-------------
+ 24:00:00-07
+(1 row)
+
+SELECT '24:00:00.01'::timetz; -- not allowed
+ERROR: date/time field value out of range: "24:00:00.01"
+LINE 1: SELECT '24:00:00.01'::timetz;
+ ^
+SELECT '23:59:60.01'::timetz; -- not allowed
+ERROR: date/time field value out of range: "23:59:60.01"
+LINE 1: SELECT '23:59:60.01'::timetz;
+ ^
+SELECT '24:01:00'::timetz; -- not allowed
+ERROR: date/time field value out of range: "24:01:00"
+LINE 1: SELECT '24:01:00'::timetz;
+ ^
+SELECT '25:00:00'::timetz; -- not allowed
+ERROR: date/time field value out of range: "25:00:00"
+LINE 1: SELECT '25:00:00'::timetz;
+ ^
--
-- TIME simple math
--
diff --git a/src/test/regress/sql/time.sql b/src/test/regress/sql/time.sql
index 99a1562ed23..ea5f8b639f0 100644
--- a/src/test/regress/sql/time.sql
+++ b/src/test/regress/sql/time.sql
@@ -30,6 +30,16 @@ SELECT f1 AS "None" FROM TIME_TBL WHERE f1 < '00:00';
SELECT f1 AS "Eight" FROM TIME_TBL WHERE f1 >= '00:00';
+-- Check edge cases
+SELECT '23:59:59.999999'::time;
+SELECT '23:59:59.9999999'::time; -- rounds up
+SELECT '23:59:60'::time; -- rounds up
+SELECT '24:00:00'::time; -- allowed
+SELECT '24:00:00.01'::time; -- not allowed
+SELECT '23:59:60.01'::time; -- not allowed
+SELECT '24:01:00'::time; -- not allowed
+SELECT '25:00:00'::time; -- not allowed
+
--
-- TIME simple math
--
diff --git a/src/test/regress/sql/timetz.sql b/src/test/regress/sql/timetz.sql
index 2ad4948e850..a1fa4ef3b7f 100644
--- a/src/test/regress/sql/timetz.sql
+++ b/src/test/regress/sql/timetz.sql
@@ -35,6 +35,16 @@ SELECT f1 AS "None" FROM TIMETZ_TBL WHERE f1 < '00:00-07';
SELECT f1 AS "Ten" FROM TIMETZ_TBL WHERE f1 >= '00:00-07';
+-- Check edge cases
+SELECT '23:59:59.999999'::timetz;
+SELECT '23:59:59.9999999'::timetz; -- rounds up
+SELECT '23:59:60'::timetz; -- rounds up
+SELECT '24:00:00'::timetz; -- allowed
+SELECT '24:00:00.01'::timetz; -- not allowed
+SELECT '23:59:60.01'::timetz; -- not allowed
+SELECT '24:01:00'::timetz; -- not allowed
+SELECT '25:00:00'::timetz; -- not allowed
+
--
-- TIME simple math
--