Search Postgresql Archives

Re: How to search a string inside a json structure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux