擅长:python、mysql、java
<p>TimescaleDB目前不支持在同一事务中创建连续聚合并将其物化。因此,有两种选择:</p>
<ol>
<li>不要通过将隔离级别设置为<a href="https://www.psycopg.org/docs/extensions.html#psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT" rel="nofollow noreferrer">ISOLATION_LEVEL_AUTOCOMMIT</a>来创建事务,正如在另一个答复中所回答的那样</李>
<li>不要通过指定<code>WITH NO DATA</code>和<a href="https://docs.timescale.com/latest/api#refresh_continuous_aggregate" rel="nofollow noreferrer">refreshing separately</a>或通过<a href="https://docs.timescale.com/latest/api#add_continuous_aggregate_policy" rel="nofollow noreferrer">policy</a>来具体化连续聚合</李>
</ol>
<p>第二种情况是:</p>
<pre><code>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;""")
</code></pre>