1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-11 10:01:57 +03:00

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.
This commit is contained in:
Andrew Dunstan
2024-02-10 12:12:39 -05:00
parent ce571434ae
commit 4697454686
4 changed files with 168 additions and 148 deletions

View File

@ -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;