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

Commit653d396

Browse files
committed
Teach jsonpath string() to unwrap in lax mode
This was an ommission in commit66ea94e, and brings it into compliancewith both other methods and the standard.Per complaint from David Wheeler.Author: David Wheeler, Jeevan ChalkeReviewed-by: Chapman FlackDiscussion:https://postgr.es/m/A64AE04F-4410-42B7-A141-7A7349260F4D@justatheory.com
1 parent81d20fb commit653d396

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17792,7 +17792,10 @@ ERROR: jsonpath member accessor can only be applied to an object
1779217792
methods available in <type>jsonpath</type>. Note that while the unary
1779317793
operators and methods can be applied to multiple values resulting from a
1779417794
preceding path step, the binary operators (addition etc.) can only be
17795-
applied to single values.
17795+
applied to single values. In lax mode, methods applied to an array will be
17796+
executed for each value in the array. The exceptions are
17797+
<literal>.type()</literal> and <literal>.size()</literal>, which apply to
17798+
the array itself.
1779617799
</para>
1779717800

1779817801
<table id="functions-sqljson-op-table">

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,9 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cxt, JsonPathItem *jsp,
16061606
JsonbValuejbv;
16071607
char*tmp=NULL;
16081608

1609+
if (unwrap&&JsonbType(jb)==jbvArray)
1610+
returnexecuteItemUnwrapTargetArray(cxt,jsp,jb,found, false);
1611+
16091612
switch (JsonbType(jb))
16101613
{
16111614
casejbvString:

‎src/test/regress/expected/jsonb_jsonpath.out

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2525,7 +2525,10 @@ select jsonb_path_query('null', '$.string()', silent => true);
25252525
(0 rows)
25262526

25272527
select jsonb_path_query('[]', '$.string()');
2528-
ERROR: jsonpath item method .string() can only be applied to a bool, string, numeric, or datetime value
2528+
jsonb_path_query
2529+
------------------
2530+
(0 rows)
2531+
25292532
select jsonb_path_query('[]', 'strict $.string()');
25302533
ERROR: jsonpath item method .string() can only be applied to a bool, string, numeric, or datetime value
25312534
select jsonb_path_query('{}', '$.string()');
@@ -2576,6 +2579,13 @@ select jsonb_path_query('1234', '$.string().type()');
25762579
"string"
25772580
(1 row)
25782581

2582+
select jsonb_path_query('[2, true]', '$.string()');
2583+
jsonb_path_query
2584+
------------------
2585+
"2"
2586+
"true"
2587+
(2 rows)
2588+
25792589
select jsonb_path_query('"2023-08-15 12:34:56 +5:30"', '$.timestamp().string()');
25802590
ERROR: cannot convert value from timestamptz to timestamp without time zone usage
25812591
HINT: Use *_tz() function for time zone support.

‎src/test/regress/sql/jsonb_jsonpath.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ select jsonb_path_query('"1.23aaa"', '$.string()');
586586
select jsonb_path_query('1234','$.string()');
587587
select jsonb_path_query('true','$.string()');
588588
select jsonb_path_query('1234','$.string().type()');
589+
select jsonb_path_query('[2, true]','$.string()');
589590
select jsonb_path_query('"2023-08-15 12:34:56 +5:30"','$.timestamp().string()');
590591
select jsonb_path_query_tz('"2023-08-15 12:34:56 +5:30"','$.timestamp().string()');-- should work
591592
select jsonb_path_query_array('[1.23, "yes", false]','$[*].string()');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp