fix bug in second procedure

This commit is contained in:
Pablo Martin 2024-10-01 10:38:08 +02:00
parent e6bd5dfc22
commit 8f46b474fd

View file

@ -101,19 +101,19 @@ The setup will consist on preparing:
LANGUAGE plpgsql LANGUAGE plpgsql
AS $$ AS $$
DECLARE DECLARE
schema_name TEXT; schema_to_sync TEXT;
BEGIN BEGIN
-- Step 1: Loop through each schema in the schema list -- Step 1: Loop through each schema in the schema list
FOREACH schema_name IN ARRAY schema_list FOREACH schema_to_sync IN ARRAY schema_list
LOOP LOOP
-- Step 1.1: Drop the schema if it exists -- Step 1.1: Drop the schema if it exists
IF EXISTS (SELECT 1 FROM information_schema.schemata WHERE schema_name = schema_name) THEN IF EXISTS (SELECT 1 FROM information_schema.schemata WHERE schema_name = schema_to_sync) THEN
EXECUTE format('DROP SCHEMA %I CASCADE', schema_name); EXECUTE format('DROP SCHEMA %I CASCADE', schema_to_sync);
END IF; END IF;
-- Step 1.2: Re-import the foreign schema from the server -- Step 1.2: Re-import the foreign schema from the server
EXECUTE format('IMPORT FOREIGN SCHEMA %I FROM SERVER %I INTO %I', EXECUTE format('IMPORT FOREIGN SCHEMA %I FROM SERVER %I INTO %I',
schema_name, server_name, schema_name); schema_to_sync, server_name, schema_to_sync);
END LOOP; END LOOP;
END; END;