我有一个json数组-
[{id:1,quantity:100},{id:2,quantity:25},{id:3,quantity:68}]
如何在postgres中使用query将其转换为following-
Id |Quantity
-----------------
1 |100
2 |25
3 |68
如果有可能的话,我想知道
最佳答案
select t ->> 'id' as id, t ->> 'quantity' as quantity
from jsonb_array_elements('[{"id":1,"quantity":100},{"id":2,"quantity":25},{"id":3,"quantity":68}]') as t
在线示例:https://rextester.com/YBUER58387
关于sql - PSQL查询将JSON数组转换为行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54746324/