title: How to modify Trigger to update a single attribute in PostgreSQL
body: <p>Here is my sample table.</p>
  
  <pre><code>CREATE TABLE employee_test(
  idTst SERIAL PRIMARY KEY, 
  monthDownload VARCHAR(6),
  changeDate DATE);
  </code></pre>
  
  <p>I am trying to create a function and trigger that would update changeDate attribute with a current date when monthDownload attribute is updated. 
  The function I have it works with one problem. It updates all records instead of the one that was updated. <br></p>
  
  <pre><code> CREATE OR REPLACE FUNCTION downloadMonthChange() 
   RETURNS TRIGGER AS 
   $$
   BEGIN
   IF NEW.monthDownload &lt;&gt; OLD.monthDownload THEN
   UPDATE employee_test
   SET changeDate = current_date
   where OLD.idTst = NEW.idTst;
   END IF;
   RETURN NEW;
   END;
   $$ 
   Language plpgsql;
  </code></pre>
  
  <p>Trigger</p>
  
  <pre><code>Create TRIGGER dataTest
  AFTER UPDATE
  ON employee_test
  FOR EACH ROW
  EXECUTE PROCEDURE downloadMonthChange();
  </code></pre>
  
  <p>When I execute the following Update statement:</p>
  
  <pre><code>UPDATE  employee_test SET  monthDownload = 'oct12'
  WHERE idTst = 1;
  </code></pre>
  
  <blockquote>
    <p>All changeDate rows get update with a current date. 
    Is there a way to have only a row with changed record to have a current date updated. </p>
    
    <p><a href="https://i.stack.imgur.com/83dQ8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/83dQ8.png" alt="enter image description here"></a></p>
  </blockquote>