diff --git a/tsl/test/expected/cagg_utils.out b/tsl/test/expected/cagg_utils.out index 8d09cf0a747..50934eec585 100644 --- a/tsl/test/expected/cagg_utils.out +++ b/tsl/test/expected/cagg_utils.out @@ -332,11 +332,10 @@ CREATE MATERIALIZED VIEW integer_ht_cagg GROUP BY time_bucket(1, a), a; NOTICE: continuous aggregate "integer_ht_cagg" is already up-to-date --- Get the bucket Oids -SELECT user_view_name, - cagg_get_bucket_function(mat_hypertable_id) - FROM _timescaledb_catalog.continuous_agg - WHERE user_view_name in('temperature_4h', 'temperature_tz_4h', 'temperature_tz_4h_ts', 'integer_ht_cagg') - ORDER BY user_view_name; +SELECT user_view_name, cagg_get_bucket_function(mat_hypertable_id) +FROM _timescaledb_catalog.continuous_agg +WHERE user_view_name IN ('temperature_4h', 'temperature_tz_4h', 'temperature_tz_4h_ts', 'integer_ht_cagg') +ORDER BY user_view_name; user_view_name | cagg_get_bucket_function ----------------------+--------------------------------------------------------------------------------------- integer_ht_cagg | time_bucket(integer,integer) @@ -345,7 +344,38 @@ SELECT user_view_name, temperature_tz_4h_ts | time_bucket(interval,timestamp with time zone,text,timestamp with time zone,interval) (4 rows) ---- Cleanup +-- Valid multiple time_bucket usage on view definition +CREATE MATERIALIZED VIEW temperature_tz_4h_2 +WITH (timescaledb.continuous) AS +SELECT (time_bucket('4 hour', time) at time zone 'utc')::date, avg(value) +FROM timestamptz_ht +GROUP BY time_bucket('4 hour', time) +ORDER BY 1 +WITH NO DATA; +SELECT user_view_name, cagg_get_bucket_function(mat_hypertable_id) +FROM _timescaledb_catalog.continuous_agg +WHERE user_view_name = 'temperature_tz_4h_2' +ORDER BY user_view_name; + user_view_name | cagg_get_bucket_function +---------------------+------------------------------------------------ + temperature_tz_4h_2 | time_bucket(interval,timestamp with time zone) +(1 row) + +-- Corrupt the direct view definition \c :TEST_DBNAME :ROLE_SUPERUSER +SELECT direct_view_schema, direct_view_name +FROM _timescaledb_catalog.continuous_agg +WHERE user_view_name = 'temperature_tz_4h_2' \gset +CREATE OR REPLACE VIEW :direct_view_schema.:direct_view_name AS +SELECT NULL::date AS timezone, NULL::FLOAT8 AS avg; +\set ON_ERROR_STOP 0 +-- Should error because there's no time_bucket function on the view definition +SELECT user_view_name, cagg_get_bucket_function(mat_hypertable_id) +FROM _timescaledb_catalog.continuous_agg +WHERE user_view_name = 'temperature_tz_4h_2' +ORDER BY user_view_name; +ERROR: time_bucket function not found in CAgg definition for mat_ht_id: 11 +\set ON_ERROR_STOP 1 +--- Cleanup DROP FUNCTION IF EXISTS cagg_get_bucket_function(INTEGER); \c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER diff --git a/tsl/test/sql/cagg_utils.sql b/tsl/test/sql/cagg_utils.sql index 5b6a825998e..d55a34d3455 100644 --- a/tsl/test/sql/cagg_utils.sql +++ b/tsl/test/sql/cagg_utils.sql @@ -167,13 +167,43 @@ CREATE MATERIALIZED VIEW integer_ht_cagg GROUP BY time_bucket(1, a), a; --- Get the bucket Oids -SELECT user_view_name, - cagg_get_bucket_function(mat_hypertable_id) - FROM _timescaledb_catalog.continuous_agg - WHERE user_view_name in('temperature_4h', 'temperature_tz_4h', 'temperature_tz_4h_ts', 'integer_ht_cagg') - ORDER BY user_view_name; +SELECT user_view_name, cagg_get_bucket_function(mat_hypertable_id) +FROM _timescaledb_catalog.continuous_agg +WHERE user_view_name IN ('temperature_4h', 'temperature_tz_4h', 'temperature_tz_4h_ts', 'integer_ht_cagg') +ORDER BY user_view_name; + +-- Valid multiple time_bucket usage on view definition +CREATE MATERIALIZED VIEW temperature_tz_4h_2 +WITH (timescaledb.continuous) AS +SELECT (time_bucket('4 hour', time) at time zone 'utc')::date, avg(value) +FROM timestamptz_ht +GROUP BY time_bucket('4 hour', time) +ORDER BY 1 +WITH NO DATA; ---- Cleanup +SELECT user_view_name, cagg_get_bucket_function(mat_hypertable_id) +FROM _timescaledb_catalog.continuous_agg +WHERE user_view_name = 'temperature_tz_4h_2' +ORDER BY user_view_name; + +-- Corrupt the direct view definition \c :TEST_DBNAME :ROLE_SUPERUSER + +SELECT direct_view_schema, direct_view_name +FROM _timescaledb_catalog.continuous_agg +WHERE user_view_name = 'temperature_tz_4h_2' \gset + +CREATE OR REPLACE VIEW :direct_view_schema.:direct_view_name AS +SELECT NULL::date AS timezone, NULL::FLOAT8 AS avg; + +\set ON_ERROR_STOP 0 +-- Should error because there's no time_bucket function on the view definition +SELECT user_view_name, cagg_get_bucket_function(mat_hypertable_id) +FROM _timescaledb_catalog.continuous_agg +WHERE user_view_name = 'temperature_tz_4h_2' +ORDER BY user_view_name; +\set ON_ERROR_STOP 1 + +--- Cleanup DROP FUNCTION IF EXISTS cagg_get_bucket_function(INTEGER); \c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER