test=# create table hibiscus (id int primary key, val1 int, val2 int);
CREATE TABLE
Time: 5,692 ms
test=*# create or replace function ignore_val2_insert() returns trigger as $$begin new.val2 := null; return new; end; $$ language plpgsql;
CREATE FUNCTION
Time: 0,565 ms
test=*# create or replace function ignore_val2_update() returns trigger as $$begin new.val2 := old.val2; return new; end; $$ language plpgsql;
CREATE FUNCTION
Time: 0,391 ms
test=*# create trigger trg1 before insert on hibiscus for each row execute procedure ignore_val2_insert();
CREATE TRIGGER
Time: 0,295 ms
test=*# create trigger trg2 before update on hibiscus for each row execute procedure ignore_val2_update();
CREATE TRIGGER
Time: 0,339 ms
test=*# insert into hibiscus values (1, 10, 20);
INSERT 0 1
Time: 0,586 ms
test=*# select * from hibiscus ;
id | val1 | val2
----+------+------
1 | 10 |
(1 row)
Time: 0,235 ms
test=*# update hibiscus set val2=30 where id = 1;
UPDATE 1
Time: 0,531 ms
test=*# select * from hibiscus ;
id | val1 | val2
----+------+------
1 | 10 |
(1 row)