title: Postgres trigger after insert accessing NEW
body: <p>I have a pretty simple trigger:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION f_log_datei()
  RETURNS TRIGGER AS $$
  BEGIN
    INSERT INTO logs (aktion, tabelle, benutzer_id) VALUES(TG_OP, 'dateien', NEW.benutzer_id);
  END; $$ LANGUAGE 'plpgsql';
  
  CREATE TRIGGER log_datei AFTER INSERT OR UPDATE OR DELETE
  ON dateien
  FOR EACH STATEMENT
  EXECUTE PROCEDURE f_log_datei();
  </code></pre>
  
  <p>My table logs is the following:</p>
  
  <pre><code>CREATE TABLE logs(
      id int PRIMARY KEY DEFAULT NEXTVAL('logs_id_seq'),
      zeit timestamp DEFAULT now(),
      aktion char(6),
      tabelle varchar(32),
      alt varchar(256),
      neu varchar(256),
      benutzer_id int references benutzer(id)
  );
  </code></pre>
  
  <p>After inserting something in dateien I get the following error:</p>
  
  <pre><code>ERROR:  record "new" is not assigned yet
  DETAIL:  The tuple structure of a not-yet-assigned record is indeterminate.
  CONTEXT:  SQL statement "INSERT INTO logs (aktion, tabelle, benutzer_id) VALUES(TG_OP, 'dateien', NEW.benutzer_id)"
  PL/pgSQL function "f_log_datei" line 3 at SQL statement
  </code></pre>
  
  <p>Why did I get this error? I looked into the documentation and it seems they use new in the same way I do.</p>