WITH A AS (select BLOCK_TIMESTAMP, TX_ID, MSG_VALUE:"execute_msg":"feed_price":"prices"[0][0]::STRING AS ADDRESS, MSG_VALUE:"execute_msg":"feed_price":"prices"[0][1]::FLOAT AS PRICE from terra.msgs
where BLOCK_TIMESTAMP >= '2021-10-01T00:00:00Z'
--and BLOCK_TIMESTAMP <= '2021-11-19T13:33:00Z'
and MSG_MODULE = 'wasm'
and TX_STATUS = 'SUCCEEDED'
and MSG_VALUE:"contract"::string = 'terra1cgg6yef7qcdm070qftghfulaxmllgmvk77nc7t'
and MSG_VALUE:"execute_msg":"feed_price":"prices" IS NOT NULL
and MSG_VALUE:"execute_msg":"feed_price":"prices"[0][0]::STRING = 'terra1kc87mu460fwkqte29rquh4hc20m54fxwtsx7gp'
order by BLOCK_TIMESTAMP)
SELECT time_slice(BLOCK_TIMESTAMP, 60, 'SECOND', 'START') as "START OF SLICE",
time_slice(BLOCK_TIMESTAMP, 60, 'SECOND', 'END') as "END OF SLICE",
AVG(PRICE)
FROM A
GROUP BY "START OF SLICE", "END OF SLICE"
ORDER BY "START OF SLICE"