Skip to content

Instantly share code, notes, and snippets.

@chy-causer
Forked from jberger/is_AoA.sql
Last active September 16, 2016 14:41
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 chy-causer/a55b514c03ca6f7a8ac07b0d46782a5c to your computer and use it in GitHub Desktop.
Save chy-causer/a55b514c03ca6f7a8ac07b0d46782a5c 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) returns boolean as $$
select _input = '[]' or 'array' = all(array_agg(jsonb_typeof(foo))) from (select jsonb_array_elements(_input) foo) x;
$$ language sql immutable;
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