Helper function to convert json arrays to PG arrays

This commit is contained in:
Juan Ignacio Sánchez Lara 2018-07-16 19:55:04 +02:00
parent e82346e7f6
commit 8cb9e123b1
2 changed files with 12 additions and 2 deletions

View File

@ -18,7 +18,12 @@ BEGIN
RETURN ROWS;
END
$func$ LANGUAGE plpgsql;--
$func$ LANGUAGE plpgsql;
-- Taken from https://stackoverflow.com/a/48013356/351721
CREATE OR REPLACE FUNCTION jsonb_array_casttext(jsonb) RETURNS text[] AS $f$
SELECT array_agg(x) || ARRAY[]::text[] FROM jsonb_array_elements_text($1) t(x);
$f$ LANGUAGE sql IMMUTABLE;--
-- Geocoder server connection config
--
-- The purpose of this function is provide to the PL/Proxy functions

View File

@ -12,4 +12,9 @@ BEGIN
RETURN ROWS;
END
$func$ LANGUAGE plpgsql;
$func$ LANGUAGE plpgsql;
-- Taken from https://stackoverflow.com/a/48013356/351721
CREATE OR REPLACE FUNCTION jsonb_array_casttext(jsonb) RETURNS text[] AS $f$
SELECT array_agg(x) || ARRAY[]::text[] FROM jsonb_array_elements_text($1) t(x);
$f$ LANGUAGE sql IMMUTABLE;