From 3e90c18bcdabc1bb59e7d6f2152a28c8f7d4371f Mon Sep 17 00:00:00 2001 From: Dino Date: Mon, 22 Dec 2025 19:51:16 -0600 Subject: [PATCH] Check if the citus_columnar and pg_ivm extensions are installed before before depending on them --- sql/timeseries.sql | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/sql/timeseries.sql b/sql/timeseries.sql index 2e9e100..3d3b9e8 100644 --- a/sql/timeseries.sql +++ b/sql/timeseries.sql @@ -368,6 +368,15 @@ BEGIN RETURN; END IF; + -- make sure we have the expected columnar extension available + IF NOT _extension_exists('citus_columnar') THEN + RAISE NOTICE object_not_in_prerequisite_state USING + MESSAGE = 'Cannot apply compression policy', + DETAIL = 'The citus_columnar extension is required to apply a compression policy', + HINT = 'Did you forget to run "CREATE EXTENSION citus_columnar" ?'; + RETURN; + END IF; + SELECT format('%s.%s', n.nspname, c.relname) INTO table_name FROM pg_class c @@ -652,6 +661,15 @@ DECLARE old_client_msg text; old_log_msg text; BEGIN + + -- make sure we have the expected pg_ivm extension available + IF NOT _extension_exists('pg_ivm') THEN + RAISE NOTICE object_not_in_prerequisite_state USING + MESSAGE = 'Cannot create incremental view', + DETAIL = 'The pg_ivm extension is required to create incremental views with pg_timeseries', + HINT = 'Did you forget to run "CREATE EXTENSION pg_ivm" ?'; + RETURN; + END IF; -- check that target_view_id is actually a view -- check that target_view_id mentions only one table @@ -692,3 +710,14 @@ BEGIN target_view_id, columns_sql, immv_name); END; $function$; + +CREATE FUNCTION @extschema@._extension_exists(extension_name TEXT) + RETURNS BOOLEAN + LANGUAGE SQL +AS $function$ +SELECT EXISTS ( + SELECT 1 + FROM pg_extension + WHERE extname = extension_name +) +$function$;