2

I'm facing a problem when creating a continuous aggregate on timescaledb (based on materialized views) when the source time column and the new time column have the same name like below:

CREATE MATERIALIZED VIEW IF NOT EXISTS minute_table
WITH (timescaledb.continuous) AS
SELECT
 time_bucket(INTERVAL '1 minute', my_time_col) AS my_time_col,
 ...
FROM source_table
GROUP BY my_time_col
WITH NO DATA;

I get the following error:

ERROR: continuous aggregate view must include a valid time bucket function

But if I change the new time column name like in the below example just works:

CREATE MATERIALIZED VIEW IF NOT EXISTS minute_table
WITH (timescaledb.continuous) AS
SELECT
 time_bucket(INTERVAL '1 minute', my_time_col) AS my_time_col_asdf,
 ...
FROM source_table
GROUP BY my_time_col_asdf
WITH NO DATA;

How can I work around this? I need the source and new time columns to have the same name...

asked Mar 3, 2023 at 19:39

1 Answer 1

4

I found out.

There are two ways if you want to keep same name in both columns:

  1. GROUP BY time_bucket(INTERVAL '1 minute', my_time_col)
  2. GROUP BY 1

The first one more robust the second one shorter.

answered Mar 3, 2023 at 20:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.