1

Does Postgres have a function to transform an array into a single value? For example, I'd like to do something like:

reduce(ARRAY['one','two']) -> onetwo, or even better: reduce(ARRAY['one','two], ', ') -> one, two

If not, how would I go about implementing that in my query. I know of unnest, but that just gives me one row per array element

3
  • 4
    array_to_string()? postgresql.org/docs/current/static/functions-array.html Commented Nov 16, 2015 at 17:12
  • Thanks, I must have been sleeping while reading that page >_< Commented Nov 16, 2015 at 17:22
  • @a_horse feel free to make that an answer so I can accept it Commented Nov 16, 2015 at 17:32

1 Answer 1

2

As in the comments:

select array_to_string(array['one','two'],',');
 array_to_string 
-----------------
 one,two
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.