remove dash of UUID generated directly on MySQL
10,192
REPLACE(UUID(),'-','')
You don't need the UNHEX, just simply replace the hyphens.
Comments
-
fishcracker almost 2 years
I generate
UUID
usingINSERT 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 usingstr_replace()
. -
fishcracker over 11 yearsWhy do I need to
UNHEX
it? My column type is simply justVARCHAR
-
adambullmer over 8 yearsIf you're using the UUID as a PRIMARY KEY, then you'll want to store it as a
BINARY(16)
instead of aVARCHAR(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