The trigger currently only gets triggered when an existing record is modified.
create or replace TRIGGER library
BEFORE update ON books
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
WHEN ( new.author != old.author
) DECLARE
I am confused whey it's not getting triggered for a new record because old.author would be equal to null so it would new.author != null, which is true. How do I get the trigger to work for new records and existing record modifications?
I have tried modifying it to check for insert and IS NULL
create or replace TRIGGER library
BEFORE update or insert ON books
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
WHEN ( old.author IS NULL or old.author = '' OR new.author != old.author
) DECLARE
but it's still not working.
new.author != NULL
andnew.author = NULL
are both always false. Instead use this syntax:new.author IS NOT NULL
ornew.author IS NULL
– Nick.McDermaid