title: Update timestamp in postgresSQL after a tuple update
body: <p>I have a table X with 4 attributes and several tuples of information. One of those attributes called 'Update Date' collects the current timestamp of when those records were introduced to the table.</p>
  <p>So, what I would like is to implement a function and trigger that will update the 'Update Date' attribute of a record when a change occurs in that record only, indicating the new CURRENT TIMESTAMP.</p>
  <p>For example,</p>
  <p>In a record ('Susan', 'Parker', '27',05-05-2020 00:00:00:00), I want that changing the first field 'Susan' will also cause a change in the fourth attribute with the new current timestamp.</p>
  <p>I have tried to implement the function as follows:</p>
  <p>I imagine that the function must include UPDATE for them to be entered and I have performed the function this way but it is not implemented correctly.</p>
  <pre><code>CREATE FUNCTION function()
  RETURNS trigger language plpgsql AS $$
  BEGIN
      IF (NEW.attribute1 &lt;&gt; OLD.attribute1) THEN
          UPDATE table SET Date_update DEFAULT CURRENT_TIMESTAMP;
      END IF;
      IF (NEW.attribute2 &lt;&gt; OLD.attribute2) THEN
          UPDATE table SET Date_update DEFAULT CURRENT_TIMESTAMP;
      END IF;
      IF (NEW.attribute3 &lt;&gt; OLD.attribute3) THEN
          UPDATE table SET Date_update DEFAULT CURRENT_TIMESTAMP;
      END IF;
      RETURN DEFAULT CURRENT_TIMESTAMP;
  END;
  $$;
  
  </code></pre>
  <pre><code>CREATE TRIGGER trigger
  AFTER UPDATE ON table
  FOR EACH ROW EXECUTE PROCEDURE function();
  
  </code></pre>
  <p>Thank you in advance</p>