Skip to content

Instantly share code, notes, and snippets.

@chy-causer
chy-causer / is_AoA.sql
Last active September 16, 2016 14:41 — forked from jberger/is_AoA.sql
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))
);