TimeScale Training: Difference between revisions
Ian.readman (talk | contribs) Created page with "== Setup == <pre> SET search_path = "$user", public, "timescaledb_information"; SET timezone TO 'Europe/Berlin'; \dv timescaledb_information.* </pre> <pre> DROP TABLE IF EXISTS metrics; CREATE TABLE metrics (id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY, device_time timestamptz NOT NULL, device_id integer, cpu_usage numeric); </pre> == Create Hypertable == <pre> SELECT create_hypertable('metrics', by_range('device_time'));..." |
Ian.readman (talk | contribs) No edit summary |
||
Line 11: | Line 11: | ||
CREATE TABLE metrics (id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY, | CREATE TABLE metrics (id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY, | ||
device_time timestamptz NOT NULL, | device_time timestamptz NOT NULL, | ||
device_id integer, | |||
cpu_usage numeric); | |||
</pre> | </pre> | ||
Revision as of 16:50, 13 April 2025
Setup
SET search_path = "$user", public, "timescaledb_information"; SET timezone TO 'Europe/Berlin'; \dv timescaledb_information.*
DROP TABLE IF EXISTS metrics; CREATE TABLE metrics (id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY, device_time timestamptz NOT NULL, device_id integer, cpu_usage numeric);
Create Hypertable
SELECT create_hypertable('metrics', by_range('device_time'));
ERROR: cannot create a unique index without the column "device_time" (used in partitioning) HINT: If you're creating a hypertable on a table with a primary key, ensure the partitioning column is part of the primary or composite key.