【发布时间】:2021-05-24 22:33:37
【问题描述】:
我在使用 postgres 物化视图的 timescaledb 创建连续聚合时遇到错误:
connection = psycopg2.connect(DATABASE_URI)
cursor = connection.cursor()
cursor.execute(
"""CREATE MATERIALIZED VIEW quotes_1h WITH
(timescaledb.continuous)
AS
SELECT ticker, time_bucket('1h', time) as hour,
min(close) as low,
max(close) as high,
first(close, time) as open,
last(close, time) as close
FROM quotes
GROUP BY
ticker, time_bucket('1h', time);""")
connection.commit()
错误: psycopg2.errors.ActiveSqlTransaction: CREATE MATERIALIZED VIEW ... WITH DATA 不能在事务块内运行
我设置了自动提交,但没有帮助
【问题讨论】:
-
我无法复制这个。查询字符串也不正确。这部分
CREATE MATERIALIZED VIEW quotes_1h WITH.
标签: python postgresql psycopg2 timescaledb