title: Inserting and selecting UUIDs as binary(16)
body: <p>I don't understand why</p>
  
  <pre><code>SELECT UUID();
  </code></pre>
  
  <p>Returns something like:</p>
  
  <pre><code>3f06af63-a93c-11e4-9797-00505690773f
  </code></pre>
  
  <p>But if I insert it into a binary(16) field (the UUID() function) with for instance a BEFORE INSERT trigger and run a select, it returns something like:</p>
  
  <pre><code>0782ef48-a439-11
  </code></pre>
  
  <p>Note that these two UUIDs are not the same data.</p>
  
  <p>I realize binary and an UUID string doesn't look identical, but shouldn't the selected data at least be just as long? Otherwise how can it possibly be equally likely to be unique?</p>
  
  <p>Is it better to store it as char(36)? I just need it to be unique to prevent duplicate inserts. It is never selected or used for joins.</p>
  
  <p>EDIT:</p>
  
  <p>before trigger would be like:</p>
  
  <pre><code>BEGIN
  
  if NEW.UUID IS NULL THEN
  
  NEW.UUID = UUID();
  
  END IF
  
  END
  </code></pre>