[英]Postgres query to return rows where json in the json column contains array elements more than one
我們正在使用Postgres DB,因為我們有一個表包含JSON類型的列,格式如下
{
"name" : "XXX",
"id" : "123",
"course" :[
{
"name" : "java",
"tutor":"YYYY"
},
{
"name" : "python",
"tutor":"ZZZZ"
}
]
}
{
"name" : "XXX",
"id" : "123",
"course" :[
{
"name" : "java",
"tutor":"YYYY"
},
{
"name" : "python",
"tutor":"ZZZZ"
}
]
}
例如,我們有兩行,在json列中,每行都像上面一樣
我想Postgre查詢,它將檢查課程數組中的元素數,如果大於一個,則僅返回該行
沒有得到如何從json鍵內部計算數組元素
可以請建議嗎
為什么不只是 json_array_length
?..例如:
f=# with c(j) as (values('{
"name" : "XXX",
"id" : "123",
"course" :[
{
"name" : "java",
"tutor":"YYYY"
},
{
"name" : "python",
"tutor":"ZZZZ"
}
]
}'::json))
select json_array_length(j->'course') from c;
json_array_length
-------------------
2
(1 row)
像
select * from table_name where json_array_length(j->'course') > 1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.