---
title: attach_chunk() | Tiger Data Docs
description: Attach a chunk to a hypertable
---

Since [2.21.0](https://github.com/timescale/timescaledb/releases/tag/2.21.0)

Attach a hypertable as a chunk in another hypertable at a given slice in a dimension.

![Hypertable structure with time-based partitioning into chunks](/docs/_astro/hypertable-structure.CyTvF21Z_CcUht.webp)

The schema, name, existing constraints, and indexes of `chunk` do not change, even if a constraint conflicts with a chunk constraint in `hypertable`.

The `hypertable` you attach `chunk` to does not need to have the same dimension columns as the hypertable you previously [detached `chunk`](/docs/reference/timescaledb/hypertables/detach_chunk/index.md) from.

While attaching `chunk` to `hypertable`:

- Dimension columns in `chunk` are set as `NOT NULL`.
- Any foreign keys in `hypertable` are created in `chunk`.

You cannot:

- Attaching a chunk that is still attached to another hypertable. First call [detach\_chunk](/docs/reference/timescaledb/hypertables/detach_chunk/index.md).
- Attaching foreign tables are not supported.

## Samples

Attach a hypertable as a chunk in another hypertable for a specific slice in a dimension:

```
CALL attach_chunk('ht', '_timescaledb_internal._hyper_1_2_chunk', '{"device_id": [0, 1000]}');
```

## Arguments

The syntax is:

```
CALL attach_chunk(
    hypertable = '<hypertable_name>',
    chunk = '<chunk_name>',
    slices = '<jsonb_slices>'
);
```

| Name         | Type     | Default | Required | Description                                                                                                                                |
| ------------ | -------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| `hypertable` | REGCLASS | -       | ✔        | Name of the hypertable to attach `chunk` to.                                                                                               |
| `chunk`      | REGCLASS | -       | ✔        | Name of the chunk to attach.                                                                                                               |
| `slices`     | JSONB    | -       | ✔        | The slice `chunk` will occupy in `hypertable`. `slices` cannot clash with the slice already occupied by an existing chunk in `hypertable`. |

## Returns

This function returns void.
