【发布时间】:2021-06-16 19:18:01
【问题描述】:
在 postgres DB 中,我有一个 jsonb 列,其中包含字符串数组中的数据,例如:
{
"name": "john doe",
"testData": "["1", "2", "3", "", "", ""]"
}
我想将字符串 testData 转换为数组,然后将这些字符串整数转换为 int,然后将它们相加。
select sum(ARRAY(test_column->>'testData')::int) as sum from table;
Output -> "6"
【问题讨论】:
标签: sql postgresql postgresql-9.5