title: postgres - creating trigger functions with arguments
body: <p>I was wondering if it was possible to create a trigger function with arguments, since the function's logic is the same, but may just insert into different tables and column names.</p>
  
  <p>Here's the function:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION 
      createInstance(table_name TEXT, column_name TEXT) 
  RETURNS TRIGGER AS
  $BODY$
  BEGIN
      INSERT INTO
          table_name
          (
              column_name,
              account_id
          )
      VALUES
          (
              new._id,
              new.account_id
          );
  
      RETURN new;
  END;
  $BODY$
  language plpgsql;
  </code></pre>
  
  <p>The error:</p>
  
  <pre><code>ERROR:  trigger functions cannot have declared arguments
  HINT:  The arguments of the trigger can be accessed through TG_NARGS and TG_ARGV instead.
  CONTEXT:  compilation of PL/pgSQL function "createinstance" near line 1
  </code></pre>
  
  <p>Example trigger:</p>
  
  <pre><code>CREATE TRIGGER trig_instanced_item_copy
      AFTER INSERT ON creator.items
      FOR EACH ROW
      EXECUTE PROCEDURE createInstance();
  </code></pre>