aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/date.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-12-09 13:30:43 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2022-12-09 13:30:47 -0500
commit2661469d862239ea8b9e3a1cf5352d833f6f0fec (patch)
treeec0c5ac6086a3d1850af80a6e2104b8f0dace218 /src/backend/utils/adt/date.c
parentfc7852c6cb89a5384e0b4ad30874de92f63f88be (diff)
downloadpostgresql-2661469d862239ea8b9e3a1cf5352d833f6f0fec.tar.gz
postgresql-2661469d862239ea8b9e3a1cf5352d833f6f0fec.zip
Allow DateTimeParseError to handle bad-timezone error messages.
Pay down some ancient technical debt (dating to commit 022fd9966): fix a couple of places in datetime parsing that were throwing ereport's immediately instead of returning a DTERR code that could be interpreted by DateTimeParseError. The reason for that was that there was no mechanism for passing any auxiliary data (such as a zone name) to DateTimeParseError, and these errors seemed to really need it. Up to now it didn't matter that much just where the error got thrown, but now we'd like to have a hard policy that datetime parse errors get thrown from just the one place. Hence, invent a "DateTimeErrorExtra" struct that can be used to carry any extra values needed for specific DTERR codes. Perhaps in the future somebody will be motivated to use this to improve the specificity of other DateTimeParseError messages, but for now just deal with the timezone-error cases. This is on the way to making the datetime input functions report parse errors softly; but it's really an independent change, so commit separately. Discussion: https://postgr.es/m/3bbbb0df-7382-bf87-9737-340ba096e034@postgrespro.ru
Diffstat (limited to 'src/backend/utils/adt/date.c')
-rw-r--r--src/backend/utils/adt/date.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c
index 10c11e00db9..3c5a8a69858 100644
--- a/src/backend/utils/adt/date.c
+++ b/src/backend/utils/adt/date.c
@@ -122,13 +122,15 @@ date_in(PG_FUNCTION_ARGS)
char *field[MAXDATEFIELDS];
int ftype[MAXDATEFIELDS];
char workbuf[MAXDATELEN + 1];
+ DateTimeErrorExtra extra;
dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
field, ftype, MAXDATEFIELDS, &nf);
if (dterr == 0)
- dterr = DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp);
+ dterr = DecodeDateTime(field, ftype, nf,
+ &dtype, tm, &fsec, &tzp, &extra);
if (dterr != 0)
- DateTimeParseError(dterr, str, "date");
+ DateTimeParseError(dterr, &extra, str, "date");
switch (dtype)
{
@@ -148,7 +150,7 @@ date_in(PG_FUNCTION_ARGS)
PG_RETURN_DATEADT(date);
default:
- DateTimeParseError(DTERR_BAD_FORMAT, str, "date");
+ DateTimeParseError(DTERR_BAD_FORMAT, &extra, str, "date");
break;
}
@@ -1398,13 +1400,15 @@ time_in(PG_FUNCTION_ARGS)
char *field[MAXDATEFIELDS];
int dtype;
int ftype[MAXDATEFIELDS];
+ DateTimeErrorExtra extra;
dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
field, ftype, MAXDATEFIELDS, &nf);
if (dterr == 0)
- dterr = DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz);
+ dterr = DecodeTimeOnly(field, ftype, nf,
+ &dtype, tm, &fsec, &tz, &extra);
if (dterr != 0)
- DateTimeParseError(dterr, str, "time");
+ DateTimeParseError(dterr, &extra, str, "time");
tm2time(tm, fsec, &result);
AdjustTimeForTypmod(&result, typmod);
@@ -2284,13 +2288,15 @@ timetz_in(PG_FUNCTION_ARGS)
char *field[MAXDATEFIELDS];
int dtype;
int ftype[MAXDATEFIELDS];
+ DateTimeErrorExtra extra;
dterr = ParseDateTime(str, workbuf, sizeof(workbuf),
field, ftype, MAXDATEFIELDS, &nf);
if (dterr == 0)
- dterr = DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec, &tz);
+ dterr = DecodeTimeOnly(field, ftype, nf,
+ &dtype, tm, &fsec, &tz, &extra);
if (dterr != 0)
- DateTimeParseError(dterr, str, "time with time zone");
+ DateTimeParseError(dterr, &extra, str, "time with time zone");
result = (TimeTzADT *) palloc(sizeof(TimeTzADT));
tm2timetz(tm, fsec, tz, result);
@@ -3042,9 +3048,11 @@ timetz_zone(PG_FUNCTION_ARGS)
int tz;
char tzname[TZ_STRLEN_MAX + 1];
char *lowzone;
- int type,
+ int dterr,
+ type,
val;
pg_tz *tzp;
+ DateTimeErrorExtra extra;
/*
* Look up the requested timezone. First we look in the timezone
@@ -3061,7 +3069,9 @@ timetz_zone(PG_FUNCTION_ARGS)
strlen(tzname),
false);
- type = DecodeTimezoneAbbrev(0, lowzone, &val, &tzp);
+ dterr = DecodeTimezoneAbbrev(0, lowzone, &type, &val, &tzp, &extra);
+ if (dterr)
+ DateTimeParseError(dterr, &extra, NULL, NULL);
if (type == TZ || type == DTZ)
{