Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4cff4d6

Browse files
Florents-TselaiCommitfest Bot
authored and
Commitfest Bot
committed
Add additional jsonpath string methods
Add the following jsonpath methods: * l/r/btrim() * lower(), upper() * initcap() * replace() * split_part() Each simply dispatches to the standard string processing functions. These depend on the locale, but since it's set at `initdb`, they can be considered immutable and therefore allowed in any jsonpath expression.
1 parent 03c53a7 commit 4cff4d6

File tree

10 files changed

+1219
-4
lines changed

10 files changed

+1219
-4
lines changed

doc/src/sgml/func.sgml

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18627,6 +18627,177 @@ ERROR: jsonpath member accessor can only be applied to an object
1862718627
<returnvalue>[{"id": 0, "key": "x", "value": "20"}, {"id": 0, "key": "y", "value": 32}]</returnvalue>
1862818628
</para></entry>
1862918629
</row>
18630+
18631+
<row>
18632+
<entry role="func_table_entry"><para role="func_signature">
18633+
<replaceable>string</replaceable> <literal>.</literal> <literal>lower()</literal>
18634+
<returnvalue><replaceable>string</replaceable></returnvalue>
18635+
</para>
18636+
<para>
18637+
String converted to all lower case according to the rules of the database's locale.
18638+
</para>
18639+
<para>
18640+
<literal>jsonb_path_query('"TOM"', '$.lower()')</literal>
18641+
<returnvalue>"tom"</returnvalue>
18642+
</para></entry>
18643+
</row>
18644+
18645+
<row>
18646+
<entry role="func_table_entry"><para role="func_signature">
18647+
<replaceable>string</replaceable> <literal>.</literal> <literal>upper()</literal>
18648+
<returnvalue><replaceable>string</replaceable></returnvalue>
18649+
</para>
18650+
<para>
18651+
String converted to all upper case according to the rules of the database's locale.
18652+
</para>
18653+
<para>
18654+
<literal>jsonb_path_query('"tom"', '$.upper()')</literal>
18655+
<returnvalue>"TOM"</returnvalue>
18656+
</para></entry>
18657+
</row>
18658+
18659+
<row>
18660+
<entry role="func_table_entry"><para role="func_signature">
18661+
<replaceable>string</replaceable> <literal>.</literal> <literal>initcap()</literal>
18662+
<returnvalue><replaceable>string</replaceable></returnvalue>
18663+
</para>
18664+
<para>
18665+
String with the first letter of each word converted to upper case
18666+
according to the rules of the database's locale. Words are sequences
18667+
of alphanumeric characters separated by non-alphanumeric characters.
18668+
</para>
18669+
<para>
18670+
<literal>jsonb_path_query('"hi THOMAS"', '$.initcap()')</literal>
18671+
<returnvalue>"Hi Thomas"</returnvalue>
18672+
</para></entry>
18673+
</row>
18674+
18675+
<row>
18676+
<entry role="func_table_entry"><para role="func_signature">
18677+
<replaceable>string</replaceable> <literal>.</literal> <literal>replace(<replaceable>from</replaceable>, <replaceable>to</replaceable>)</literal>
18678+
<returnvalue><replaceable>string</replaceable></returnvalue>
18679+
</para>
18680+
<para>
18681+
String with all occurrences of substring from replaced with substring to.
18682+
</para>
18683+
<para>
18684+
<literal>jsonb_path_query('"abcdefabcdef"', '$.replace("cd", "XX")')</literal>
18685+
<returnvalue>"abXXefabXXef"</returnvalue>
18686+
</para></entry>
18687+
</row>
18688+
18689+
<row>
18690+
<entry role="func_table_entry"><para role="func_signature">
18691+
<replaceable>string</replaceable> <literal>.</literal> <literal>split_part(<replaceable>delimiter</replaceable>, <replaceable>n</replaceable>)</literal>
18692+
<returnvalue><replaceable>string</replaceable></returnvalue>
18693+
</para>
18694+
<para>
18695+
String split at occurrences of <replaceable>delimiter</replaceable>
18696+
and returns the <replaceable>n</replaceable>'th field (counting from
18697+
one) or, when <replaceable>n</replaceable> is negative, returns the
18698+
|<replaceable>n</replaceable>|'th-from-last field.
18699+
</para>
18700+
<para>
18701+
<literal>jsonb_path_query('"abc~@~def~@~ghi"', '$.split_part("~@~", 2)')</literal>
18702+
<returnvalue>"def"</returnvalue>
18703+
</para>
18704+
<para>
18705+
<literal>jsonb_path_query('"abc,def,ghi,jkl"', '$.split_part(",", 2)')</literal>
18706+
<returnvalue>"ghi"</returnvalue>
18707+
</para></entry>
18708+
</row>
18709+
18710+
<row>
18711+
<entry role="func_table_entry"><para role="func_signature">
18712+
<replaceable>string</replaceable> <literal>.</literal> <literal>ltrim()</literal>
18713+
<returnvalue><replaceable>string</replaceable></returnvalue>
18714+
</para>
18715+
<para>
18716+
String with spaces removed from the start of <replaceable>string</replaceable>
18717+
</para>
18718+
<para>
18719+
<literal> jsonb_path_query('" hello"', '$.ltrim()')</literal>
18720+
<returnvalue>"hello"</returnvalue>
18721+
</para></entry>
18722+
</row>
18723+
18724+
<row>
18725+
<entry role="func_table_entry"><para role="func_signature">
18726+
<replaceable>string</replaceable> <literal>.</literal> <literal>ltrim(<replaceable>characters</replaceable>)</literal>
18727+
<returnvalue><replaceable>string</replaceable></returnvalue>
18728+
</para>
18729+
<para>
18730+
String with the longest string containing only characters in
18731+
<replaceable>characters</replaceable> removed from the start of
18732+
<replaceable>string</replaceable>
18733+
</para>
18734+
<para>
18735+
<literal>jsonb_path_query('"zzzytest"', '$.ltrim("xyz")')</literal>
18736+
<returnvalue>"test"</returnvalue>
18737+
</para></entry>
18738+
</row>
18739+
18740+
<row>
18741+
<entry role="func_table_entry"><para role="func_signature">
18742+
<replaceable>string</replaceable> <literal>.</literal> <literal>rtrim()</literal>
18743+
<returnvalue><replaceable>string</replaceable></returnvalue>
18744+
</para>
18745+
<para>
18746+
String with spaces removed from the end of <replaceable>string</replaceable>
18747+
</para>
18748+
<para>
18749+
<literal>jsonb_path_query('"hello "', '$.rtrim()')</literal>
18750+
<returnvalue>"hello"</returnvalue>
18751+
</para></entry>
18752+
</row>
18753+
18754+
<row>
18755+
<entry role="func_table_entry"><para role="func_signature">
18756+
<replaceable>string</replaceable> <literal>.</literal> <literal>rtrim(<replaceable>characters</replaceable>)</literal>
18757+
<returnvalue><replaceable>string</replaceable></returnvalue>
18758+
</para>
18759+
<para>
18760+
String with the longest string containing only characters in
18761+
<replaceable>characters</replaceable> removed from the end of
18762+
<replaceable>string</replaceable>
18763+
</para>
18764+
<para>
18765+
<literal>jsonb_path_query('"testxxzx"', '$.rtrim("xyz")')</literal>
18766+
<returnvalue>"test"</returnvalue>
18767+
</para></entry>
18768+
</row>
18769+
18770+
<row>
18771+
<entry role="func_table_entry"><para role="func_signature">
18772+
<replaceable>string</replaceable> <literal>.</literal> <literal>btrim()</literal>
18773+
<returnvalue><replaceable>string</replaceable></returnvalue>
18774+
</para>
18775+
<para>
18776+
String with spaces removed from the start and end of
18777+
<replaceable>string</replaceable>
18778+
</para>
18779+
<para>
18780+
<literal>jsonb_path_query('" hello "', '$.btrim()')</literal>
18781+
<returnvalue>"hello"</returnvalue>
18782+
</para></entry>
18783+
</row>
18784+
18785+
<row>
18786+
<entry role="func_table_entry"><para role="func_signature">
18787+
<replaceable>string</replaceable> <literal>.</literal> <literal>btrim(<replaceable>characters</replaceable>)</literal>
18788+
<returnvalue><replaceable>string</replaceable></returnvalue>
18789+
</para>
18790+
<para>
18791+
String with the longest string containing only characters in
18792+
<replaceable>characters</replaceable> removed from the start and end
18793+
of <replaceable>string</replaceable>
18794+
</para>
18795+
<para>
18796+
<literal>jsonb_path_query('"xyxtrimyyx"', '$.btrim("xyz")')</literal>
18797+
<returnvalue>"trim"</returnvalue>
18798+
</para></entry>
18799+
</row>
18800+
1863018801
</tbody>
1863118802
</tgroup>
1863218803
</table>

0 commit comments

Comments
 (0)