Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PostgreSQL从json提取数据_Json_Postgresql - Fatal编程技术网

使用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