-- a float column grouped by the buckets of its values (floor, ceil, trunc, round or an integer cast of x / c): the expression runs for each bucket, the bucket numbers of a chunk come from the kernels -- label: `GROUP BY floor(value_a / 5)::int` of a float8 column with a distinct value in almost every one of {rows} rows, 200 buckets -- ordered: yes --@ setup DO $do$ BEGIN IF to_regclass('fb_readings') IS NULL THEN CREATE TABLE fb_readings (id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, value_a float8 NOT NULL, count_a int NOT NULL); INSERT INTO fb_readings (value_a, count_a) SELECT round((random() * 1000)::numeric, 3)::float8, (random() * 100)::int FROM generate_series(1, {rows}) g; CREATE INDEX fb_readings_col ON fb_readings USING sift_col (id, value_a, count_a); END IF; END $do$; VACUUM (FREEZE, ANALYZE) fb_readings --@ pg SELECT floor(value_a / 5)::int AS bucket, count(*) AS n, avg(count_a) AS mean_a FROM fb_readings GROUP BY 1 ORDER BY 1