I'm getting an error on creating continuous aggregates with timescaledb which uses postgres materialized views:
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()
the error: psycopg2.errors.ActiveSqlTransaction: CREATE MATERIALIZED VIEW ... WITH DATA cannot run inside a transaction block
I have set the auto-commit on but it didn't help
Creating a continuous aggregate and materializing it in the same transaction is currently not supported in TimescaleDB. Thus there are two choices:
WITH NO DATA and refreshing separately or through a policy.The second case will be:
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)
WITH NO DATA;""")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With