Create a hypertable
Creating a hypertable is a two-step process.
Create a standard table ([PostgreSQL docs][postgres-createtable]).
CREATE TABLE conditions (
time TIMESTAMPTZ NOT NULL,
location TEXT NOT NULL,
temperature DOUBLE PRECISION NULL
);
Execute the TimescaleDB
create_hypertable
command on this newly created table, or usecreate_distributed_hypertable
to create a distributed hypertable that scales out across multiple data nodes.SELECT create_hypertable('conditions', 'time');
If you need to migrate data from an existing table to a hypertable, make sure to set the migrate_data
argument to true
when calling the function. If you would like finer control over index formation and other aspects of your hypertable, follow these migration instructions instead.
warning
The use of the migrate_data
argument to convert a non-empty table can lock the table for a significant amount of time, depending on how much data is in the table.
tip
The ‘time’ column used in the create_hypertable
function supports timestamp, date, or integer types, so you can use a parameter that is not explicitly time-based, as long as it can increment. For example, a monotonically increasing id would work.