Re: PATCH: jsonpath string methods: lower, upper, initcap, l/r/btrim, replace, split_part

jian he <jian.universality@gmail.com>

From: jian he <jian.universality@gmail.com>
To: "David E. Wheeler" <david@justatheory.com>
Cc: Chao Li <li.evan.chao@gmail.com>, Álvaro Herrera <alvherre@kurilemu.de>, Florents Tselai <florents.tselai@gmail.com>, Tom Lane <tgl@sss.pgh.pa.us>, Peter Eisentraut <peter@eisentraut.org>, Robert Haas <robertmhaas@gmail.com>, Alexander Korotkov <aekorotkov@gmail.com>, pgsql-hackers <pgsql-hackers@lists.postgresql.org>, Andrew Dunstan <andrew@dunslane.net>
Date: 2025-12-07T11:21:47Z
Lists: pgsql-hackers
hi.
       <para>
        <literal>jsonb_path_query('"abc,def,ghi,jkl"',
'$.split_part(",", 2)')</literal>
        <returnvalue>"ghi"</returnvalue>
       </para></entry>
the return value should be
"def"
?

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <replaceable>string</replaceable> <literal>.</literal>
<literal>ltrim(<replaceable>characters</replaceable>)</literal>
        <returnvalue><replaceable>string</replaceable></returnvalue>
       </para>
       <para>
        String with the longest string containing only spaces or the
        characters in <replaceable>characters</replaceable> removed from the
        start of <replaceable>string</replaceable>
       </para>
       <para>
        <literal> jsonb_path_query('"  hello"', '$.ltrim()')</literal>
        <returnvalue>"hello"</returnvalue>
       </para>
       <para>
        <literal>jsonb_path_query('"zzzytest"', '$.ltrim("xyz")')</literal>
        <returnvalue>"test"</returnvalue>
       </para></entry>
      </row>

The actual signature:
<replaceable>characters</replaceable> part is optional, but we didn't
use square brackets
to indicate it's optional.

personally I would prefer list two seperate function signature, like:
       <entry role="func_table_entry"><para role="func_signature">
        <replaceable>string</replaceable> <literal>.</literal>
<literal>ltrim()</literal>
        <returnvalue><replaceable>string</replaceable></returnvalue>
       </para>
       <para role="func_signature">
        <replaceable>string</replaceable> <literal>.</literal>
<literal>ltrim(<replaceable>characters</replaceable>)</literal>
        <returnvalue><replaceable>string</replaceable></returnvalue>
       </para>

similarly:
string . rtrim([ characters ]) → string
change to
```
string . rtrim() → string
string . rtrim(characters ) → string
```

string . btrim([ characters ]) → string
change to
```
string . btrim() → string
string . btrim([ characters ]) → string
``
would improve the readability, I think.


--
jian
https://www.enterprisedb.com/



Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Add additional jsonpath string methods

  2. Rename jsonpath method arg tokens

  3. Fix transient memory leakage in jsonpath evaluation.

  4. Make jsonpath .string() be immutable for datetimes.