Created
September 16, 2016 14:32
-
-
Save jberger/173ba1c2ba9300aec2a9d2c07170572b to your computer and use it in GitHub Desktop.
Check a jsonb column is an array of arrays
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
create or replace function is_AoA(_input jsonb, out _out boolean) as $$ | |
begin | |
select into _out 't'::boolean=all(array_agg(jsonb_typeof(v)='array')) from jsonb_array_elements(_input) as v; | |
end; | |
$$ language plpgsql; | |
create table mytest ( | |
id bigserial primary key, | |
myAoA jsonb check (is_AoA(myAoA)) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment