json数组中的数组中的Postgresql搜索
我有一个带列的表:json数组中的数组中的Postgresql搜索,sql,json,postgresql,Sql,Json,Postgresql,我有一个带列的表: id,word,decode 其中,decode是一个json数组,如下所示: [{ "character": "三", "components": [ "一", "二" ] }, { "character": "大", "components": [ "大" ] }, { "character": "洋", "components": [ "氵",
id
,word
,decode
其中,decode
是一个json数组,如下所示:
[{
"character": "三",
"components": [
"一",
"二"
]
},
{
"character": "大",
"components": [
"大"
]
},
{
"character": "洋",
"components": [
"氵",
"羊"
]
}]
我需要在组件中搜索组件。例如:二' 您可以使用
json\u array\u elements\u text(json)
函数将json
数组扩展为一组文本值,然后按所需值进行过滤:
select q.arrays
from
(
select json_array_elements_text(decode) as arrays
from tab
) q
where q.arrays like '%二%';
arrays
---------------------------------------------------
{ "character": "三", "components": [ "一", "二" ]}
如果确实要提取包含角色的子组件()二"代码>),然后使用:
select *
from
(
select elms -> 'components' as elm
from tab t,
json_array_elements(decode) as elms
) q
where elm::text like '%二%';
elm
---------------------------------------------------
[ "一", "二" ]
您可以使用json\u array\u elements\u text(json)
函数将json
数组扩展为一组文本值,然后按所需值进行过滤:
select q.arrays
from
(
select json_array_elements_text(decode) as arrays
from tab
) q
where q.arrays like '%二%';
arrays
---------------------------------------------------
{ "character": "三", "components": [ "一", "二" ]}
如果确实要提取包含角色的子组件()二“
),然后使用:
select *
from
(
select elms -> 'components' as elm
from tab t,
json_array_elements(decode) as elms
) q
where elm::text like '%二%';
elm
---------------------------------------------------
[ "一", "二" ]
另一个[{“字符”的另一个示例:俄“,“组件”:[”亻", "手", "戈]},{“字符”:罗“,“组件”:[”罒", "夕]},{“字符”:斯“,“组件”:[”甘", "一", "八", "斤“]}]另一个[{”字符]的另一个示例:俄“,“组件”:[”亻", "手", "戈]},{“字符”:罗“,“组件”:[”罒", "夕]},{“字符”:斯“,“组件”:[”甘", "一", "八", "斤" ] } ]