gpt4 book ai didi

json - 如何从数组中的postgresql json数组字段获取数据

转载 作者:行者123 更新时间:2023-11-29 12:41:56 26 4
gpt4 key购买 nike

下面是列名元和表名层中的 json 数据。在这里,我通过 meta->'pages' 检索 'pages' 键的数据,但我不知道如何获取 'lable' 键值,它是再次位于数组页面中的 'fields' 的数组元素。

{
"id":1,
"name":"org_details",
"action":"organisation.php",
"lable":"Manage Organisation",
"pages":[
{
"name":"Create Org",
"lable":"Organisation Name",
"fields":[
{
"id":11,
"type":1,
"subtype":1,
"lable":"Organisation Name"
},
{
"id":12,
"type":2,
"subtype":1,
"lable":"Description",
"mandatory":TRUE,
"validations":{
"minl":2,
"maxl":60
}
},
{
"id":13,
"type":3,
"subtype":1,
"lable":"Org. Type",
"default value":1,
"mandatory":TRUE,
"choices":[
{
"lable":"OFSDP",
"value":1
},
{
"lable":"AGRICULTURE",
"value":2
},
{
"lable":"HUTICULTURE",
"value":3
}
]
},
{
"id":14,
"type":4,
"lable":"checkbox",
"default value":1
},
{
"id":15,
"type":5,
"subtype":1,
"lable":"Upload",
"mandatory":TRUE
},
{
"id":16,
"type":6,
"subtype":1,
"lable":"GIS"
},
{
"id":17,
"type":7,
"subtype":1,
"lable":"Date"
},
{
"id":18,
"type":8,
"lable":"Attachment"
}
]
}
]
}

最佳答案

json_array_elements 的一种方式:

(假设你的表是your_table,json列名是meta)

select j.value->>'lable'
from your_table
join lateral json_array_elements(meta->'pages'->0->'fields') j
on true

关于json - 如何从数组中的postgresql json数组字段获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45709773/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com