【问题标题】:TimescaleDB cannot create a unique index without the columnTimescaleDB 无法创建没有列的唯一索引
【发布时间】:2021-09-05 00:53:36
【问题描述】:

我正在使用带有新创建的表的 Timescaledb 2.3.0 版。我有下表(已编辑):

local=# \d+ dock_status;
                                               Table "public.dock_status"
       Column       |           Type           | Collation | Nullable | Default | Storage  | Stats target | Description
--------------------+--------------------------+-----------+----------+---------+----------+--------------+-------------
 id                 | uuid                     |           | not null |         | plain    |              |
 dock_id            | uuid                     |           |          |         | plain    |              |
 created_at         | timestamp with time zone |           | not null |         | plain    |              |
 updated_at         | timestamp with time zone |           |          |         | plain    |              |
 deleted_at         | timestamp with time zone |           |          |         | plain    |              |
 is_pwr_btn_enabled | boolean                  |           |          |         | plain    |              |
Indexes:
    "dock_status_pkey" PRIMARY KEY, btree (id)
    "unique_index_dock_status_created_at" UNIQUE, btree (created_at)
Access method: heap

我尝试通过以下方式创建超表:

SELECT create_hypertable('dock_status', 'created_at', migrate_data => true, if_not_exists => true);

错误信息是:

ERROR:  cannot create a unique index without the column "created_at" (used in partitioning)

根据this,我应该为 created_at 创建一个唯一索引,我这样做了。那么到底出了什么问题呢?

【问题讨论】:

标签: sql postgresql timescaledb


【解决方案1】:

“超表”是围绕 PostgreSQL 分区的一个薄层。

分区表上的索引是分区索引——它由每个表分区上的索引组成。这种索引可以是全局唯一的唯一方法是它在定义上是唯一的,即包含分区键作为索引列。

这是 PostgreSQL 的限制,但您应该准备好为分区的好处付出代价。一个可以支持全局唯一索引的“全局索引”会给分区带来很多乐趣。

【讨论】:

    猜你喜欢
    • 2019-12-04
    • 2020-07-27
    • 2021-06-16
    • 2014-07-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 2021-06-22
    相关资源
    最近更新 更多