1条回答
默认
最新
采纳答案后不可修改和取消
通过update更新整个数组或数组的某些元素。
数组值可以整个被更新,也可以只更新数组中的单个元素。
更新整个数组值的示例如下:
postgres=# select * from testtab09;
id | col1
----+---------------------------
1 | {{1,2,3},{4,5,6},{7,8,9}}
(1 row)
postgres=# update testtab09 set col1='{{10,11,12},{13,14,15},{16,17,18}}' where id=1;
UPDATE 1
postgres=# select * from testtab09;
id | col1
----+------------------------------------
1 | {{10,11,12},{13,14,15},{16,17,18}}
(1 row)
只修改数组中的某个元素值的示例如下:
postgres=# update testtab09 set col1[2][1]=100 where id=1;
UPDATE 1
postgres=# select * from testtab09;
id | col1
----+-------------------------------------
1 | {{10,11,12},{100,14,15},{16,17,18}}
(1 row)
注意,不能直接修改多维数组中某一维的值:
postgres=# update testtab09 set col1[3]=100 where id=1;
ERROR: wrong number of array subscripts
postgres=# update testtab09 set col1[3]='{200,300}' where id=1;
ERROR: invalid input syntax for type integer: "{200,300}"
LINE 1: update testtab09 set col1[3]='{200,300}' where id=1;
评论
有用 0回答交流
提交
问题信息
请登录之后查看
邀请回答
暂无人订阅该标签,敬请期待~~
墨值悬赏

