i want to create a function that will add a trigger to every user table in a database. i tried the following, but it gives me an error nearw keyword "trigger". is what i'm trying to do possible or is the "execute" statement not able to run "create" statements?
Code:
CREATE OR REPLACE FUNCTION createtriggers()
RETURNS void AS
$BODY$
DECLARE
tables CURSOR for select table_name from alltables;
table_name alltables.table_name%type;
strsql varchar(1000);
BEGIN
open tables;
loop
fetch tables into table_name;
if not found then
exit;
end if;
strsql = 'CREATE OR REPLACE TRIGGER ' || table_name || '_stamp AFTER INSERT OR UPDATE OR DELETE ON ' || table_name || ' FOR EACH ROW EXECUTE PROCEDURE process_table_stamp()';
execute strsql;
end loop;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;