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

From: "David E(dot) Wheeler" <david(at)justatheory(dot)com>
To: Florents Tselai <florents(dot)tselai(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter(at)eisentraut(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>, Alexander Korotkov <aekorotkov(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andrew Dunstan <andrew(at)dunslane(dot)net>
Subject: Re: PATCH: jsonpath string methods: lower, upper, initcap, l/r/btrim, replace, split_part
Date: 2025-07-12 18:24:25
Message-ID: 44F87861-8026-4AB8-95B0-E755E22C6B3F@justatheory.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Jul 12, 2025, at 00:07, Florents Tselai <florents(dot)tselai(at)gmail(dot)com> wrote:

> To recap so far;
>
> - I like your changes and renames on the parser/lexer; it indeed looks much cleaner now and will help with future improvements.

Thanks!

> - I also like the addition of executeStringInternalMethod ; it'll help us add more stuff in the future (reminder that for the original patch I implemented the methods I'd like more, but string operations are quite more).

Agreed.

> - AFAICT no test cases / results have changed with your versions; is this correct ?

I made some minor changes, notably to test alternate trim values and a negative position passed to split_part():

```patch
--- a/src/test/regress/sql/jsonb_jsonpath.sql
+++ b/src/test/regress/sql/jsonb_jsonpath.sql
@@ -627,7 +627,7 @@ rollback;
select jsonb_path_query('" hello "', '$.ltrim(" ")');
select jsonb_path_query('" hello "', '$.ltrim(" ")');
select jsonb_path_query('" hello "', '$.ltrim()');
-select jsonb_path_query('" hello "', '$.ltrim()');
+select jsonb_path_query('"zzzytest"', '$.ltrim("xyz")');
select jsonb_path_query('null', '$.ltrim()');
select jsonb_path_query('null', '$.ltrim()', silent => true);
select jsonb_path_query('[]', '$.ltrim()');
@@ -647,13 +647,13 @@ select jsonb_path_query_array('[" maybe ", " yes", " no"]', '$[*].ltrim().ty
-- test .rtrim()
select jsonb_path_query('" hello "', '$.rtrim(" ")');
-select jsonb_path_query('" hello "', '$.rtrim(" ")');
+select jsonb_path_query('"testxxzx"', '$.rtrim("xyz")');
select jsonb_path_query('" hello "', '$.rtrim()');
select jsonb_path_query('" hello "', '$.rtrim()');
-- test .btrim()
select jsonb_path_query('" hello "', '$.btrim(" ")');
-select jsonb_path_query('" hello "', '$.btrim(" ")');
+select jsonb_path_query('"xyxtrimyyx"', '$.btrim("xyz")');
select jsonb_path_query('" hello "', '$.btrim()');
select jsonb_path_query('" hello "', '$.btrim()');
@@ -723,6 +723,7 @@ select jsonb_path_query('"hello world"', '$.replace("hello","bye") starts with "
-- Test .split_part()
select jsonb_path_query('"abc~(at)~def~@~ghi"', '$.split_part("~(at)~", 2)');
+select jsonb_path_query('"abc,def,ghi,jkl"', '$.split_part(",", -2)');
-- Test string methods play nicely together
select jsonb_path_query('"hello world"', '$.replace("hello","bye").upper()');
```

Best,

David

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Marcos Pegoraro 2025-07-12 18:30:38 Bug on drop extension dependencies ?
Previous Message Tom Lane 2025-07-12 18:04:53 Re: patch: Use pg_assume in jsonb_util.c to fix GCC 15 warnings