Note that there are some explanatory texts on larger screens.

plurals
  1. POMySQL Trigger after update only if row has changed
    primarykey
    data
    text
    <p>Is there any possibility to use an "after update" trigger only in the case the data has been REALLY changed. I know of "NEW and OLD". But when using them I'm only able to compare columns. For example "NEW.count &lt;> OLD.count".</p> <p>But I want something like: run trigger if "NEW &lt;> OLD"</p> <p>An Example:</p> <pre><code>create table foo (a INT, b INT); create table bar (a INT, b INT); INSERT INTO foo VALUES(1,1); INSERT INTO foo VALUES(2,2); INSERT INTO foo VALUES(3,3); CREATE TRIGGER ins_sum AFTER UPDATE ON foo FOR EACH ROW INSERT INTO bar VALUES(NEW.a, NEW.b); UPDATE foo SET b = 3 WHERE a=3; Query OK, 0 rows affected (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 0 select * from bar; +------+------+ | a | b | +------+------+ | 3 | 3 | +------+------+ </code></pre> <p>The point is, there was an update, but <strong>nothing has changed</strong>. But the trigger ran anyway. IMHO there should be a way it doesn't.</p> <p>I know that I could have used </p> <blockquote> <p>IF NOW.b &lt;> OLD.b</p> </blockquote> <p>for this example.</p> <p>BUT imagine a large table with changing columns. You have to compare every column and if the database changes you have to adjust the trigger. AND it doesn't "feel" good to compare every column of the row hardcoded :)</p> <p><strong>Addition</strong></p> <p>As you can see on the line </p> <blockquote> <p>Rows matched: 1 Changed: 0 Warnings: 0</p> </blockquote> <p>MySQL knows that the line didn't change. But it doesn't share this knowledge with the trigger. A trigger like "AFTER REAL UPDATE" or something like this would be cool.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload