Larry
Larry

Reputation: 11919

PostgreSQL: Convert array-to-string, with delimiter

Consider I have a function like (but the following does not work):

CREATE FUNCTION func(VARIADIC params character varying[]) 
RETURNS type1 AS
$BODY$
   SELECT * FROM func2('id', array_to_string($1,'###’)
$BODY$
LANGUAGE sql VOLATILE;

The signature of func2 is:

 func2(character varying, character varying)

Thus, what I am trying to do is convert the array from “func” into a long string that is delimited by say the characters “###”. I then want to pass the entire string as the second argument of func2.

Upvotes: 0

Views: 3922

Answers (1)

Larry
Larry

Reputation: 11919

Just to make clear, the answer to the above question is as follows:

CREATE FUNCTION func(VARIADIC params character varying[]) 
RETURNS type1 AS
$BODY$
   SELECT * FROM func2('id', array_to_string($1,'###’))
$BODY$
LANGUAGE sql VOLATILE;

Upvotes: 2

Related Questions