DO $$
DECLARE
row record;
cmd text;
BEGIN
FOR row IN SELECT schemaname, tablename FROM pg_tables WHERE schemaname = ‘public’ LOOP

–row.schemaname
cmd := format(‘CREATE TRIGGER trschema AFTER INSERT OR UPDATE OR DELETE ON %I FOR EACH ROW EXECUTE PROCEDURE genera_schema(); ‘, row.tablename);
RAISE NOTICE ‘%’, cmd;
EXECUTE cmd;
END LOOP;
END
$$ LANGUAGE plpgsql;

Anuncios