From dd3bdc33bea0c3dcc3ebf2acd19b7453e6a0d007 Mon Sep 17 00:00:00 2001 From: XRAY Robot <38279597+xray-robot@users.noreply.github.com> Date: Mon, 18 Dec 2023 13:38:38 +0300 Subject: [PATCH] Drop triggers loop fix (#252) 1) Postgres 16.1 throws an error: ``` NOTICE: schema "grestv0" already exists, skipping NOTICE: web_anon exists, skipping... NOTICE: authenticator exists, skipping... NOTICE: role "authenticator" has already been granted membership in role "web_anon" by role "postgres" NOTICE: table "genesis" does not exist, skipping NOTICE: No fuctions found in schema grest ERROR: syntax error at or near "FOR" LINE 1: FOR r IN (SELECT trigger_name, event_object_table FROM infor... ^ Exiting... ``` --- files/grest/rpc/db-scripts/basics.sql | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/files/grest/rpc/db-scripts/basics.sql b/files/grest/rpc/db-scripts/basics.sql index 8cd57625..8c3ebb9e 100644 --- a/files/grest/rpc/db-scripts/basics.sql +++ b/files/grest/rpc/db-scripts/basics.sql @@ -116,9 +116,17 @@ END $do$; -- DROP EXISTING GREST ADDED TRIGGERS ON PUBLIC SCHEMA -FOR r IN (SELECT trigger_name, event_object_table FROM information_schema.triggers WHERE trigger_schema = 'public' AND action_statement LIKE '%grest.%') LOOP - EXECUTE 'DROP TRIGGER IF EXISTS ' || quote_ident(r.trigger_name) || ' ON ' || quote_ident(r.event_object_table); -END LOOP; +DO +$$ +DECLARE + r record; +BEGIN + FOR r IN (SELECT trigger_name, event_object_table FROM information_schema.triggers WHERE trigger_schema = 'public' AND action_statement LIKE '%grest.%') + LOOP + EXECUTE 'DROP TRIGGER IF EXISTS ' || quote_ident(r.trigger_name) || ' ON ' || quote_ident(r.event_object_table); + END LOOP; +END +$$; -- HELPER FUNCTIONS -- CREATE FUNCTION grest.get_query_pids_partial_match(_query text)