Не понимаю зачем в этой связке нужен постгрес.
Пишете в кликхауз в таблицу сырые данные/события.
Делаете нужные materialized views.
CREATE TABLE events (
requestId String,
userId UInt16,
siteId UInt16,
type String,
pubCut Float,
createdAt Date
) ENGINE = MergeTree() PARTITION BY createdAt
ORDER BY
(requestId, createdAt);
CREATE MATERIALIZED VIEW mv_overall_data ENGINE = AggregatingMergeTree()
ORDER BY
(date, siteId, userId) POPULATE AS
SELECT
toDayOfMonth(createdAt) as date,
siteId,
userId,
countStateIf(type = 'i') as impressions,
countStateIf(type = 'c') as clicks,
sumState(pubCut) as earnings
FROM
events
GROUP BY
(date, siteId, userId)
Далее запрашиваем это дело
SELECT
date as group_by,
countMerge(impressions) AS ad_impressions,
countMerge(clicks) AS ad_clicks,
sumMerge(earnings) AS ad_earnings
FROM
default.mv_overall_data
GROUP BY
date
как то так...