diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-08-03 17:39:39 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-08-03 17:40:43 -0400 |
commit | 3152bf722fe334b70281256dbb74d9cb1e3643e1 (patch) | |
tree | afacae58a2711c33843708648c57202406387f14 /src/backend/utils/adt/datetime.c | |
parent | 95e750520c47416554765a508b280f96802ff54f (diff) | |
download | postgresql-3152bf722fe334b70281256dbb74d9cb1e3643e1.tar.gz postgresql-3152bf722fe334b70281256dbb74d9cb1e3643e1.zip |
Fix bugs with parsing signed hh:mm and hh:mm:ss fields in interval input.
DecodeInterval() failed to honor the "range" parameter (the special SQL
syntax for indicating which fields appear in the literal string) if the
time was signed. This seems inappropriate, so make it work like the
not-signed case. The inconsistency was introduced in my commit
f867339c0148381eb1d01f93ab5c79f9d10211de, which as noted in its log message
was only really focused on making SQL-compliant literals work per spec.
Including a sign here is not per spec, but if we're going to allow it
then it's reasonable to expect it to work like the not-signed case.
Also, remove bogus setting of tmask, which caused subsequent processing to
think that what had been given was a timezone and not an hh:mm(:ss) field,
thus confusing checks for redundant fields. This seems to be an aboriginal
mistake in Lockhart's commit 2cf1642461536d0d8f3a1cf124ead0eac04eb760.
Add regression test cases to illustrate the changed behaviors.
Back-patch as far as 8.4, where support for spec-compliant interval
literals was added.
Range problem reported and diagnosed by Amit Kapila, tmask problem by me.
Diffstat (limited to 'src/backend/utils/adt/datetime.c')
-rw-r--r-- | src/backend/utils/adt/datetime.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index 1c2c39b2e27..26c6742e8b1 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -2873,19 +2873,18 @@ DecodeInterval(char **field, int *ftype, int nf, int range, case DTK_TZ: /* - * Timezone is a token with a leading sign character and at + * Timezone means a token with a leading sign character and at * least one digit; there could be ':', '.', '-' embedded in * it as well. */ Assert(*field[i] == '-' || *field[i] == '+'); /* - * Try for hh:mm or hh:mm:ss. If not, fall through to - * DTK_NUMBER case, which can handle signed float numbers and - * signed year-month values. + * Check for signed hh:mm or hh:mm:ss. If so, process exactly + * like DTK_TIME case above, plus handling the sign. */ if (strchr(field[i] + 1, ':') != NULL && - DecodeTime(field[i] + 1, fmask, INTERVAL_FULL_RANGE, + DecodeTime(field[i] + 1, fmask, range, &tmask, tm, fsec) == 0) { if (*field[i] == '-') @@ -2903,9 +2902,14 @@ DecodeInterval(char **field, int *ftype, int nf, int range, * are reading right to left. */ type = DTK_DAY; - tmask = DTK_M(TZ); break; } + + /* + * Otherwise, fall through to DTK_NUMBER case, which can + * handle signed float numbers and signed year-month values. + */ + /* FALL THROUGH */ case DTK_DATE: |