For example, suppose I have the following database in PostgreSQL
CREATE DATABASE salary;
CREATE TABLE emp(NAME text PRIMARY key, salary integer NOT NULL);
I can create a trigger which will automatically call a particular function whenever an event occurs:
CREATE TRIGGER trig_emp_row_insert_before BEFORE INSERT ON emp FOR EACH ROW
EXECUTE PROCEDURE trig_emp_row_insert_before_fnc();
CREATE OR REPLACE FUNCTION trig_emp_row_insert_before_fnc()
RETURNS TRIGGER AS
$$
BEGIN
-- You Code --
RETURN NEW;
END;
$$
LANGUAGE 'plpgsql';
When I call INSERT INTO emp VALUES('alice', 10);
the function trig_emp_row_insert_before_fnc
will be automatically executed. Note that the trig_emp_row_insert_before_fnc
can further insert more records which fire the trigger again (It even can absorb events and so on).
Does SWI-Prolog support the trigger system like PostgreSQL?
Iād like to create triggers to handle event when some one calls assert
/ retract
. I found that prolog_listen/3 seems what I want, but it was placed in Hackers corner. So Iām not sure if this is the correct use.
Also, the dynamic database seems weaker than traditional database.
For example:
-
It have only āinsertā(assertz) and ādeleteā(retract), but no āupdateā operation?
-
It can only give me
p/1
not the full termp(a)
in the example below.:- dynamic p/1. :- prolog_listen(p/1, updated(p/1)). updated(Pred, Action, Context) :- format('Updated ~p: ~p ~p~n', [Pred, Action, Context]). ?- assert(p(a)). Updated p/1 assertz <clause>(000000000280D8D0) % I want to get p(a) instead of p/1 true.
Thanks.