I have set up a small query that uses a DO block to dynamically edit multiple tables.
DO
$$
DECLARE
_table varchar[];
loop_item text;
BEGIN
SELECT array_agg(table_name::TEXT) FROM information_schema.tables
INTO _table
WHERE table_schema = 'public';
FOREACH loop_item IN ARRAY "_table"
LOOP
IF loop_item != 'test' THEN
EXECUTE format('ALTER TABLE %s
ADD COLUMN IF NOT EXISTS new_column varchar;', loop_item);
END IF;
END LOOP;
END;
$$
If the EXECUTE statement is not executed, a notice is printed. But I would also like to know when it was executed successfully. How can I capture and RAISE the return message of the EXECUTE statement?
Info: I am using the Azure Database for Postgres and have no access to the config files.