> ## 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.

# alter_policies()

> Alter refresh, compression, or data retention policies on a continuous aggregate

export const CHUNK = 'chunk';

export const COLUMNSTORE = 'columnstore';

export const HYPERTABLE = 'hypertable';

export const CAGG = 'continuous aggregate';

<Icon icon="flask" /> Early access <Icon icon="tag" iconType="duotone" /> Since [2.10.0][tsdb-2.10.0]

Alter refresh, {COLUMNSTORE}, or data retention policies on a {CAGG}. The altered {COLUMNSTORE} and retention policies
apply to the
{CAGG}, *not* to the original {HYPERTABLE}.

```sql theme={"dark"}
timescaledb_experimental.alter_policies(
     relation REGCLASS,
     if_exists BOOL = false,
     refresh_start_offset "any" = NULL,
     refresh_end_offset "any" = NULL,
     compress_after "any" = NULL,
     drop_after "any" = NULL
) RETURNS BOOL
```

## Samples

Given a {CAGG} named `example_continuous_aggregate` with an
existing {COLUMNSTORE} policy, alter the {COLUMNSTORE} policy to compress data older
than 16 days:

```sql theme={"dark"}
SELECT timescaledb_experimental.alter_policies(
    'continuous_agg_max_mat_date',
    compress_after => '16 days'::interval
);
```

## Arguments

The syntax is:

```sql theme={"dark"}
SELECT timescaledb_experimental.alter_policies(
    relation = '<view_name>',
    refresh_start_offset = <interval>,
    refresh_end_offset = <interval>,
    compress_after = <interval>,
    drop_after = <interval>
);
```

| Name                   | Type                    | Default | Required | Description                                                                                                                         |
| ---------------------- | ----------------------- | ------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| `relation`             | `REGCLASS`              | -       | ✔        | The {CAGG} that you want to alter policies for                                                                                      |
| `if_exists`            | `BOOL`                  | false   | -        | When true, prints a warning instead of erroring if the policy doesn't exist.                                                        |
| `refresh_start_offset` | `INTERVAL` or `INTEGER` | -       | -        | The start of the {CAGG} refresh window, expressed as an offset from the policy run time.                                            |
| `refresh_end_offset`   | `INTERVAL` or `INTEGER` | -       | -        | The end of the {CAGG} refresh window, expressed as an offset from the policy run time. Must be greater than `refresh_start_offset`. |
| `compress_after`       | `INTERVAL` or `INTEGER` | -       | -        | {CAGG} {CHUNK}s are compressed into the {COLUMNSTORE} if they exclusively contain data older than this interval.                    |
| `drop_after`           | `INTERVAL` or `INTEGER` | -       | -        | {CAGG} {CHUNK}s are dropped if they exclusively contain data older than this interval.                                              |

For arguments that could be either an `INTERVAL` or an `INTEGER`, use an
`INTERVAL` if your time bucket is based on timestamps. Use an `INTEGER` if your
time bucket is based on integers.

## Returns

Returns `true` if successful.

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