We are currently moving from Oracle to Postgres. In Oracle we have a trigger creating statement like this:
create or replace TRIGGER action2md
AFTER INSERT OR UPDATE OR DELETE
ON action
DECLARE
Mutating_table EXCEPTION;
PRAGMA EXCEPTION_INIT (Mutating_table, -4091);
BEGIN
UPDATE global_tables_md
SET moddate = SYSTIMESTAMP
WHERE table_name='action';
EXCEPTION
WHEN Mutating_table THEN
NULL;
END;
If needed you can read more about remote exception handling in Oracle triggers here.
We are using ora2pg to help migrate the database and it changed the trigger creation statement to the following:
DROP TRIGGER IF EXISTS action2md ON action CASCADE;
CREATE OR REPLACE FUNCTION trigger_fct_action2md() RETURNS trigger AS $BODY$
DECLARE
Mutating_table EXCEPTION;
PRAGMA EXCEPTION_INIT (Mutating_table, -4091);
BEGIN
UPDATE global_tables_md
SET moddate = CURRENT_TIMESTAMP
WHERE table_name='action';
IF TG_OP = 'DELETE' THEN
RETURN OLD;
ELSE
RETURN NEW;
END IF;
EXCEPTION
WHEN Mutating_table THEN
NULL;
END
$BODY$
LANGUAGE 'plpgsql';
CREATE TRIGGER action2md
AFTER INSERT OR UPDATE OR DELETE ON action FOR EACH STATEMENT
EXECUTE PROCEDURE trigger_fct_action2md();
This results in the error [42704] ERROR: type "exception" does not exist.
It seems to me that the problem has to do with the DECLARE block. Do you have any insight on how we can create an equivalent trigger in Postgres?