Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4697454

Browse files
committed
Disallow jsonpath methods involving TZ in immutable functions
Timezones are not immutable and so neither is any function that relies onthem. In commit66ea94e, we introduced a few methods which do castingfrom one time to another and thus may involve the current timezone. Topreserve the immutability of jsonpath functions currently markedimmutable, disallow these methods from being called from non-TZ awarefunctions.Jeevan Chalke, per a report from Jian He.
1 parentce57143 commit4697454

File tree

4 files changed

+168
-148
lines changed

4 files changed

+168
-148
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18240,7 +18240,12 @@ ERROR: jsonpath member accessor can only be applied to an object
1824018240
<type>timestamptz</type>, and <type>time</type> to <type>timetz</type>.
1824118241
However, all but the first of these conversions depend on the current
1824218242
<xref linkend="guc-timezone"/> setting, and thus can only be performed
18243-
within timezone-aware <type>jsonpath</type> functions.
18243+
within timezone-aware <type>jsonpath</type> functions. Similarly, other
18244+
date/time-related methods that convert strings to date/time types
18245+
also do this casting, which may involve the current
18246+
<xref linkend="guc-timezone"/> setting. Therefore, these conversions can
18247+
also only be performed within timezone-aware <type>jsonpath</type>
18248+
functions.
1824418249
</para>
1824518250
</note>
1824618251

‎src/backend/utils/adt/jsonpath_exec.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ static JsonbValue *getScalar(JsonbValue *scalar, enum jbvType type);
268268
staticJsonbValue*wrapItemsInArray(constJsonValueList*items);
269269
staticintcompareDatetime(Datumval1,Oidtypid1,Datumval2,Oidtypid2,
270270
booluseTz,bool*cast_error);
271+
staticvoidcheckTimezoneIsUsedForCast(booluseTz,constchar*type1,
272+
constchar*type2);
271273

272274
/****************** User interface to JsonPath executor ********************/
273275

@@ -2409,6 +2411,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
24092411
value);
24102412
break;
24112413
caseTIMESTAMPTZOID:
2414+
checkTimezoneIsUsedForCast(cxt->useTz,
2415+
"timestamptz","date");
24122416
value=DirectFunctionCall1(timestamptz_date,
24132417
value);
24142418
break;
@@ -2433,6 +2437,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
24332437
caseTIMEOID:/* Nothing to do for TIME */
24342438
break;
24352439
caseTIMETZOID:
2440+
checkTimezoneIsUsedForCast(cxt->useTz,
2441+
"timetz","time");
24362442
value=DirectFunctionCall1(timetz_time,
24372443
value);
24382444
break;
@@ -2441,6 +2447,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
24412447
value);
24422448
break;
24432449
caseTIMESTAMPTZOID:
2450+
checkTimezoneIsUsedForCast(cxt->useTz,
2451+
"timestamptz","time");
24442452
value=DirectFunctionCall1(timestamptz_time,
24452453
value);
24462454
break;
@@ -2480,6 +2488,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
24802488
text_to_cstring(datetime)))));
24812489
break;
24822490
caseTIMEOID:
2491+
checkTimezoneIsUsedForCast(cxt->useTz,
2492+
"time","timetz");
24832493
value=DirectFunctionCall1(time_timetz,
24842494
value);
24852495
break;
@@ -2531,6 +2541,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
25312541
caseTIMESTAMPOID:/* Nothing to do for TIMESTAMP */
25322542
break;
25332543
caseTIMESTAMPTZOID:
2544+
checkTimezoneIsUsedForCast(cxt->useTz,
2545+
"timestamptz","timestamp");
25342546
value=DirectFunctionCall1(timestamptz_timestamp,
25352547
value);
25362548
break;
@@ -2570,6 +2582,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
25702582
switch (typid)
25712583
{
25722584
caseDATEOID:
2585+
checkTimezoneIsUsedForCast(cxt->useTz,
2586+
"date","timestamptz");
25732587
value=DirectFunctionCall1(date_timestamptz,
25742588
value);
25752589
break;
@@ -2581,6 +2595,8 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
25812595
text_to_cstring(datetime)))));
25822596
break;
25832597
caseTIMESTAMPOID:
2598+
checkTimezoneIsUsedForCast(cxt->useTz,
2599+
"timestamp","timestamptz");
25842600
value=DirectFunctionCall1(timestamp_timestamptz,
25852601
value);
25862602
break;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp