Postgresql json data 如何列出一个数组的所有元素
Postgreql json data how to list all elements of an array
我在 postgresql DB table 中有一个 jsonB 字段,它有这样的数据
{
"units": [
{
"id": 299872379221376,
"unitNumber": "1",
"unitFloorSpace": 1,
"createdTimeStamp": 1587994498586
},
{
"id": 299872417011074,
"unitNumber": "2",
"unitFloorSpace": 2,
"createdTimeStamp": 1588001330085
}
]
}
我只想像下面这样列出所有 unitNumbers,查询的内容是什么?
1,
2,
我尝试了下面的 json 查询,但没有列出
Select form_data -> units -> unitNumbers from table where row_id =1;
这是一种方法:
select jsonb_array_elements(jsonb_extract_path(jdata,'units')) ->> 'unitNumber' as UnitNumber
from tableName;
db<>fiddle here
我在 postgresql DB table 中有一个 jsonB 字段,它有这样的数据
{
"units": [
{
"id": 299872379221376,
"unitNumber": "1",
"unitFloorSpace": 1,
"createdTimeStamp": 1587994498586
},
{
"id": 299872417011074,
"unitNumber": "2",
"unitFloorSpace": 2,
"createdTimeStamp": 1588001330085
}
]
}
我只想像下面这样列出所有 unitNumbers,查询的内容是什么?
1, 2,
我尝试了下面的 json 查询,但没有列出
Select form_data -> units -> unitNumbers from table where row_id =1;
这是一种方法:
select jsonb_array_elements(jsonb_extract_path(jdata,'units')) ->> 'unitNumber' as UnitNumber
from tableName;
db<>fiddle here