How in the trigger to track the change column for a specific value?

In a database PostgreSQL has a table called SURVEYS (POLLS). It looks like this:

| ID (uuid) | name (varchar) | status (boolean) | update_at (timestamp) | 
|--------------------------------------|----------------|------------------|--------------------------|
| 9bef1274-f1ee-4879-a60e-16e94e88df38 | Doom| 1 | 2019-03-26 00:00:00 |


In this table, as you can see, the columns are status (status) and update_at (last updated).

If a record changes the value in the column status to 2 and update_at to any new value, you need to run the function. In the function itself are going to use the record ID that was changed. I understand that checking for a value in column status should be done at trigger level and not function level? I've created this trigger, but not sure how it is correct in my case.

CREATE TRIGGER –°HECK_FOR_UPDATES_IN_SURVEYS
BEFORE UPDATE ON SURVEYS
FOR EACH ROW
WHEN 
 (OLD.update_at IS DISTINCT FROM NEW.update_at)
AND 
 (OLD.the condition IS DISTINCT FROM NEW.condition AND NEW.condition = 2)
EXECUTE PROCEDURE CREATE_SURVEYS_QUESTIONS_RELATIONSHIP(NOV.id);
March 19th 20 at 08:40
0 answer

Find more questions by tags PostgreSQL