function to convert jsonb array into a string of text seperated by delimiter

This commit is contained in:
Paul Trowbridge 2020-05-27 20:44:56 -04:00
parent 0e6e7e45f4
commit 982b9bc284

View File

@ -0,0 +1,20 @@
DROP FUNCTION IF EXISTS public.jsonb_array_string_agg;
CREATE FUNCTION public.jsonb_array_string_agg(_arr jsonb, _delim text) RETURNS text AS
$$
DECLARE
_ret text;
BEGIN
SELECT
string_agg(ae.v,_delim)
INTO
_ret
FROM
jsonb_array_elements_text(_arr) ae(v);
return _ret;
END;
$$
LANGUAGE plpgsql;