我正在使用 postgresql 11 并且我有一個 jsonb 欄位。
amount
----------------------------------------
{"value": "3590", "currency": "AUD"}
我可以使用此語法來選擇嵌套欄位value: select amount->'value'。
但我不知道如何將其轉換為整數并求和,例如 select sum(amount->'value') from
我收到此錯誤: HINT: No function matches the given name and argument types. You might need to add explicit type casts.
我試圖將它轉換為
select sum(amount->'value')::DECIMAL
select sum(TO_NUMBER(amount->'value'))
但他們都沒有作業。這樣做的正確方法是什么?
uj5u.com熱心網友回復:
使用->>運算子獲取值為text:https :
//www.postgresql.org/docs/11/functions-json.html
SELECT SUM((amount->>'value')::INT)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/321665.html
標籤:PostgreSQL
上一篇:每次點擊都能改變背景
下一篇:如何改變元素的位置?
