Function array_to_string

Source
fn array_to_string(
    array: ListRef<'_>,
    delimiter: &str,
    ctx: &Context,
    writer: &mut impl Write,
)
Expand description

Converts each array element to its text representation, and concatenates those separated by the delimiter string. If null_string is given and is not NULL, then NULL array entries are represented by that string; otherwise, they are omitted.

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

Examples:

query T
select array_to_string(array[1, 2, 3, NULL, 5], ',')
----
1,2,3,5

query T
select array_to_string(array[1, 2, 3, NULL, 5], ',', '*')
----
1,2,3,*,5

query T
select array_to_string(array[null,'foo',null], ',', '*');
----
*,foo,*

query T
select array_to_string(array['2023-02-20 17:35:25'::timestamp, null,'2023-02-19 13:01:30'::timestamp], ',', '*');
----
2023-02-20 17:35:25,*,2023-02-19 13:01:30

query T
with t as (
  select array[1,null,2,3] as arr, ',' as d union all
  select array[4,5,6,null,7] as arr, '|')
select array_to_string(arr, d) from t;
----
1,2,3
4|5|6|7

# `array` or `delimiter` are required. Otherwise, returns null.
query T
select array_to_string(array[1,2], NULL);
----
NULL

query error polymorphic type
select array_to_string(null, ',');

# multidimensional array
query T
select array_to_string(array[array['one', null], array['three', 'four']]::text[][], ',');
----
one,three,four

query T
select array_to_string(array[array['one', null], array['three', 'four']]::text[][], ',', '*');
----
one,*,three,four