본문 바로가기

Program/PostgreSQL

[PostgreSQL] PostgreSQL Trigger

* Create Trigger Function



* Create Trigger
CREATE [ CONSTRAINT ] TRIGGER name { BEFORE | AFTER | INSTEAD OF } { event [ OR ... ] }
    ON table
    [ FROM referenced_table_name ]
    { NOT DEFERRABLE | [ DEFERRABLE ] { INITIALLY IMMEDIATE | INITIALLY DEFERRED } }
    [ FOR [ EACH ] { ROW | STATEMENT } ]
    [ WHEN ( condition ) ]
    EXECUTE PROCEDURE function_name ( arguments )

where event can be one of:

    INSERT
    UPDATE [ OF column_name [, ... ] ]
    DELETE
    TRUNCATE


* Drop Trigger


* 트리거 함수를 만들고, 테이블에 적용할 트리거를 생성하면서 트리거 함수를 적용한다. 

* Create Trigger 참고 : http://www.postgresql.org/docs/9.1/static/sql-createtrigger.html 
* Drop Trigger 참고 : http://www.postgresql.org/docs/9.1/static/sql-droptrigger.html

* Trigger Procedure 참고 :

http://www.postgresql.org/docs/9.1/static/plpgsql-trigger.html