Here’s an updated version of this patch.
The previous version failed several CI steps; this passes them all.

Unless someone disagrees,
I’ll proceed with the documentation and add this for the next CF.


As a future note:
It’s worth noting that both this newly added jspItem and other ones like (jpiDecimal, jpiString)
use jspGetRightArg and jspGetLeftArg.
left and right can be confusing if more complex methods are added in the future.
i.e. jsonpath methods with nargs>=3 .
I was wondering if we’d like something like JSP_GETARG(n)


GitHub PR in case you prefer it’s UI  https://github.com/Florents-Tselai/postgres/pull/3 

Attachment: v2-0001-Add-first-working-version-for-jsonpath-.replace-s.patch
Description: Binary data

Attachment: v2-0002-replace-should-work-with-strings-inside-arrays.patch
Description: Binary data

Attachment: v2-0003-Fix-logic-for-jpiReplaceFunc.patch
Description: Binary data



On 15 Sep 2024, at 4:15 AM, Florents Tselai <florents.tse...@gmail.com> wrote:

Hi,

When working with jsonb/jsonpath, I’ve always wanted more fluent string operations for data cleaning.
Ideally, chaining text processing methods together.

Here’s a draft patch that adds a string replace method.

It works like this
select jsonb_path_query('"hello world"', '$.replace("hello","bye")');
jsonb_path_query
------------------
"bye world"
(1 row)
And looks like plays nicely with existing facilities  

select jsonb_path_query('"hello world"', '$.replace("hello","bye") starts with "bye"');
jsonb_path_query
------------------
true
(1 row)
I’d like some initial feedback on whether this is of interested before I proceed with the following:
- I’ve tried respecting the surrounding code, but a more experienced eye can spot some inconsistencies. I’ll revisit those
- Add more test cases (I’ve added the obvious ones, but ideas on more cases are welcome).
- pg upgrades currently fail on CI (see)
- better error handling/reporting: I’ve kept the wording of error messages, but we’ll need something akin to ERRCODE_INVALID_ARGUMENT_FOR_SQL_JSON_DATETIME_FUNCTION.
- documentation.

<v1-0001-jsonpath-replace-method.patch>

Reply via email to