Created
September 14, 2020 21:27
-
-
Save abn/85b4613be44f87e105d8dcea06d7b89d to your computer and use it in GitHub Desktop.
Implicit casting from jsonb array to psql text array
This file contains hidden or 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
-- https://stackoverflow.com/a/45244285 | |
CREATE OR REPLACE FUNCTION public.jsonb_array_to_text_array( | |
JSONB | |
) RETURNS TEXT[] AS | |
$f$ | |
SELECT array_agg(x::TEXT) FROM jsonb_array_elements($1) t(x); | |
$f$ | |
LANGUAGE sql | |
IMMUTABLE; | |
CREATE CAST (JSONB AS TEXT[]) WITH FUNCTION public.jsonb_array_to_text_array(JSONB) AS IMPLICIT; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment