From 469745468668917434dbef48eddad4f961880b3d Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Sat, 10 Feb 2024 12:12:39 -0500 Subject: Disallow jsonpath methods involving TZ in immutable functions Timezones are not immutable and so neither is any function that relies on them. In commit 66ea94e8, we introduced a few methods which do casting from one time to another and thus may involve the current timezone. To preserve the immutability of jsonpath functions currently marked immutable, disallow these methods from being called from non-TZ aware functions. Jeevan Chalke, per a report from Jian He. --- src/backend/utils/adt/jsonpath_exec.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/backend/utils/adt/jsonpath_exec.c') diff --git a/src/backend/utils/adt/jsonpath_exec.c b/src/backend/utils/adt/jsonpath_exec.c index 573b6ce2ba7..8372863de74 100644 --- a/src/backend/utils/adt/jsonpath_exec.c +++ b/src/backend/utils/adt/jsonpath_exec.c @@ -268,6 +268,8 @@ static JsonbValue *getScalar(JsonbValue *scalar, enum jbvType type); static JsonbValue *wrapItemsInArray(const JsonValueList *items); static int compareDatetime(Datum val1, Oid typid1, Datum val2, Oid typid2, bool useTz, bool *cast_error); +static void checkTimezoneIsUsedForCast(bool useTz, const char *type1, + const char *type2); /****************** User interface to JsonPath executor ********************/ @@ -2409,6 +2411,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, value); break; case TIMESTAMPTZOID: + checkTimezoneIsUsedForCast(cxt->useTz, + "timestamptz", "date"); value = DirectFunctionCall1(timestamptz_date, value); break; @@ -2433,6 +2437,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, case TIMEOID: /* Nothing to do for TIME */ break; case TIMETZOID: + checkTimezoneIsUsedForCast(cxt->useTz, + "timetz", "time"); value = DirectFunctionCall1(timetz_time, value); break; @@ -2441,6 +2447,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, value); break; case TIMESTAMPTZOID: + checkTimezoneIsUsedForCast(cxt->useTz, + "timestamptz", "time"); value = DirectFunctionCall1(timestamptz_time, value); break; @@ -2480,6 +2488,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, text_to_cstring(datetime))))); break; case TIMEOID: + checkTimezoneIsUsedForCast(cxt->useTz, + "time", "timetz"); value = DirectFunctionCall1(time_timetz, value); break; @@ -2531,6 +2541,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, case TIMESTAMPOID: /* Nothing to do for TIMESTAMP */ break; case TIMESTAMPTZOID: + checkTimezoneIsUsedForCast(cxt->useTz, + "timestamptz", "timestamp"); value = DirectFunctionCall1(timestamptz_timestamp, value); break; @@ -2570,6 +2582,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, switch (typid) { case DATEOID: + checkTimezoneIsUsedForCast(cxt->useTz, + "date", "timestamptz"); value = DirectFunctionCall1(date_timestamptz, value); break; @@ -2581,6 +2595,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp, text_to_cstring(datetime))))); break; case TIMESTAMPOID: + checkTimezoneIsUsedForCast(cxt->useTz, + "timestamp", "timestamptz"); value = DirectFunctionCall1(timestamp_timestamptz, value); break; -- cgit v1.2.3