From aa1e4b969499f855ffdf1bdbdb982bd7a155a958 Mon Sep 17 00:00:00 2001 From: Artem Gavrilov Date: Fri, 27 Dec 2024 17:59:38 +0200 Subject: [PATCH] PG-1245 Update tests --- expected/debug_json.out | 29 ++++++++++++++++++----------- sql/debug_json.sql | 30 +++++++++++++++++++----------- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/expected/debug_json.out b/expected/debug_json.out index a0fbaa8..1831d02 100644 --- a/expected/debug_json.out +++ b/expected/debug_json.out @@ -43,10 +43,15 @@ WHERE '"' || current_setting('server_version') || '"' = (SELECT CAST(read_json matches (1 row) -SELECT 'matches' AS settings -FROM pg_settings -WHERE name NOT LIKE 'plpgsql.%' AND vartype != 'string' -HAVING COUNT(*) = (SELECT json_array_length(read_json_file()::JSON->'settings')); +WITH settings_comparison AS ( + SELECT name + FROM pg_settings + FULL OUTER JOIN json_object_keys(read_json_file()::JSON->'settings') AS json_keys + ON json_keys = name + WHERE name NOT LIKE 'plpgsql.%' AND vartype != 'string' AND json_keys IS NULL AND name IS NULL +) +SELECT 'matches' AS settings +WHERE NOT EXISTS (SELECT 1 FROM settings_comparison); settings ---------- matches @@ -71,13 +76,15 @@ HAVING COUNT(*) = ( (1 row) -- Databases count will fail if you have any preexisting databases other than the standard template1 and postgres -SELECT 'matches' AS databases_count_calc -FROM pg_database -WHERE datallowconn = true -HAVING COUNT(*) = ( - SELECT json_array_length(read_json_file()::JSON->'databases') - + CAST(NOT EXISTS (SELECT * FROM pg_settings where name = 'percona_pg_telemetry.path') AS INTEGER) - ); +WITH databases_comparison AS ( + SELECT datname + FROM pg_database + FULL OUTER JOIN json_object_keys(read_json_file()::JSON->'databases') AS json_keys + ON json_keys = datname + WHERE datallowconn = true AND json_keys IS NULL AND datname IS NULL +) +SELECT 'matches' AS databases_count_calc +WHERE NOT EXISTS (SELECT 1 FROM databases_comparison); databases_count_calc ---------------------- matches diff --git a/sql/debug_json.sql b/sql/debug_json.sql index 39da131..10fba7f 100644 --- a/sql/debug_json.sql +++ b/sql/debug_json.sql @@ -34,10 +34,16 @@ WHERE '"' || system_identifier || '"' = (SELECT CAST(read_json_file()::JSON->' SELECT 'matches' AS pillar_version WHERE '"' || current_setting('server_version') || '"' = (SELECT CAST(read_json_file()::JSON->'pillar_version' AS VARCHAR)); -SELECT 'matches' AS settings -FROM pg_settings -WHERE name NOT LIKE 'plpgsql.%' AND vartype != 'string' -HAVING COUNT(*) = (SELECT json_array_length(read_json_file()::JSON->'settings')); +WITH settings_comparison AS ( + SELECT name + FROM pg_settings + FULL OUTER JOIN json_object_keys(read_json_file()::JSON->'settings') AS json_keys + ON json_keys = name + WHERE name NOT LIKE 'plpgsql.%' AND vartype != 'string' AND json_keys IS NULL AND name IS NULL +) +SELECT 'matches' AS settings +WHERE NOT EXISTS (SELECT 1 FROM settings_comparison); + SELECT 'matches' AS databases_count FROM pg_database @@ -54,13 +60,15 @@ HAVING COUNT(*) = ( ); -- Databases count will fail if you have any preexisting databases other than the standard template1 and postgres -SELECT 'matches' AS databases_count_calc -FROM pg_database -WHERE datallowconn = true -HAVING COUNT(*) = ( - SELECT json_array_length(read_json_file()::JSON->'databases') - + CAST(NOT EXISTS (SELECT * FROM pg_settings where name = 'percona_pg_telemetry.path') AS INTEGER) - ); +WITH databases_comparison AS ( + SELECT datname + FROM pg_database + FULL OUTER JOIN json_object_keys(read_json_file()::JSON->'databases') AS json_keys + ON json_keys = datname + WHERE datallowconn = true AND json_keys IS NULL AND datname IS NULL +) +SELECT 'matches' AS databases_count_calc +WHERE NOT EXISTS (SELECT 1 FROM databases_comparison); -- Databases count will fail if you have any preexisting databases other than the standard template1 and postgres DROP EXTENSION percona_pg_telemetry;