diff --git a/tsl/src/bgw_policy/policies_v2.c b/tsl/src/bgw_policy/policies_v2.c index e612cbcc84b..8c24eb7bbcf 100644 --- a/tsl/src/bgw_policy/policies_v2.c +++ b/tsl/src/bgw_policy/policies_v2.c @@ -128,9 +128,15 @@ validate_and_create_policies(policies_info all_policies, bool if_exists) { if (IS_INTEGER_TYPE(all_policies.partition_type)) { + bool found_drop_after = false; drop_after_HT = ts_jsonb_get_int64_field(orig_ht_reten_job->fd.config, POL_RETENTION_CONF_KEY_DROP_AFTER, - false); + &found_drop_after); + if (!found_drop_after) + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("could not find %s in config for job", + POL_RETENTION_CONF_KEY_DROP_AFTER))); } else { diff --git a/tsl/test/expected/cagg_policy.out b/tsl/test/expected/cagg_policy.out index 83dbb4ba5c3..6847cc36db1 100644 --- a/tsl/test/expected/cagg_policy.out +++ b/tsl/test/expected/cagg_policy.out @@ -1275,3 +1275,34 @@ SELECT * FROM deals_best_weekly; Sun Apr 24 17:00:00 2022 PDT | 117.764705882353 | 6 (1 row) +-- github issue 5907 +CREATE TABLE t(a integer NOT NULL, b integer); +SELECT create_hypertable('t', 'a', chunk_time_interval=> 10); + create_hypertable +------------------- + (25,public,t,t) +(1 row) + +CREATE OR REPLACE FUNCTION unix_now() returns int LANGUAGE SQL IMMUTABLE as $$ SELECT extract(epoch from now())::INT $$; +SELECT set_integer_now_func('t', 'unix_now'); + set_integer_now_func +---------------------- + +(1 row) + +SELECT add_retention_policy('t', 20); + add_retention_policy +---------------------- + 1056 +(1 row) + +CREATE MATERIALIZED VIEW cagg(a, sumb) WITH (timescaledb.continuous) +AS SELECT time_bucket(1, a), sum(b) + FROM t GROUP BY time_bucket(1, a); +NOTICE: continuous aggregate "cagg" is already up-to-date +SELECT timescaledb_experimental.add_policies('cagg'); + add_policies +-------------- + f +(1 row) + diff --git a/tsl/test/sql/cagg_policy.sql b/tsl/test/sql/cagg_policy.sql index 267130d320a..11e620337e5 100644 --- a/tsl/test/sql/cagg_policy.sql +++ b/tsl/test/sql/cagg_policy.sql @@ -630,3 +630,18 @@ SELECT * FROM deals_best_daily ORDER BY bucket LIMIT 2; -- expect to get an up-to-date notice CALL refresh_continuous_aggregate('deals_best_weekly', '2022-04-24', '2022-05-05'); SELECT * FROM deals_best_weekly; + +-- github issue 5907 +CREATE TABLE t(a integer NOT NULL, b integer); +SELECT create_hypertable('t', 'a', chunk_time_interval=> 10); + +CREATE OR REPLACE FUNCTION unix_now() returns int LANGUAGE SQL IMMUTABLE as $$ SELECT extract(epoch from now())::INT $$; +SELECT set_integer_now_func('t', 'unix_now'); + +SELECT add_retention_policy('t', 20); + +CREATE MATERIALIZED VIEW cagg(a, sumb) WITH (timescaledb.continuous) +AS SELECT time_bucket(1, a), sum(b) + FROM t GROUP BY time_bucket(1, a); + +SELECT timescaledb_experimental.add_policies('cagg'); \ No newline at end of file