array_to_string()

A function converting an array to a string

array_to_string() is a system function which converts the elements of an array to a string and joins them using the specified delimiter.

array_to_string() was added in PostgreSQL 7.4.

Usage

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

Change history

Examples

Basic usage example for :

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

By default NULL values are ignored:

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

However, if a value for NULL elements is explicitly provided, that will be included in the output:

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

Categories

Arrays, String manipulation, System function

See also

string_to_array()