Re: How to search a string inside a json structure
| От | Sami Pietilä | 
|---|---|
| Тема | Re: How to search a string inside a json structure | 
| Дата | |
| Msg-id | CAN08J2jNDDsPxCeNfzxfBY7O_ycP8bkDQwz379rCbQDzzN+FJg@mail.gmail.com обсуждение исходный текст  | 
		
| Ответ на | Re: How to search a string inside a json structure (Merlin Moncure <mmoncure@gmail.com>) | 
| Ответы | 
                	
            		Re: How to search a string inside a json structure
            		
            		 | 
		
| Список | 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
В списке pgsql-general по дате отправления: