I have this function built using PostgreSQL:
CREATE OR REPLACE FUNCTION "db"."t_pencabutan_likuidasi_after_update"()
RETURNS "pg_catalog"."trigger" AS $BODY$
BEGIN
IF(NEW.status <> OLD.status) THEN
INSERT INTO
t_pencabutan_likuidasi_log(id_pencabutan, id_profile, nama_petugas, nip_petugas, status, catatan)
VALUES(
NEW.id_pencabutan, NEW.id_profile, NEW.nama_petugas, NEW.nip_petugas, NEW.status, NEW.catatan);
END IF;
RETURN NEW;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
Above is a function that will triggered BEFORE UPDATE of the table liquidator
.
The problem is some of the fill on the INSERT
were not mandatory inserted, like nama_petugas
and nip_petugas
which is a temporary value. Sometimes it is inserted, but sometimes it isn't. It gives an error like this:
ERROR: record "new" has no field "nama_petugas"
How could I leave it blank when there is no value/variable that is inserted for nama_petugas
and nip_petugas
?
Here is my trigger function;
CREATE TRIGGER
"t_pencabutan_likuidasi_after_update"
AFTER UPDATE OF "status"
ON "db"."liquidator"
FOR EACH ROW
EXECUTE PROCEDURE
"db"."t_pencabutan_likuidasi_after_update"();