aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/adt/datetime.c2
-rw-r--r--src/test/regress/expected/interval.out5
-rw-r--r--src/test/regress/sql/interval.sql3
3 files changed, 9 insertions, 1 deletions
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index d1666138958..b74889039d8 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -3376,7 +3376,7 @@ DecodeInterval(char **field, int *ftype, int nf, int range,
* to dump in postgres style, not SQL style.)
*----------
*/
- if (IntervalStyle == INTSTYLE_SQL_STANDARD && *field[0] == '-')
+ if (IntervalStyle == INTSTYLE_SQL_STANDARD && nf > 0 && *field[0] == '-')
{
force_negative = true;
/* Check for additional explicit signs */
diff --git a/src/test/regress/expected/interval.out b/src/test/regress/expected/interval.out
index 579e92e7b39..c7ac408bec8 100644
--- a/src/test/regress/expected/interval.out
+++ b/src/test/regress/expected/interval.out
@@ -888,6 +888,11 @@ SELECT interval '-23 hours 45 min 12.34 sec',
-23:45:12.34 | -1 23:45:12.34 | -1-2 -1 -23:45:12.34 | -0-10 +1 +23:45:12.34
(1 row)
+-- edge case for sign-matching rules
+SELECT interval ''; -- error
+ERROR: invalid input syntax for type interval: ""
+LINE 1: SELECT interval '';
+ ^
-- test outputting iso8601 intervals
SET IntervalStyle to iso_8601;
select interval '0' AS "zero",
diff --git a/src/test/regress/sql/interval.sql b/src/test/regress/sql/interval.sql
index 0517b5b82bd..54745c40d6d 100644
--- a/src/test/regress/sql/interval.sql
+++ b/src/test/regress/sql/interval.sql
@@ -284,6 +284,9 @@ SELECT interval '-23 hours 45 min 12.34 sec',
interval '-1 year 2 months 1 day 23 hours 45 min 12.34 sec',
interval '-1 year 2 months 1 day 23 hours 45 min +12.34 sec';
+-- edge case for sign-matching rules
+SELECT interval ''; -- error
+
-- test outputting iso8601 intervals
SET IntervalStyle to iso_8601;
select interval '0' AS "zero",