--\set theta 1.000001
--\set theta 1.5
--\set theta 3.0
\set theta 0.1
ALTER TABLE compte
  DROP COLUMN e,
  DROP COLUMN d;
ALTER TABLE compte
  ADD COLUMN e FLOAT8 DEFAULT NULL,
  ADD COLUMN d FLOAT8 DEFAULT NULL;
-- infer size and counts
CREATE TABLE total AS
  SELECT SUM(1./POW(i, :theta)) AS s,
         COUNT(*) AS n,
         SUM(n) AS t
  FROM compte;
UPDATE compte
  SET e = total.t * (1./POW(i, :theta)) / total.s
  FROM total;
UPDATE compte
  SET e = ROUND(e::NUMERIC, 0);
UPDATE compte
  SET d = (n - e) / e;
