> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify-poc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# cagg_migrate()

> Migrate a continuous aggregate from the old format to the new format introduced in TimescaleDB 2.7

export const TIMESCALE_DB = 'TimescaleDB';

export const CAGG = 'continuous aggregate';

<Icon icon="sunset" iconType="duotone" /> Sunsetted [2.25.0][tsdb-2.25.0]

<Icon icon="tag" iconType="duotone" /> Since [2.7.0][tsdb-2.7.0]

Migrate a {CAGG} from the old format to the new format introduced
in {TIMESCALE_DB} 2.7.

```sql theme={"dark"}
CALL cagg_migrate (
    cagg REGCLASS,
    override BOOLEAN DEFAULT FALSE,
    drop_old BOOLEAN DEFAULT FALSE
);
```

{TIMESCALE_DB} 2.7 introduced a new format for {CAGG}s that improves
performance. It also makes {CAGG}s compatible with more types of
SQL queries.

The new format, also called the finalized format, stores the {CAGG} data exactly as it appears in the final view. The
old format, also
called the partial format, stores the data in a partially aggregated state.

Use this procedure to migrate {CAGG}s from the old format to the
new format.

For more information, see the [migration how-to guide][how-to-migrate].

<Warning>
  There are known issues with `cagg_migrate()` in version {TIMESCALE_DB} 2.8.0.
  Upgrade to version 2.8.1 or above before using it.
</Warning>

## Arguments

The syntax is:

```sql theme={"dark"}
CALL cagg_migrate(
    cagg = '<view_name>',
    override = true | false,
    drop_old = true | false
);
```

| Name       | Type       | Default | Required | Description                                                                                                                                                                                                         |
| ---------- | ---------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cagg`     | `REGCLASS` | -       | ✔        | The {CAGG} to migrate                                                                                                                                                                                               |
| `override` | `BOOLEAN`  | `false` | -        | If false, the old {CAGG} keeps its name. The new {CAGG} is named `<OLD_CONTINUOUS_AGGREGATE_NAME>_new`. If true, the new {CAGG} gets the old name. The old {CAGG} is renamed `<OLD_CONTINUOUS_AGGREGATE_NAME>_old`. |
| `drop_old` | `BOOLEAN`  | `false` | -        | If true, the old {CAGG} is deleted. Must be used together with `override`.                                                                                                                                          |

## Returns

This function returns void.

[how-to-migrate]: /use-timescale/latest/continuous-aggregates/migrate/

[tsdb-2.7.0]: https://github.com/timescale/timescaledb/releases/tag/2.7.0

[tsdb-2.25.0]: https://github.com/timescale/timescaledb/releases/tag/2.25.0
