I'm trying to use a trigger function to update old records in the same table and mark them as redundant if a new record supersedes them.
I'm trying to use TG_TABLE_NAME
as a generic way to update whichever table caused this trigger to fire. My code looks like this:
BEGIN
UPDATE TG_TABLE_NAME
SET "Redundant"=true
WHERE "DocumentID"=NEW."DocumentID"
AND "RecordID" = NEW."RecordID"
AND "TransactionID" < NEW."TransactionID"
AND "Redundant" = false ;
RETURN NEW;
END
But when the trigger fires, postgres complains that it can't find a table called "tg_table_name"
I'm guessing I'm doing something obviously wrong, but I'm new to pl/PGSQL. Does anyone have any advice for how to update old records (with matching RecordID and smaller TransactionID) ?