NOT NULL constraint.
You do not need to have a unique index on your s. When you create a unique index,
it must contain all the partitioning columns of the .
Create a hypertable and add unique indexes
To create a unique index on a :-
Determine the partitioning columns
Before you create a unique index, you need to determine which unique indexes are
allowed on your . Begin by identifying your partitioning columns.
traditionally uses the following columns to partition s:
- The
timecolumn used to create the . Every is partitioned by time. - Any space-partitioning columns. Space partitions are optional and not included in every .
- The
-
Create a hypertable
Create a for your time-series data using
CREATE TABLE. For efficient queries on data in the columnstore, remember tosegmentbythe column you will use most often to filter your data. For example:When you create a usingCREATE TABLE ... WITH ..., the default partitioning column is automatically the first column with a timestamp data type. Also, creates a columnstore policy that automatically converts your data to the , after an interval equal to the value of thechunk_interval, defined throughcompress_afterin the policy. This columnar format enables fast scanning and aggregation, optimizing performance for analytical workloads while also saving significant storage space. In the conversion, s are compressed by up to 98%, and organized for efficient, large-scale queries. You can customize this policy later usingalter_job. However, to changeafterorcreated_before, the compression settings, or the the policy is acting on, you must remove the columnstore policy and add a new one. You can also manually convert s in a to the . -
Create a unique index on the hypertable
When you create a unique index on a , it must contain all the partitioning columns. It may contain
other columns as well, and they may be arranged in any order. You cannot create a unique index without
time, becausetimeis a partitioning column. For example:-
Create a unique index on
timeanddevice_idwith a call toCREATE UNIQUE INDEX: -
Create a unique index on
time,user_id, anddevice_id.device_idis not a partitioning column, but this still works:
This restriction is necessary to guarantee global uniqueness in the index. -
Create a unique index on
Create a hypertable from an existing table with unique indexes
If you create a unique index on a table before turning it into a hypertable, the same restrictions apply in reverse. You can only partition the table by columns in your unique index.-
Create a relational table
-
Create a unique index on the table
For example, on
device_idandtime: -
Turn the table into a partitioned hypertable
-
On
timealone: -
On
timeanddevice_id:
timeanduser_id. This is becauseuser_idis not part of theUNIQUE INDEX. To fix the error, adduser_idto your unique index. -
On