Let’s suppose I have an instruction that does the following:
update client set active = 0;
Is there any way to do it in Firebird, the same thing as Oracle does …
if updating (active) ...
The trigger would only be executed if it had only only updating the “active” column.
I tried that way, but it’s not working:
CREATE OR ALTER TRIGGER CLIENT_SYNC FOR CLIENT ACTIVE BEFORE INSERT OR UPDATE POSITION 0 as begin IF UPDATE(ACTIVE) new.ACTIVE = NULL; end;
Advertisement
Answer
Firebird doesn’t have anything like updating
. You need to compare the previous value (in the old
context variable) with the new value (in the new
context variable), preferably using is distinct from
to avoid issues with null
:
set term #; CREATE OR ALTER TRIGGER CLIENT_SYNC FOR CLIENT ACTIVE BEFORE INSERT OR UPDATE POSITION 0 as begin IF (old.active is distinct from new.active) then new.ACTIVE = NULL; end# set term ;#
The update of by setting new.ACTIVE = null
seems a bit odd in the context, but I assume that is just a placeholder (otherwise ACTIVE
can never by anything other than null
).
And be sure to consult the Firebird documentation on procedural SQL, as the code in your question has several other syntax errors.