Create hypertables

After creating a TimescaleDB database, you’re ready to create your first hypertable. Creating a hypertable is a two-step process:

  1. Create a PostgreSQL table as usual
  2. Convert it to a TimescaleDB hypertable

You can create a distributed hypertable similarly.

Create a hypertable

To create a hypertable, you need to create a standard PostgreSQL table, and then convert it into a TimescaleDB hypertable.

Hypertables are intended for time-series data, so your table needs a column that holds time values. This can be a timestamp, date, or integer. For more information about creating hypertables, see create_hypertable().

Creating a hypertable

  1. Create a standard PostgreSQL table:

``` 1. CREATE TABLE conditions (

  1. time TIMESTAMPTZ NOT NULL,

  2. location TEXT NOT NULL,

  3. temperature DOUBLE PRECISION NULL,

  4. humidity DOUBLE PRECISION NULL

  5. ); ```

  6. Convert the table to a hypertable. Specify the name of the table you want to convert, and the column that holds its time values.

1. SELECT create_hypertable('conditions', 'time');

note

If your table already has data, you can migrate the data when creating the hypertable. Set the migrate_data argument to true when you call the create_hypertable function. This might take a long time if you have a lot of data. To learn other ways of migrating data, see the migration section.