text: SELECT dist_quantile(dist_agg(x), 0.50) FROM generate_series(1, 1000) AS x;
  SELECT dist_quantile(dist_agg(x), 0.10) FROM generate_series(1, 1000) AS x;
  SELECT dist_quantile(dist_agg(x), 0.05) FROM generate_series(1, 1000) AS x;
  SELECT dist_quantile(dist_agg(x), 0.90) FROM generate_series(1, 1000) AS x;
  SELECT dist_quantile(dist_agg(x), 0.99) FROM generate_series(1, 1000) AS x;
  
  SELECT dist_cdf(dist_agg(x), 1) FROM generate_series(1, 1000) AS x;
  SELECT dist_cdf(dist_agg(x), 5) FROM generate_series(1, 1000) AS x;
  SELECT dist_cdf(dist_agg(x), 10) FROM generate_series(1, 1000) AS x;
  SELECT dist_cdf(dist_agg(x), 500) FROM generate_series(1, 1000) AS x;
  SELECT dist_cdf(dist_agg(x), 999) FROM generate_series(1, 1000) AS x;
  SELECT dist_cdf(dist_agg(x), 1000) FROM generate_series(1, 1000) AS x;
  SELECT dist_cdf(dist_agg(x), 2000) FROM generate_series(1, 1000) AS x;
  
  SELECT dist_quantile(dist_add(dist_agg(x), 10000), 0.99) FROM generate_series(1, 1000) AS x;
  SELECT dist_cdf(dist_add(dist_agg(x), 10000), 2000) FROM generate_series(1, 1000) AS x;
  
  drop table foo;  drop extension digests;
  create extension digests;
  create table foo (id int, data tdigest);
  
  insert into foo(id, data)
  SELECT 1, tdigest_compress(dist_agg(x)) FROM generate_series(0, 1000) AS x;
  insert into foo(id, data)
  SELECT 2, tdigest_compress(dist_agg(x)) FROM generate_series(0, 1000) AS x;
  insert into foo(id, data)
  SELECT 3, tdigest_compress(dist_agg(x)) FROM generate_series(0, 1000) AS x;
  
  
  select tdigest_print(data) from foo;
  SELECT dist_quantile(data, 0.5) FROM foo;
  SELECT dist_quantile(dist_union(data), 0.5) FROM foo;
  
  drop table foo;  drop extension digests;
  create extension digests;
  create table foo (id int, data tdigest);
  
  insert into foo(id, data)
  SELECT 1, dist_agg(x) FROM generate_series(0, 10000) AS x;
  insert into foo(id, data)
  SELECT 2, dist_agg(x) FROM generate_series(0, 10000) AS x;
  insert into foo(id, data)
  SELECT 3, dist_agg(x) FROM generate_series(0, 10000) AS x;
  
  
  select tdigest_print(data) from foo;
  SELECT dist_quantile(data, 0.5) FROM foo;
  SELECT dist_quantile(dist_union(data), 0.5) FROM foo;
  
  ---
  drop extension digests cascade; drop table foo; drop table bar;
  create extension digests;
  create table foo (id int, data tdigest);
  create table bar (id int, data tdigest, primary key(id));
  
  insert into foo(id, data)
  SELECT 1, dist_agg(x) FROM generate_series(0, 10000) AS x;
  insert into foo(id, data)
  SELECT 2, dist_agg(x) FROM generate_series(0, 10000) AS x;
  insert into foo(id, data)
  SELECT 3, dist_agg(x) FROM generate_series(0, 10000) AS x;
  
  insert into bar(id, data)
  SELECT 1, dist_agg(x) FROM generate_series(0, 10000) AS x;
  insert into bar(id, data)
  SELECT 2, dist_agg(x) FROM generate_series(0, 10000) AS x;
  insert into bar(id, data)
  SELECT 3, dist_agg(x) FROM generate_series(0, 10000) AS x;
  
  select tdigest_print(data) from bar;
  insert into bar(id, data)
   select id, data
   from foo
  on conflict(id)
  do update
     set data = dist_union(EXCLUDED.data, bar.data);
  
  select tdigest_print(data) from bar;
  SELECT dist_quantile(data, 0.5) FROM bar;
  SELECT dist_quantile(dist_union(data), 0.5) FROM bar;
  ===
  create table foo (value double precision, weight int);
  insert into foo(value, weight) values (1.0, 10), (2, 10), (5,50);
  create table bar (dist tdigest);
  select dist_agg(value, weight) from foo;
  select dist_quantile(dist_agg(value, weight), 0.01) from foo;
  
  
  SELECT tdigest_print(dist_agg(x)) FROM generate_series(1, 1000) AS x;
  SELECT tdigest_weight(dist_agg(x)) FROM generate_series(1, 1000) AS x;
  