# "pretty print" the histogram as a table create or replace function pp(data, limits) as table ( with hist as ( select histogram(boundary) as h from bins(data, limits) t(value, boundary) ), upper as (select h['inf'::DOUBLE][1] as upper from hist) select '< ' || x::VARCHAR as bin, (select coalesce(h[x][1],0) from hist) as frequency from unnest(limits) _(x) union all select '< inf', upper from upper ); from pp(getvariable('data'), getvariable('limits'));