title: How to extract uuid inserted into a row as a primary key via a trigger
body: <p>Consider the table:</p>
  
  <pre><code>CREATE TABLE `information` (
      `id` char(36) NOT NULL,
      `data` text NOT NULL,
      PRIMARY KEY (`id`)
  )
  </code></pre>
  
  <p>with the trigger:</p>
  
  <pre><code>CREATE TRIGGER `information_uuid_ins_trg` 
  BEFORE INSERT ON information 
  FOR EACH ROW
  BEGIN
      SET NEW.id = UUID();
  END;
  </code></pre>
  
  <p>What I'd like to be able to do, is to know the id that was used with the previous insert statement.</p>
  
  <p>INSERT INTO information ( data ) VALUES ('[some data]')</p>
  
  <p>Given a replicated master-master environment where the [some data] is not guaranteed to be unique. Obviously the <a href="http://dev.mysql.com/doc/refman/5.5/en/information-functions.html#function_last-insert-id" rel="nofollow">last_insert_id()</a> can't be used since the field is not an auto_increment field. Adding an update of a temp table with LAST_INSERT_ID(UUID(  )) won't work since LAST_INSERT_ID(expr) expects an integer value as expr. In OracleRDBMS I would approach this with:</p>
  
  <pre><code>INSERT INTO information 
  (data) values ('[some data]') 
  RETURNING id INTO var_id
  </code></pre>
  
  <p>or with Microsoft SQL Server / Postgres I would use: </p>
  
  <pre><code>INSERT INTO information 
  (data) values ('[some data]') 
  OUTPUT INSERTED.*
  </code></pre>
  
  <p>This would all be called from a PHP frontend running on a collection of webservers. </p>
  
  <p>Any thoughts as to how to return the uuid pk in mysql?</p>