25

I need to form a string from a given array.

Suppose array[1] = gvk, array[2] = gvk1 and array[3] = gvk2, then I need to get these values into a string like:

Mystring = gvk | gvk1 | gvk2

2 Answers 2

56

I think you can use the array_to_string function here :

array_to_string(anyarray, text) --> text
concatenates array elements using supplied delimiter

Example:

scalasb=> select array_to_string(ARRAY[1, 2, 3], '~^~');
 array_to_string 
-----------------
 1~^~2~^~3
(1 row)

scalasb=>
Sign up to request clarification or add additional context in comments.

Comments

0

The MS SQL to POSTGRES Blogspot has a demonstration of how to implement a group_concat function in Postgres. It should be pretty straightforward to modify it to include a separator

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.