---
title: Continuous aggregates overview | Tiger Data Docs
description: TimescaleDB reference for calculating continuous aggregates on your data. Includes SQL functions and views related to creating, altering, and dropping continuous aggregates
---

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](/docs/_astro/continuous-aggregate.dGxXBEuT_18QL0n.webp)

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 PostgreSQL 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](/docs/learn/columnar-storage/understand-hypercore/index.md), or [tiered to object storage](/docs/build/data-management/storage/manage-storage/index.md). You can even create [continuous aggregates on top of your continuous aggregates](/docs/learn/continuous-aggregates/hierarchical-continuous-aggregates/index.md), for an even more fine-tuned aggregation.

[Real-time aggregation](/docs/learn/continuous-aggregates/real-time-aggregates/index.md) 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.

In TimescaleDB v2.13 and later, real-time aggregates are **DISABLED** by default. In earlier versions, real-time aggregates are **ENABLED** by default; when you create a continuous aggregate, queries to that view include the results from the most recent raw data.

For more information about using continuous aggregates, see the documentation in [Use continuous aggregates](/docs/build/continuous-aggregates/create-a-continuous-aggregate/index.md).

## Samples

### Create a continuous aggregate

Create a continuous aggregate that calculates hourly average temperature:

```
CREATE MATERIALIZED VIEW conditions_hourly
WITH (timescaledb.continuous) AS
SELECT
  time_bucket('1 hour', time) AS bucket,
  location,
  AVG(temperature) AS avg_temp,
  MAX(temperature) AS max_temp,
  MIN(temperature) AS min_temp
FROM conditions
GROUP BY bucket, location;
```

### Add a refresh policy

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

```
SELECT add_continuous_aggregate_policy('conditions_hourly',
  start_offset => INTERVAL '3 hours',
  end_offset => INTERVAL '1 hour',
  schedule_interval => INTERVAL '1 hour');
```

### Manually refresh a continuous aggregate

Refresh a specific time range in the continuous aggregate:

```
CALL refresh_continuous_aggregate('conditions_hourly',
  '2024-01-01', '2024-02-01');
```

### Query a continuous aggregate

Query the continuous aggregate just like a regular table:

```
SELECT bucket, location, avg_temp
FROM conditions_hourly
WHERE bucket >= NOW() - INTERVAL '7 days'
  AND location = 'office'
ORDER BY bucket DESC;
```

## Available functions

### Create and modify continuous aggregates

- [`CREATE MATERIALIZED VIEW (Continuous Aggregate)`](/docs/reference/timescaledb/continuous-aggregates/create_materialized_view/index.md): create a continuous aggregate on a hypertable or another continuous aggregate
- [`ALTER MATERIALIZED VIEW (Continuous Aggregate)`](/docs/reference/timescaledb/continuous-aggregates/alter_materialized_view/index.md): change an existing continuous aggregate
- [`DROP MATERIALIZED VIEW (Continuous Aggregate)`](/docs/reference/timescaledb/continuous-aggregates/drop_materialized_view/index.md): drop a continuous aggregate view
- [`cagg_migrate()`](/docs/reference/timescaledb/continuous-aggregates/cagg_migrate/index.md): migrate a continuous aggregate from the old format to the new format introduced in TimescaleDB 2.7

### Refresh continuous aggregates

- [`refresh_continuous_aggregate()`](/docs/reference/timescaledb/continuous-aggregates/refresh_continuous_aggregate/index.md): manually refresh a continuous aggregate

### Manage policies

- [`add_continuous_aggregate_policy()`](/docs/reference/timescaledb/continuous-aggregates/add_continuous_aggregate_policy/index.md): add policy to schedule automatic refresh of a

continuous aggregate

- [`remove_continuous_aggregate_policy()`](/docs/reference/timescaledb/continuous-aggregates/remove_continuous_aggregate_policy/index.md): remove a refresh policy from a continuous aggregate

### Experimental policy management

- [`add_policies()`](/docs/reference/timescaledb/continuous-aggregates/add_policies/index.md): add refresh, compression, and data retention policies on a continuous aggregate
- [`alter_policies()`](/docs/reference/timescaledb/continuous-aggregates/alter_policies/index.md): alter refresh, compression, or data retention policies on a continuous aggregate
- [`remove_policies()`](/docs/reference/timescaledb/continuous-aggregates/remove_policies/index.md): remove refresh, compression, or data retention policies from a continuous aggregate
- [`remove_all_policies()`](/docs/reference/timescaledb/continuous-aggregates/remove_all_policies/index.md): remove all policies from a continuous aggregate
- [`show_policies()`](/docs/reference/timescaledb/continuous-aggregates/show_policies/index.md): show all policies that are currently set on a continuous aggregate
