我正在使用PostgreSQL 11。我正在尝试从这个json获取"wmnote“标记(这是一个片段,有必要关闭标签):{
"order": [
{
"notes": {
"note": []
},
"onHold": "false",
"wmnotes": {
"wmnote": []
},
"invoices": {
"invoiceDetail": []
},
"confirmed": "true",
"enteredBy": "",
"entryType": "",
"orderType": "DTC",
"orderEvent": "Update",
"orderLines": {
"orderLine": [
{
"notes": {
"note": []
},
"isGift": "false",
"itemID": "4027956",
"onHold": "false",
"wmnotes": {
"wmnote": [
{
"noteSeq": "1",
"noteCode": "",
"noteType": "DDate",
"visibility": "0",
"commentText": "02/07/2019"
}这是我的疑问:
select o.info->>'order'-> 'orderLines'->'wmnotes'->'wmnote'
from customer_orders o
where o.order_id = 1;但结果为空。
列名info是一个数据类型jsonb。
他们可以帮我构建查询!
发布于 2019-05-20 15:51:33
3点:
->>给出一个文本,而不是JSON类型。因此,您将无法将结果作为JSON对象处理。使用->代替您对所有进一步步骤的使用order包含一个数组。因此,您必须指定要搜索的数组元素。如果要搜索第一个元素,需要调用"order" -> 0 -> "orderlines" (注意,JSON数组是基于零的!)orderline还包含一个数组。见第2点。因此,您的查询应该如下所示:
SELECT o.info->'order'->0 -> 'orderLines' -> 'orderLine' -> 0 -> 'wmnotes'->'wmnote'
FROM customer_orders ohttps://stackoverflow.com/questions/56224292
复制相似问题