Answer the question
In order to leave comments, you need to log in
PostgreSQL, why is the "TG_TABLE_NAME" variable not being substituted?
Good afternoon!
Why does an error occur and the data from the variable is not substituted?
Trigger and function code:
CREATE OR REPLACE FUNCTION update_dt_column() RETURNS TRIGGER AS $$
BEGIN
UPDATE TG_TABLE_NAME SET dt_update = NOW() WHERE id = NEW.id;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER t_phones_dt_update
AFTER UPDATE ON phones FOR EACH ROW EXECUTE PROCEDURE update_dt_column();
Answer the question
In order to leave comments, you need to log in
Because why did you decide that pl/pgsql has an update variable set syntax? He is not here. This place is always the name of the table.
However, the trigger is completely absurd and will not generate anything other than an infinite recursion.
You need a before insert trigger with
NEW.dt_update = NOW();
return NEW;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question