Answer the question
In order to leave comments, you need to log in
How to check if certain fields have changed on Update in PostgreSQL?
I have a table with 20 fields. It is necessary to check on UPDATE that the value of 15 of these fields has not changed during the update (the most important ones). If they have changed, then make a record in another table. What is the easiest way to do this?
Whether manually twice to write all titles of fields?
IF NEW.abc <> OLD.abc AND NEW.bac <> OLD.bac AND .... THEN
INSERT INTO ...;
END IF;
Answer the question
In order to leave comments, you need to log in
I asked myself, I found the answer myself:
IF ROW(NEW.fieldA, NEW.fieldB, NEW.fieldC) IS DISTINCT FROM
ROW(OLD.fieldA, OLD.fieldB, OLD.fieldC) THEN
-- here code
END IF;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question