Search a JSON array for an object containing a value matching a pattern

前端 未结 2 1117
悲哀的现实
悲哀的现实 2020-12-12 03:01

I have a DB with a jsonb column where each row essentially holds an array of name value pairs. Example for a single jsonb value:

[
         


        
2条回答
  •  爱一瞬间的悲伤
    2020-12-12 03:26

    You can use the function jsonb_array_elements() in a lateral join and use its result value in the WHERE clause:

    select distinct t.* 
    from my_table t
    cross join jsonb_array_elements(jsoncol)
    where value->>'value' like '%ba%'
    

    Please, read How to query jsonb arrays with IN operator for notes about distinct and performance.

提交回复
热议问题