Postgres 查询以从 json/jsonb 中查找所有匹配字段

问题描述 投票:0回答:1
[
  {
    "id": "234",
    "name": "JCR",
    "self": "https://jira.abc.io/jira/rest/api/2/component/234"
  },
  {
    "id": "123",
    "name": "React",
    "self": "https://jira.abc.io/jira/rest/api/2/component/123"
  }
]

需要'name'字段的值/找到所有匹配where子句的名字

postgresql postgresql-9.5
1个回答
0
投票
WITH data AS(
  SELECT '[{"id": "234", "name": "JCR", "self": "https://jira.abc.io/jira/rest/api/2/component/234"}, {"id": "123", "name": "React", "self": "https://jira.abc.io/jira/rest/api/2/component/123"}]'::jsonb val
)
SELECT  el
FROM jsonb_array_elements((SELECT val FROM data)) el
WHERE el @> '{"name": "React"}';

db_fiddle

© www.soinside.com 2019 - 2024. All rights reserved.