Skip to content

Commit

Permalink
Handle when FROM clause is missing in continuous aggregate definition
Browse files Browse the repository at this point in the history
It now errors out for such a case.

Fixes #5500
  • Loading branch information
RafiaSabih committed Mar 29, 2023
1 parent cb81c33 commit ff5959f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -28,6 +28,7 @@ accidentally triggering the load of a previous DB version.**
* #5459 Fix issue creating dimensional constraints
* #5499 Do not segfault on large histogram() parameters
* #5497 Allow named time_bucket arguments in Cagg definition
* #5500 Fix when no FROM clause in continuous aggregate definition

**Thanks**
* @nikolaps for reporting an issue with the COPY fetcher
Expand Down
6 changes: 5 additions & 1 deletion tsl/src/continuous_aggs/create.c
Expand Up @@ -1050,7 +1050,11 @@ cagg_query_supported(const Query *query, StringInfo hint, StringInfo detail, con
}
#endif
#endif

if (!query->jointree->fromlist)
{
appendStringInfoString(hint, "FROM clause missing in the query");
return false;
}
if (query->commandType != CMD_SELECT)
{
appendStringInfoString(hint, "Use a SELECT query in the continuous aggregate view.");
Expand Down
3 changes: 3 additions & 0 deletions tsl/test/expected/cagg_errors.out
Expand Up @@ -631,3 +631,6 @@ ERROR: invalid continuous aggregate query
CREATE MATERIALIZED VIEW matv1 AS SELECT now() AS time;
CREATE MATERIALIZED VIEW cagg1 WITH (timescaledb.continuous) AS SELECT time_bucket('1h',time) FROM matv1 GROUP BY 1;
ERROR: invalid continuous aggregate view
-- No FROM clause in CAGG definition
CREATE MATERIALIZED VIEW cagg1 with (timescaledb.continuous) AS SELECT 1 GROUP BY 1 WITH NO DATA;
ERROR: invalid continuous aggregate query
2 changes: 2 additions & 0 deletions tsl/test/sql/cagg_errors.sql
Expand Up @@ -523,3 +523,5 @@ CREATE MATERIALIZED VIEW cagg1 WITH (timescaledb.continuous) AS SELECT time_buck
CREATE MATERIALIZED VIEW matv1 AS SELECT now() AS time;
CREATE MATERIALIZED VIEW cagg1 WITH (timescaledb.continuous) AS SELECT time_bucket('1h',time) FROM matv1 GROUP BY 1;

-- No FROM clause in CAGG definition
CREATE MATERIALIZED VIEW cagg1 with (timescaledb.continuous) AS SELECT 1 GROUP BY 1 WITH NO DATA;

0 comments on commit ff5959f

Please sign in to comment.