When defining your materialized view, the columns in your SELECT
are not matching the columns in the destination table. You are simply missing an AS mtm_sum
clause in your view:
CREATE MATERIALIZED VIEW crypto_trade_mtm_aggs_view
TO crypto_trade_mtm_aggs_dest
AS SELECT
counterparty,
sumForEachState(mtm) AS mtm_sum
FROM crypto_trade_mtm
GROUP BY counterparty;