trigger_function.txt
1 |
CREATE OR REPLACE FUNCTION update_datemodified_column() |
---|---|
2 |
RETURNS TRIGGER AS $$ |
3 |
BEGIN |
4 |
IF TG_OP = 'INSERT' THEN |
5 |
new.datemodified=now(); |
6 |
RETURN NEW; |
7 |
ELSIF TG_OP = 'UPDATE' THEN |
8 |
new.datemodified= now(); |
9 |
RETURN NEW; |
10 |
ELSE |
11 |
RETURN old; |
12 |
END IF; |
13 |
END; |
14 |
$$ language 'plpgsql'; |
15 |
DROP TRIGGER IF EXISTS update_datemodified ON roads.highways; |
16 |
CREATE TRIGGER update_datemodified before insert or update ON roads.highways FOR EACH ROW EXECUTE PROCEDURE update_datemodified_column(); |