May 14, 2024, 7:32 p.m. | Dmitry Romanoff

DEV Community dev.to

The ARRAY_TO_STRING() function in PostgreSQL is used to convert an array into a string by concatenating its elements with a specified delimiter. Its syntax looks like this:



ARRAY_TO_STRING(array_expression, delimiter)


For example, if you have an array of numbers [-10, 20, -30, 0, -40], and you want to concatenate its elements into a string with a comma delimiter, you can use ARRAY_TO_STRING() like this:



SELECT ARRAY_TO_STRING(ARRAY[-10, 20, -30, 0, -40], ',');


Output:

-10,20,-30,0,-40


The following PostgreSQL query will generate a random …

array database example function numbers postgres postgresql sql string syntax tutorial

Software Engineer for AI Training Data (School Specific)

@ G2i Inc | Remote

Software Engineer for AI Training Data (Python)

@ G2i Inc | Remote

Software Engineer for AI Training Data (Tier 2)

@ G2i Inc | Remote

Data Engineer

@ Lemon.io | Remote: Europe, LATAM, Canada, UK, Asia, Oceania

Artificial Intelligence – Bioinformatic Expert

@ University of Texas Medical Branch | Galveston, TX

Lead Developer (AI)

@ Cere Network | San Francisco, US