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

# Schema modifications

> Modify the schema of compressed hypertables

export const HYPERTABLE = 'hypertable';

export const TIMESCALE_DB = 'TimescaleDB';

<Icon icon="archive" iconType="duotone" /> Old API since [2.18.0][tsdb-2.18.0]. Superseded by [hypercore][hypercore].
However, compression APIs are still supported, you do not need to migrate to the hypercore APIs.

[hypercore]: /manage-data/capabilities/hypercore

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

You can modify the schema of compressed hypertables in recent versions of {TIMESCALE_DB}.

| Schema modification                                           | Before TimescaleDB 2.1 | TimescaleDB 2.1 to 2.5 | TimescaleDB 2.6 and above |
| ------------------------------------------------------------- | ---------------------- | ---------------------- | ------------------------- |
| Add a nullable column                                         | ❌                      | ✅                      | ✅                         |
| Add a column with a default value and a `NOT NULL` constraint | ❌                      | ❌                      | ✅                         |
| Rename a column                                               | ❌                      | ✅                      | ✅                         |
| Drop a column                                                 | ❌                      | ❌                      | ✅                         |
| Change the data type of a column                              | ❌                      | ❌                      | ❌                         |

To perform operations that aren't supported on compressed {HYPERTABLE}s, first [decompress][decompress-chunks] the table.

## Add a nullable column

To add a nullable column:

```sql theme={"dark"}
ALTER TABLE <hypertable> ADD COLUMN <column_name> <datatype>;
```

For example:

```sql theme={"dark"}
ALTER TABLE conditions ADD COLUMN device_id integer;
```

Note that adding constraints to the new column is not supported before {TIMESCALE_DB} v2.6.

## Add a column with a default value and a NOT NULL constraint

To add a column with a default value and a not-null constraint:

```sql theme={"dark"}
ALTER TABLE <hypertable> ADD COLUMN <column_name> <datatype>
    NOT NULL DEFAULT <default_value>;
```

For example:

```sql theme={"dark"}
ALTER TABLE conditions ADD COLUMN device_id integer
    NOT NULL DEFAULT 1;
```

## Rename a column

To rename a column:

```sql theme={"dark"}
ALTER TABLE <hypertable> RENAME <column_name> TO <new_name>;
```

For example:

```sql theme={"dark"}
ALTER TABLE conditions RENAME device_id TO devid;
```

## Drop a column

You can drop a column from a compressed {HYPERTABLE}, if the column is not an `orderby` or `segmentby` column. To drop a
column:

```sql theme={"dark"}
ALTER TABLE <hypertable> DROP COLUMN <column_name>;
```

For example:

```sql theme={"dark"}
ALTER TABLE conditions DROP COLUMN temperature;
```

[decompress-chunks]: /manage-data/capabilities/compression/decompress-chunks
