title: Set a temporary global variable during a Postgres query
body: <p>Is it possible to set a variable during a query (valid only for the query in question) that can be captured by a TRIGGER procedure?</p>
  
  <p>For example, I want to record the ID of the executor of a query (current_user is always the same).
  So I would do something like this:</p>
  
  <pre><code>tbl_executor (
    id   PRIMARY KEY,
    name VARCHAR
  );
  tbl_log (
    executor REFERENCE tbl_executor(id),
    op VARCHAR
  );
  tbl_other ...
  
  CREATE TRIGGER t AFTER INSERT OR UPDATE OR DELETE ON tbl_executor 
  FOR EACH ROW 
  EXECUTE PROCEDURE (INSERT INTO tbl_log VALUES( ID_VAR_OF_THIS_QUERY ,TG_OP))
  </code></pre>
  
  <p>Now if I run a query like:</p>
  
  <pre><code>INSERT INTO tbl_other 
  VALUES(.......) - and set ID_VAR_OF_THIS_QUERY='id of executor' -
  </code></pre>
  
  <p>I get the following result:</p>
  
  <pre><code>           tbl_log
  -----------------------------
  id                | op      |
  -----------------------------
  'id of executor'  | 'INSERT'|
  </code></pre>
  
  <p>I hope I have made the idea... and I think it is hardly feasible... but is there anyone who could help me?</p>