麻烦从 json 中提取数据与 PostgreSQL .



我有一个这样的文本列:

{
"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_array_elements_text(文本(不存在":

select js ->> 'priceTotal' as p 
from web.order_details, 
jsonb_array_elements_text(calculatedproductprice) as js

我没有想法,但也许这不是有效的 json 数据?

好吧,你的 JSON 不是一个数组,所以显然jsonb_array_elements不是正确的函数。

由于您感兴趣的密钥是顶级密钥,因此除了->>运算符之外,您不需要任何其他内容:

select calculatedproductprice::jsonb -> 'priceTotal' as price_total
from web.order_details

最新更新