From: | Florents Tselai <florents(dot)tselai(at)gmail(dot)com> |
---|---|
To: | pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | PATCH: jsonpath string methods: lower, upper, initcap, l/r/btrim, replace, split_part |
Date: | 2024-09-25 18:17:20 |
Message-ID: | CA+v5N40sJF39m0v7h=QN86zGp0CUf9F1WKasnZy9nNVj_VhCZQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hello hackers,
This patch is a follow-up and generalization to [0].
It adds the following jsonpath methods: lower, upper, initcap, l/r/btrim,
replace, split_part.
It makes jsonpath able to support expressions like these:
select jsonb_path_query('" hElLo WorlD "',
'$.btrim().lower().upper().lower().replace("hello","bye") starts with
"bye"');
select jsonb_path_query('"abc~(at)~def~@~ghi"', '$.split_part("~(at)~", 2)')
They, of course, forward their implementation to the internal
pg_proc-registered function.
As a first wip/poc I've picked the functions I typically need to clean up
JSON data.
I've also added a README.jsonpath with documentation on how to add a new
jsonpath method.
If I had this available when I started, it would have saved me some time.
So, I am leaving it here for the next hacker.
This patch is not particularly intrusive to existing code:
Afaict, the only struct I've touched is JsonPathParseItem , where I added {
JsonPathParseItem *arg0, *arg1; } method_args.
Up until now, most of the jsonpath methods that accept arguments rely on
left/right operands,
which works, but it could be more convenient for future more complex
methods.
I've also added the appropriate jspGetArgX(JsonPathItem *v, JsonPathItem
*a).
Open items
- What happens if the jsonpath standard adds a new method by the same name?
A.D. mentioned this in [0] with the proposal of having a prefix like pg_ or
initial-upper letter.
- Still using the default collation like the rest of the jsonpath code.
- documentation N/A yet
- I do realize that the process of adding a new method sketches an
imaginary.
CREATE JSONPATH FUNCTION. This has been on the back of my mind for some
time now,
but I can't say I have an action plan for this yet.
GitHub PR view if you prefer:
https://github.com/Florents-Tselai/postgres/pull/18
All the best,
Flo
Attachment | Content-Type | Size |
---|---|---|
v1-0001-This-patch-adds-the-following-string-processing-m.patch | application/octet-stream | 43.1 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2024-09-25 18:47:58 | Re: pg_verifybackup: TAR format backup verification |
Previous Message | Alexander Korotkov | 2024-09-25 18:04:36 | Re: [PATCH] Support Int64 GUCs |