Skip to content

Instantly share code, notes, and snippets.

@jberger
Created September 16, 2016 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jberger/173ba1c2ba9300aec2a9d2c07170572b to your computer and use it in GitHub Desktop.
Save jberger/173ba1c2ba9300aec2a9d2c07170572b to your computer and use it in GitHub Desktop.
Check a jsonb column is an array of arrays
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