I have some stored function and triggers in my PostgreSQL. E.g. :
CREATE OR REPLACE FUNCTION log_function() RETURNS TRIGGER AS $logger$
BEGIN
IF (TG_OP = 'DELETE') THEN
INSERT INTO logger SELECT 'D', now(), user, OLD.*;
RETURN OLD;
END IF;
RETURN NULL;
END;
$logger$ LANGUAGE plpgsql;
And trigger:
CREATE TRIGGER logging_trigger
AFTER INSERT OR UPDATE OR DELETE ON some_entity
FOR EACH ROW EXECUTE PROCEDURE log_function();
And I would like import this code after each deploy. (I have <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
)
I think it is impossible for functions because its plpgsql, but for triggers it would be great.
I have been trying added triggers to import.sql, but I have got org.postgresql.util.PSQLException: ERROR: syntax error at end of input
And I don't want to move this code to Java level.
Any ideas?