array_to_string()

一个将数组转换为字符串的函数

array_to_string() 是一个系统函数,它将一个 数组 的元素转换为字符串,并使用指定的定界符将它们连接起来。

array_to_string()PostgreSQL 7.4 中添加。

用法

array_to_string ( array anyarray, delimiter text [, null_string text ] ) → text

变更历史

示例

的基本用法示例

postgres=# SELECT array_to_string(ARRAY[1,2,3], ',');
 array_to_string 
-----------------
 1,2,3
(1 row)

默认情况下,NULL 值将被忽略

postgres=# SELECT array_to_string(ARRAY['foo',NULL,'baz'], ',');
 array_to_string 
-----------------
 foo,baz
(1 row)

但是,如果明确提供了 NULL 元素的取值,它将被包含在输出中

postgres=# SELECT array_to_string(ARRAY['foo',NULL,'baz'], '|', '{NULL}');
 array_to_string 
-----------------
 foo|{NULL}|baz
(1 row)

分类

数组, 字符串操作, 系统函数

另请参阅

string_to_array()

反馈

提交有关“array_to_string()”的任何评论、建议或更正请 在此处进行。