PostgreSQL 18 reference · Array Functions
PostgreSQL ARRAY_TO_STRING() Function
Join array elements into a string with a separator, optionally writing NULLs as a given text.
PostgreSQL 18
Syntax
array_to_string(array, delimiter, null_string)
Parameters
| Parameter | Description |
|---|---|
array |
An array value. |
delimiter |
The separator. |
null_string optional |
Text used for NULL elements; otherwise they're skipped. |
Return value
text.
Examples
SELECT array_to_string(ARRAY['a', 'b', 'c'], ', ') AS joined;
Output
joined --------- a, b, c (1 row)
Run this on your computer — see “Get Started” for setup.
SELECT array_to_string(ARRAY['a', NULL, 'c'], '-') AS skip, array_to_string(ARRAY['a', NULL, 'c'], '-', '?') AS marked;
Output
skip | marked ------+-------- a-c | a-?-c (1 row)
Run this on your computer — see “Get Started” for setup.
Related
STRING_TO_ARRAY()· Split a string on a delimiter into a text array. A third argument turns matching fields into NULL.STRING_AGG()· Join a group's non-NULL values into one string with a separator, optionally in a given ORDER BY order.- SQL String Functions · tutorial