title: Postgres triggers - adding old and new values
body: <p>I am trying to learn Postgres triggers, using some simple examples. I have created a simple table:</p>
  
  <pre><code>create table emp (empname text, salary integer, last_user text);
  </code></pre>
  
  <p>My goal is to replace the old salary with a new salary computed as the salary inserted (new) + the old salary. I could not get them to sum even when I did not put a condition (i.e. <code>empname</code> is the same)</p>
  
  <p>Here is my code:</p>
  
  <pre><code>-- this table returns a new row instead of summing
  CREATE OR REPLACE FUNCTION emp_stamp() RETURNS trigger
  AS $emp_stamp$
  BEGIN
  new.salary = new.salary + old.salary ;
  RETURN NEW; 
  END;
  $emp_stamp$ LANGUAGE plpgsql;
  
  CREATE  TRIGGER emp_stamp
  BEFORE UPDATE on emp
  FOR EACH ROW
  EXECUTE PROCEDURE emp_stamp();
  </code></pre>
  
  <p>When I insert into the table, I get a new row added and no existing rows follow the formula:</p>
  
  <pre><code>INSERT INTO EMP VALUES('BR',39970,'BR')
  </code></pre>
  
  <p>I have also unsuccessfully tried the <code>UPDATE</code> command.</p>