Search code examples
uuidsinglestore

MemSQL generate UUID


I would like to migrate the database from MySQL to MemSQL. Original database use UUID as ID generated by function UUID(). Is there any possibility, how to use a similar function for generating those ID's?


Solution

  • MemSQL does not have a built-in UUID() function, but you can generate unique ids in various ways, depending on what you need them for, such as:

    • Generate random hashes. You can do this by e.g. SHA1(RAND()), or to get 16 bytes of randomness CONCAT(SUBSTRING(SHA1(RAND()), 1, 16), SUBSTRING(SHA1(RAND()), 1, 16)).
    • Use auto_increment to generate ids unique within a table
    • Generate UUIDs in the application side

    If you need them to follow the UUID format, you can reformat them with string functions