diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-09-11 15:27:30 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-09-11 15:27:30 +0000 |
commit | 70530c808bf8eaba2a41a28c9dc7b96dcc3b6c51 (patch) | |
tree | 906083f6ff70cf8d34accf93c4533645d3c3a773 /src/backend/utils/adt/datetime.c | |
parent | d53a56687f3d4772d17ffa0013a33231b7163731 (diff) | |
download | postgresql-70530c808bf8eaba2a41a28c9dc7b96dcc3b6c51.tar.gz postgresql-70530c808bf8eaba2a41a28c9dc7b96dcc3b6c51.zip |
Adjust the parser to accept the typename syntax INTERVAL ... SECOND(n)
and the literal syntax INTERVAL 'string' ... SECOND(n), as required by the
SQL standard. Our old syntax put (n) directly after INTERVAL, which was
a mistake, but will still be accepted for backward compatibility as well
as symmetry with the TIMESTAMP cases.
Change intervaltypmodout to show it in the spec's way, too. (This could
potentially affect clients, if there are any that analyze the typmod of an
INTERVAL in any detail.)
Also fix interval input to handle 'min:sec.frac' properly; I had overlooked
this case in my previous patch.
Document the use of the interval fields qualifier, which up to now we had
never mentioned in the docs. (I think the omission was intentional because
it didn't work per spec; but it does now, or at least close enough to be
credible.)
Diffstat (limited to 'src/backend/utils/adt/datetime.c')
-rw-r--r-- | src/backend/utils/adt/datetime.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index 6712d6d8d44..a1cf2b4ed54 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.191 2008/09/10 18:29:41 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.192 2008/09/11 15:27:30 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -2256,9 +2256,25 @@ DecodeTime(char *str, int fmask, int range, tm->tm_hour = 0; } } - else if (*cp != ':') - return DTERR_BAD_FORMAT; - else + else if (*cp == '.') + { + /* always assume mm:ss.sss is MINUTE TO SECOND */ + double frac; + + str = cp; + frac = strtod(str, &cp); + if (*cp != '\0') + return DTERR_BAD_FORMAT; +#ifdef HAVE_INT64_TIMESTAMP + *fsec = rint(frac * 1000000); +#else + *fsec = frac; +#endif + tm->tm_sec = tm->tm_min; + tm->tm_min = tm->tm_hour; + tm->tm_hour = 0; + } + else if (*cp == ':') { str = cp + 1; errno = 0; @@ -2284,6 +2300,8 @@ DecodeTime(char *str, int fmask, int range, else return DTERR_BAD_FORMAT; } + else + return DTERR_BAD_FORMAT; /* do a sanity check */ #ifdef HAVE_INT64_TIMESTAMP |