| From: | Sami Pietilä <sami(dot)pietila(at)gmail(dot)com> |
|---|---|
| To: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
| Cc: | Vick Khera <vivek(at)khera(dot)org>, "Jason O'Donnell" <odonnelljp01(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: How to search a string inside a json structure |
| Date: | 2015-11-07 07:27:05 |
| Message-ID: | CAN08J2jNDDsPxCeNfzxfBY7O_ycP8bkDQwz379rCbQDzzN+FJg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Hi,
I have simplified the case and tried to look from a list of json items
(please see test table content). I think I have managed to unpack values in
such a way that also partial matching is possible. However, the end result
has two "value" named columns even if I have tried to rename them.
How can I rename the columns coming from jsonb_ functions? Or is there a
better way of unpacking the list and items?
select * from test;
id | main
----+--------------------------
1 | [{"A": "b"}, {"B": "b"}]
(1 row)
select * from test, jsonb_array_elements(test.main) as m, jsonb_each(value);
id | main | value | key | value
----+--------------------------+------------+-----+-------
1 | [{"A": "b"}, {"B": "b"}] | {"A": "b"} | A | "b"
1 | [{"A": "b"}, {"B": "b"}] | {"B": "b"} | B | "b"
(2 rows)
Thanks
Performance of this will be awful. Unfortunately, FWICT there is no
> way to do partial string matches against json in a indexed way without
> some serious elbow grease. For full key-value matching though you're
> good to go.
>
> Do index this operation, the best option today will revolve around the
> pg_trgm module. It can optimize like expressions against text.
> Performance of this is a mixed bag although upcoming pg_trgm
> enhancements should make it a lot faster.
>
> merlin
>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | David G. Johnston | 2015-11-07 15:48:27 | Re: How to search a string inside a json structure |
| Previous Message | Adrian Klaver | 2015-11-07 01:37:54 | Re: Two different (postgresql & postgresql93) packages installed? |