简体   繁体   中英

LIKE in Array of Objects in JSONB column

I have JSONB data in a Postgres column like this:

{
  "Id": "5c6d3210-1def-489b-badd-2bcc4a1cda28",
  "Name": "Jane Doe",
  "Tags": [
    {
      "Key": "Project",
      "Value": "1004345"
    }
  ]
}

How can I query data where Name contains "Jane" or "Tags.Key" contains "4345"?

I tried this but this only matches the exact "Key" value:

select * from documents where data->'Tags' @> '[{ "Value":"1004345"}]';

You can use a JSON path operator using like_regex

select *
from documents
where data @@ '$.Tags[*].Value like_regex "4345"'
  • you can do this way
select *
from documents
where 'Tags' ->> 'Value' = '1004345';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM