我的 JSON 数据如下所示:
[{
"id": 1,
"payload": {
"location": "NY",
"details": [{
"name": "cafe",
"cuisine": "mexican"
},
{
"name": "foody",
"cuisine": "italian"
}
]
}
}, {
"id": 2,
"payload": {
"location": "NY",
"details": [{
"name": "mbar",
"cuisine": "mexican"
},
{
"name": "fdy",
"cuisine": "italian"
}
]
}
}]
给定文本“foo”,我想返回具有该子字符串的所有元组。但我不知道如何编写相同的查询。
我跟着这个相关答案 https://stackoverflow.com/questions/29108179/jsonb-query-with-nested-objects-in-an-array但不知道该怎么做LIKE
.
这就是我现在正在做的工作:
SELECT r.res->>'name' AS feature_name, d.details::text
FROM restaurants r
, LATERAL (SELECT ARRAY (
SELECT * FROM json_populate_recordset(null::foo, r.res#>'{payload,
details}')
)
) AS d(details)
WHERE d.details @> '{cafe}';
而不是传递整个文本cafe
我想通过ca
并获得与该文本匹配的结果。