diff --git a/tsl/src/bgw_policy/job.c b/tsl/src/bgw_policy/job.c index b11f46b1a..eb0a89057 100644 --- a/tsl/src/bgw_policy/job.c +++ b/tsl/src/bgw_policy/job.c @@ -341,6 +341,13 @@ policy_refresh_cagg_read_and_validate_config(Jsonb *config, PolicyContinuousAggD materialization_id = policy_continuous_aggregate_get_mat_hypertable_id(config); mat_ht = ts_hypertable_get_by_id(materialization_id); + + if (!mat_ht) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("configuration materialization hypertable id %d not found", + materialization_id))); + open_dim = get_open_dimension_for_hypertable(mat_ht); dim_type = ts_dimension_get_partition_type(open_dim); refresh_start = policy_refresh_cagg_get_refresh_start(open_dim, config); diff --git a/tsl/test/expected/continuous_aggs_errors.out b/tsl/test/expected/continuous_aggs_errors.out index 288eed60f..085cf169c 100644 --- a/tsl/test/expected/continuous_aggs_errors.out +++ b/tsl/test/expected/continuous_aggs_errors.out @@ -574,3 +574,18 @@ DROP TABLE measurements CASCADE; NOTICE: drop cascades to 3 other objects DROP TABLE conditions CASCADE; NOTICE: drop cascades to 3 other objects +-- test handling of invalid mat_hypertable_id +create table i2980(time timestamptz not null); +select create_hypertable('i2980','time'); + create_hypertable +--------------------- + (12,public,i2980,t) +(1 row) + +create materialized view i2980_cagg with (timescaledb.continuous) AS SELECT time_bucket('1h',time), avg(7) FROM i2980 GROUP BY 1; +NOTICE: continuous aggregate "i2980_cagg" is already up-to-date +select add_continuous_aggregate_policy('i2980_cagg',NULL,NULL,'4h') AS job_id \gset +\set ON_ERROR_STOP 0 +select alter_job(:job_id,config:='{"end_offset": null, "start_offset": null, "mat_hypertable_id": 1000}'); +ERROR: configuration materialization hypertable id 1000 not found +\set ON_ERROR_STOP 1 diff --git a/tsl/test/sql/continuous_aggs_errors.sql b/tsl/test/sql/continuous_aggs_errors.sql index 05d0f5fe3..1f6e945bb 100644 --- a/tsl/test/sql/continuous_aggs_errors.sql +++ b/tsl/test/sql/continuous_aggs_errors.sql @@ -529,3 +529,13 @@ SELECT alter_job(:job_id, DROP TABLE measurements CASCADE; DROP TABLE conditions CASCADE; + +-- test handling of invalid mat_hypertable_id +create table i2980(time timestamptz not null); +select create_hypertable('i2980','time'); +create materialized view i2980_cagg with (timescaledb.continuous) AS SELECT time_bucket('1h',time), avg(7) FROM i2980 GROUP BY 1; +select add_continuous_aggregate_policy('i2980_cagg',NULL,NULL,'4h') AS job_id \gset +\set ON_ERROR_STOP 0 +select alter_job(:job_id,config:='{"end_offset": null, "start_offset": null, "mat_hypertable_id": 1000}'); +\set ON_ERROR_STOP 1 +