数组 – 为Postgres整数数组添加值

数组 – 为Postgres整数数组添加值,第1张

概述我正在寻找帮助在PostgreSQL 9.5中为int []添加值10. 查看文档我应该能够使用这种格式来更新它,但它不起作用: int[] + int push element onto array (add it to end of array) 我试过运行这个: update table1 set integer_array = integer_array + 10::Integer. 我正在寻找帮助在Postgresql 9.5中为int []添加值10.

查看文档我应该能够使用这种格式来更新它,但它不起作用:

int[] + int   push element onto array (add it to end of array)

我试过运行这个:

update table1 set integer_array = integer_array + 10::Integer.

它没有用,我收到了这个错误:

ERROR: operator does not exist: integer[] + integer  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.  position: 67

我觉得这与文档中提供的有关如何执行此 *** 作的格式相同.

解决方法 使用array_append函数在数组的末尾追加一个元素:

UPDATE table1SET integer_array = array_append(integer_array,5);

5是一个选择值,在你的情况下它是一个整数数据类型.您可能还需要一些WHERE子句来不更新整个表.

请尝试以下方法查看其工作原理:

SELECT ARRAY[1,2],array_append(ARRAY[1,3);

结果:

array | array_append-------+-------------- {1,2} | {1,2,3}
总结

以上是内存溢出为你收集整理的数组 – 为Postgres整数数组添加值全部内容,希望文章能够帮你解决数组 – 为Postgres整数数组添加值所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/1160224.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存