array_append() 是一个系统函数,用于将一个元素追加到 数组 的末尾。
array_append() 在 PostgreSQL 7.4 中添加。
示例
array_append() 的基本用法示例
postgres=# SELECT array_append(ARRAY[1,2], 3);
array_append
--------------
{1,2,3}
(1 row)
postgres=# SELECT array_append(ARRAY['foo','bar'], 'baz');
array_append
---------------
{foo,bar,baz}
(1 row)
请注意,anyarray || anyelement 操作符与之等价
postgres=# SELECT ARRAY[1,2] || 3;
?column?
----------
{1,2,3}
(1 row)
不可能将任意数据类型追加到特定类型的数组中
ERROR: function array_append(text[], integer) does not exist
LINE 1: SELECT array_append(ARRAY['foo','bar'], 1);
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
参考资料
- PostgreSQL documentation: 数组函数
