gvk
gvk

Reputation: 251

Array to string conversion with delimiter pipe | in PostgreSQL

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

Upvotes: 25

Views: 42466

Answers (2)

Peter Tillemans
Peter Tillemans

Reputation: 35341

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=>

Upvotes: 56

Mark Baker
Mark Baker

Reputation: 212412

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

Upvotes: 0

Related Questions