我刚开始使用时间刻度数据库 https://www.timescale.com/与 postgresql。我有一个名为storage_db
其中包含一个名为day_ahead_prices
.
安装 timescaledb 后,我正在关注从同一个 postgresql 数据库迁移 https://docs.timescale.com/latest/getting-started/migrating-data迁移我的storage_db
到 timescaledb 中。
当我这样做时(包括索引):
CREATE TABLE tsdb_day_ahead_prices (LIKE day_ahead_prices INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING INDEXES);
select create_hypertable('tsdb_day_ahead_prices', 'date_time');
它给了我以下错误:
ERROR: cannot create a unique index without the column "date_time" (used in partitioning)
但是当我这样做时(排除索引):
CREATE TABLE tsdb_day_ahead_prices (LIKE day_ahead_prices INCLUDING DEFAULTS INCLUDING CONSTRAINTS EXCLUDING INDEXES);
select create_hypertable('tsdb_day_ahead_prices', 'date_time');
成功了。接下来,我做了
select create_hypertable('tsdb_day_ahead_prices', 'date_time');
它给了我以下输出:
create_hypertable
------------------------------------
(3,public,tsdb_day_ahead_prices,t)
(1 row)
我对此有点陌生,所以有人可以向我解释一下它们之间有什么区别以及为什么我在第一种情况下会出错吗?
P.S.:
My day_ahead_prices
看起来如下:
id | country_code | values | date_time
----+--------------+---------+----------------------------
1 | LU | 100.503 | 2020-04-11 14:04:30.461605
2 | LU | 100.503 | 2020-04-11 14:18:39.600574
3 | DE | 106.68 | 2020-04-11 15:59:10.223965
Edit 1:
我创建了day_ahead_prices
表中python
using flask
and flask_sqlalchemy
代码是:
class day_ahead_prices(db.Model):
__tablename__ = "day_ahead_prices"
id = db.Column(db.Integer, primary_key=True)
country_code = db.Column(avail_cc_enum, nullable=False)
values = db.Column(db.Float(precision=2), nullable=False)
date_time = db.Column(db.DateTime, default=datetime.now(tz=tz), nullable=False)
def __init__(self, country_code, values):
self.country_code = country_code
self.values = values