Skip to content
Advertisement

Is there a way to calculate difference whthin a specific time range using clickhouse MV?

For example, this is my source table

What I want to do is to create a MV which asynchronously calculate the price difference whthin 30 min. And then, I can get the difference from this MV using an id every time. Here is an SQL example. It works correctly while directly execute it, but does not work while creating a MV(AS SELECT ...) and querying from the MV.

Here is my SQL to create a MV

Advertisement

Answer

Materialized view is just after insert trigger which works inside new data block which you inserted So, your INSERT INTO market doesn’t contain all required data in most of the cases

POPULATE recalculate full table for materialized view just once

Try to use window functions in SELECT https://clickhouse.com/docs/en/sql-reference/window-functions/, without materialized view

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement