From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
---|---|
To: | Vick Khera <vivek(at)khera(dot)org> |
Cc: | sampie(at)iki(dot)fi, "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-03 16:43:13 |
Message-ID: | CAHyXU0yjxuZpNNjbUMghctPFRHyFgJ3iuHM3OtO=kNemFmMRtA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Tue, Nov 3, 2015 at 9:57 AM, Vick Khera <vivek(at)khera(dot)org> wrote:
>
> On Tue, Nov 3, 2015 at 10:07 AM, Sami Pietilä <sami(dot)pietila(at)gmail(dot)com>
> wrote:
>>
>> Unfortunately I could not figure out how to select rows which, for
>> example, contain following json: '{"a":"world","c":{"b":"helloworld"}}' by
>> search with "hello" string.
>
> cast the field to a text:
>
> select * from t where myfield::text like '%hello%';
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 | Tom Lane | 2015-11-03 17:31:25 | Re: Drop or alter column under load give ERROR #42804 structure of query does not match function result type: |
Previous Message | Merlin Moncure | 2015-11-03 16:32:53 | Re: Approach to extract top records from table based upon aggregate |