array_prepend()

在数组前面添加元素的函数

array_prepend() 是一个用于将元素添加到数组开头的系统函数。

array_prepend()PostgreSQL 7.4 中添加。

用法

array_prepend ( anyelement, anyarray ) → anyarray

变更历史

示例

有关 array_prepend() 的基本用法示例

postgres=# SELECT array_prepend(1, ARRAY[2,3]);
 array_prepend 
---------------
 {1,2,3}
(1 row)

postgres=# SELECT array_prepend('foo', ARRAY['bar','baz']);
 array_prepend 
---------------
 {foo,bar,baz}
(1 row)

请注意,anyelement || anyarray 操作符是等效的。

postgres=# SELECT 1 || ARRAY[2,3];
 ?column? 
----------
 {1,2,3}
(1 row)

无法将任意数据类型添加到特定类型的数组中。

postgres=# SELECT array_prepend(1, ARRAY['bar','baz']);
ERROR:  function array_prepend(integer, text[]) does not exist
LINE 1: SELECT array_prepend(1, ARRAY['bar','baz']);
               ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts

分类

数组, 系统函数

另请参阅

array_append(), array_cat()

反馈

提交任何有关“array_prepend()”的评论、建议或更正,请点此 这里