Mengupdate nilai suatu kolom, jika nilai kolom lain berubah
Contoh :CREATE OR REPLACE FUNCTION soal_set_status_akhir()
RETURNS TRIGGER
AS $$
BEGIN
NEW.status_akhir := CASE WHEN NEW.id_status_soal = 1 THEN 1
ELSE 0 END;
RETURN NEW;
END $$ LANGUAGE plpgsql;
DROP TRIGGER IF EXISTS soal_set_status_akhir ON soal;
CREATE TRIGGER soal_set_status_akhir
BEFORE INSERT OR UPDATE ON soal
FOR EACH ROW
EXECUTE PROCEDURE soal_set_status_akhir();
Referensi
- Create Trigger, https://www.postgresql.org/docs/9.1/static/sql-createtrigger.html
- Postgresql Trigger based on value of one column to change or update value of other column in each row., http://stackoverflow.com/questions/20958569/postgresql-trigger-based-on-value-of-one-column-to-change-or-update-value-of-oth
- Dokumentasi : Database, http://banksoal.openthinklabs.com/2017/01/dokumentasi-database.html
No comments:
Post a Comment