Re: PATCH: jsonpath string methods: lower, upper, initcap, l/r/btrim, replace, split_part - Mailing list pgsql-hackers

From David E. Wheeler
Subject Re: PATCH: jsonpath string methods: lower, upper, initcap, l/r/btrim, replace, split_part
Date
Msg-id 44F87861-8026-4AB8-95B0-E755E22C6B3F@justatheory.com
Whole thread Raw
In response to Re: PATCH: jsonpath string methods: lower, upper, initcap, l/r/btrim, replace, split_part  (Florents Tselai <florents.tselai@gmail.com>)
List pgsql-hackers
On Jul 12, 2025, at 00:07, Florents Tselai <florents.tselai@gmail.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
forthe 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~@~def~@~ghi"', '$.split_part("~@~", 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


Attachment

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: patch: Use pg_assume in jsonb_util.c to fix GCC 15 warnings
Next
From: Marcos Pegoraro
Date:
Subject: Bug on drop extension dependencies ?