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:

    CREATE TABLE conditions (
    time TIMESTAMPTZ NOT NULL,
    location TEXT NOT NULL,
    temperature DOUBLE PRECISION NULL,
    humidity DOUBLE PRECISION NULL
    );
  2. Convert the table to a hypertable. Specify the name of the table you want to convert, and the column that holds its time values.

    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.

Found an issue on this page?

Report an issue!

Keywords

Related Content