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

nlejzf6q  于 2023-04-05  发布在  PostgreSQL
关注(0)|答案(1)|浏览(177)
[
  {
    "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子句匹配的所有名称

3ks5zfa0

3ks5zfa01#

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

相关问题