Skip to main content
In modern applications, data usually grows very quickly. This means that aggregating it into useful summaries can become very slow. If you are collecting data very frequently, you might want to aggregate your data into minutes or hours instead. For example, if an IoT device takes temperature readings every second, you might want to find the average temperature for each hour. Every time you run this query, the database needs to scan the entire table and recalculate the average. TimescaleDB makes aggregating data lightning fast, accurate, and easy with continuous aggregates. Reduced data calls with continuous aggregates Continuous aggregates in TimescaleDB are a kind of hypertable that is refreshed automatically in the background as new data is added, or old data is modified. Changes to your dataset are tracked, and the hypertable behind the continuous aggregate is automatically updated in the background. Continuous aggregates have a much lower maintenance burden than regular Postgres materialized views, because the whole view is not created from scratch on each refresh. This means that you can get on with working your data instead of maintaining your database. Because continuous aggregates are based on hypertables, you can query them in exactly the same way as your other tables. This includes continuous aggregates in the rowstore, compressed into the columnstore, or tiered to object storage. You can even create continuous aggregates on top of your continuous aggregates, for an even more fine-tuned aggregation. Real-time aggregation enables you to combine pre-aggregated data from the materialized view with the most recent raw data. This gives you up-to-date results on every query. For more information about using continuous aggregates, see the documentation in Use continuous aggregates.

Samples

Create a continuous aggregate

Create a continuous aggregate that calculates hourly average temperature:

Add a refresh policy

Automatically refresh the continuous aggregate to keep it up to date:

Manually refresh a continuous aggregate

Refresh a specific time range in the continuous aggregate:

Query a continuous aggregate

Query the continuous aggregate just like a regular table:

Available functions

Create and modify continuous aggregates

Refresh continuous aggregates

Manage policies

continuous aggregate

Experimental policy management

  • add_policies(): add refresh, compression, and data retention policies on a continuous aggregate
  • alter_policies(): alter refresh, compression, or data retention policies on a continuous aggregate
  • remove_policies(): remove refresh, compression, or data retention policies from a continuous aggregate
  • remove_all_policies(): remove all policies from a continuous aggregate
  • show_policies(): show all policies that are currently set on a continuous aggregate