Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
json数组中的数组中的Postgresql搜索_Sql_Json_Postgresql - Fatal编程技术网

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
---------------------------------------------------
[ "一",  "二" ]

另一个[{“字符”的另一个示例:俄“,“组件”:[”亻", "手", "戈]},{“字符”:罗“,“组件”:[”罒", "夕]},{“字符”:斯“,“组件”:[”甘", "一", "八", "斤“]}]另一个[{”字符]的另一个示例:俄“,“组件”:[”亻", "手", "戈]},{“字符”:罗“,“组件”:[”罒", "夕]},{“字符”:斯“,“组件”:[”甘", "一", "八", "斤" ] } ]