Created
August 5, 2016 03:37
-
-
Save urodoz/bf6435585bc0fe51c73c0183a087737a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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