0

Is it possible to concatenate elements of 2 arrays in the correct order of its elements?

Example:

array1=['a','b','c']
array2=['d','e','f']

concatenated_array=['ad','be','cf']

My data is in the following way:

id           col1              col2
1        ['a','b','c']     ['d','e','f']
2        ['g','h','i']     ['j','k','l']
3        ['a','b','c']     ['j','k','l']
1
  • 1
    Just a hint: select coalesce(x||y,x,y) from unnest('{1,null,3}'::varchar[], '{a,b}'::varchar[]) t(x,y); Commented Mar 22, 2016 at 18:55

1 Answer 1

3

Use array_agg and unnest (with column alias).

SELECT array_agg(el1||el2)
FROM unnest(ARRAY['a','b','c'], ARRAY['d','e','f']) el (el1, el2);

 array_agg  
------------
 {ad,be,cf}
(1 row)
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.