使用PostgreSQL从json提取数据
我有这样一个文本栏:使用PostgreSQL从json提取数据,json,postgresql,Json,Postgresql,我有这样一个文本栏: { "addFee":0, "addFeeTotal":0, "addFeeType":0, "addFeeUsers":0, "addFeeVat":0, "addFeeYears":0, "priceTotal":0, "unit1":"db", "unit1Value":5, "unit2":null, "unit2Value":0 } 我想列出价格总值,但是 我得到了“无法从标量中提取元素”的答案:
{
"addFee":0,
"addFeeTotal":0,
"addFeeType":0,
"addFeeUsers":0,
"addFeeVat":0,
"addFeeYears":0,
"priceTotal":0,
"unit1":"db",
"unit1Value":5,
"unit2":null,
"unit2Value":0
}
我想列出价格总值,但是
我得到了“无法从标量中提取元素”的答案:
select p
from web.order_details,
jsonb_array_elements_text(calculatedproductprice::jsonb -> 'priceTotal') as p
并得到“函数jsonb_数组_元素_文本(文本)不存在”的结论:
select js ->> 'priceTotal' as p
from web.order_details,
jsonb_array_elements_text(calculatedproductprice) as js
我没有主意了,但可能这不是一个有效的json数据?好吧,你的json不是数组,所以显然jsonb_数组_元素不是正确的函数 由于您感兴趣的键是顶级键,因此除了
->
操作符之外,您不需要其他任何东西:
select calculatedproductprice::jsonb -> 'priceTotal' as price_total
from web.order_details