aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/jsonpath_exec.c
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2024-02-10 12:12:39 -0500
committerAndrew Dunstan <andrew@dunslane.net>2024-02-10 12:12:39 -0500
commit469745468668917434dbef48eddad4f961880b3d (patch)
tree8518d9f17d7307bfacf766b08e0a801befde556d /src/backend/utils/adt/jsonpath_exec.c
parentce571434ae7027462565706236a0c6fbdf603734 (diff)
downloadpostgresql-469745468668917434dbef48eddad4f961880b3d.tar.gz
postgresql-469745468668917434dbef48eddad4f961880b3d.zip
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.
Diffstat (limited to 'src/backend/utils/adt/jsonpath_exec.c')
-rw-r--r--src/backend/utils/adt/jsonpath_exec.c16
1 files changed, 16 insertions, 0 deletions
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;