Hypertables are designed for real-time analytics, they are PostgreSQL tables that automatically partition your data by time. Typically, you partition hypertables on columns that hold time values. These partitioning columns can be of the timestamptz, date, or integer types. While timestamp is also supported, best practice is to use timestamptz.

This code uses the best practice create_hypertable API introduced in TimescaleDB 2.13. You can also use the old interface.

After you have created a Timescale Cloud service, you're ready to create your first hypertable:

  1. Create a standard PostgreSQL table:

    CREATE TABLE conditions (
    time TIMESTAMPTZ NOT NULL,
    location TEXT NOT NULL,
    device TEXT NOT NULL,
    temperature DOUBLE PRECISION NULL,
    humidity DOUBLE PRECISION NULL
    );
  2. Convert the table to a hypertable.

    Specify the name of the table to convert and the column that holds its time values. For example:

    SELECT create_hypertable('conditions', by_range('time'));
Note

If your table already has data, set migrate_data to true when you create the hypertable.

However, if you have a lot of data, this may take a long time. For more information about migrating data, see Migrate your data to Timescale Cloud.

Keywords

Found an issue on this page?Report an issue or Edit this page in GitHub.