title: Using tsvector update trigger in Postgres trigger
body: <p>I have a <code>tsvector</code> column that I want to update when the row changes. For an <code>INSERT</code> I am using this trigger:</p>
  
  <pre><code>CREATE TRIGGER albums_vector_insert BEFORE INSERT
  ON albums
  FOR EACH ROW EXECUTE PROCEDURE
   tsvector_update_trigger('search_vector', 'pg_catalog.english', 'name')
  </code></pre>
  
  <p>Which works fine, seemingly. I would like to use another trigger on <code>UPDATE</code> clauses, but I only want it to fire when the name actually changes, so I dont waste cycles updating the search vector needlessly. I've tried this:</p>
  
  <pre><code>CREATE TRIGGER albums_vector_update BEFORE UPDATE ON albums
  FOR EACH ROW EXECUTE PROCEDURE
      IF NEW.name &lt;&gt; OLD.name THEN
          tsvector_update_trigger(search_vector, 'pg_catalog.english', name);
      END IF;
  </code></pre>
  
  <p>But this throws 2 errors when I try to create the trigger:</p>
  
  <pre><code>Error : ERROR:  syntax error at or near "NEW"
  LINE 3:  IF NEW.name &lt;&gt; OLD.name THEN
              ^
  Error : ERROR:  syntax error at or near "IF"
  LINE 1: END IF
              ^
  </code></pre>
  
  <p>From my understanding, if I use the trigger procedure syntax, ala:</p>
  
  <p><code>CREATE OR REPLACE FUNCTION something() RETURNS TRIGGER</code></p>
  
  <p>then associate my function with a trigger, then I wont be able to use the built-in <code>tsvector_update_trigger</code> function and will need to handle the <code>ts_vector</code> manipulation myself. Hence my trying to use the all-in-one-trigger+procedure syntax...</p>
  
  <p>Any ideas?</p>