Skip to content

Instantly share code, notes, and snippets.

@urodoz
Created August 5, 2016 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urodoz/bf6435585bc0fe51c73c0183a087737a to your computer and use it in GitHub Desktop.
Save urodoz/bf6435585bc0fe51c73c0183a087737a to your computer and use it in GitHub Desktop.
-- JSONB to text array
CREATE OR REPLACE FUNCTION jsonb_arr2text_arr(_js jsonb)
RETURNS text[] AS
$func$
SELECT ARRAY(SELECT jsonb_array_elements_text(_js))
$func$
LANGUAGE sql IMMUTABLE;
-- JSONB to int array
CREATE OR REPLACE FUNCTION jsonb_arr2int_arr(_js jsonb)
RETURNS integer[] AS
$func$
SELECT array_agg(x)::INTEGER[] FROM jsonb_array_elements_text(_js) x
$func$
LANGUAGE sql IMMUTABLE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment