remove dash of UUID generated directly on MySQL

10,192
REPLACE(UUID(),'-','')

You don't need the UNHEX, just simply replace the hyphens.

Share:
10,192
fishcracker
Author by

fishcracker

Crunchy, salty, yummy!

Updated on June 05, 2022

Comments

  • fishcracker
    fishcracker almost 2 years

    I generate UUID using INSERT INTO tbl1 (key, val) VALUES (UUID(), :value) directly on MySQL using PDO. I don't have any idea how to remove those - (dashes) on MySQL side, on PHP side I can simply remove it using str_replace().

  • fishcracker
    fishcracker over 11 years
    Why do I need to UNHEX it? My column type is simply just VARCHAR
  • adambullmer
    adambullmer over 8 years
    If you're using the UUID as a PRIMARY KEY, then you'll want to store it as a BINARY(16) instead of a VARCHAR(32). It'll really boost your performance when it comes to datasets as small as the 10's of thousands. To do so, you would need to strip dashes and unhex it as in this example. You can read more about UUIDs as Primary Keys from a percona blog here