select '{
"CUSTA": {
"name": "Customer A"
},
"CUSTB": {
"name": "Customer B"
},
"CUSTC": {
"name": "Customer C"
}
}'::json#>>'{CUSTA}';
?column?
------------------------------
{ +
"name": "Customer A"+
}
(1 row)
注意:name:customer x后跟逗号,这不是正确的json。对于您的查询,您可能会执行以下操作:
select data#>>'{CUSTA}' from invoices;
或者,如果数据还不是json字段:
select data::json#>>'{CUSTA}' from invoices;
我不明白为什么任何一张发票都会有一个以上的客户。
-G