I have two tables
Main table
Sub table
My intention is to use a trigger function to insert the new row into the Sub Table if it fulfils a condition of a column not being Null.
I have tried this method but my Sub Table will still insert the row with a null value
BEGIN
INSERT INTO unsubscriber_list("ID","Name","Email","unsubdate")
SELECT new."ID",new."Name",new."Email",new."date_of_unsub" FROM master_database
WHERE date_of_unsub IS NOT NULL
ORDER BY "account_created_on" DESC LIMIT 1;
RETURN NULL;
END;
I have also tried an IFTHEN condition but it produces error
BEGIN
IF master_database.date_of_unsub IS NOT NULL THEN
INSERT INTO unsubscriber_list("ID","Name","Email","unsubdate")
SELECT new."ID",new."Name",new."Email",new."date_of_unsub" FROM master_database;
END IF;
RETURN NULL;
END;
This is the error that they showed
ERROR: missing FROM-clause entry for table "master_database"
LINE 1: SELECT master_database.date_of_unsub IS NOT NULL
My expected result is one whereby an Insert Trigger activates the Trigger Function whereby it validates if that specific column IS NOT NULL
If Null: ignore If not Null: Insert.
newrecord is automatically available in a trigger function.