skip to Main Content

I’m trying to SELECT data from a table that stores Java UUIDs as binary(16).

For example, the UUID 76572de1-aa8c-435b-afe4-8e260e19466b looks like this in phpMyAdmin: 0x76572de1aa8c435bafe48e260e19466b.

Now, how can I query any values from that table by using a simple string?:

  • SELECT ... WHERE uuid = '76572de1-aa8c-435b-afe4-8e260e19466b'
  • SELECT ... WHERE uuid = '76572de1aa8c435bafe48e260e19466b'
  • SELECT ... WHERE uuid = '0x76572de1-aa8c-435b-afe4-8e260e19466b'
  • SELECT ... WHERE BINARY uuid = '76572de1aa8c435bafe48e260e19466b'
  • SELECT ... WHERE BINARY uuid = '76572de1-aa8c-435b-afe4-8e260e19466b'
  • and a lot of other things utilizing CONVERT or BINARY keywords

2

Answers


  1. Hexadecimal literals in MySQL look like this: X'01AF' or this: 0x01AF (case insensitive in both cases.

    One option would be SELECT ... WHERE uuid = X'76572de1aa8c435bafe48e260e19466b'

    Login or Signup to reply.
  2. Use BIN_TO_UUID() and UUID_TO_BIN() functions.

    SELECT ... WHERE uuid = UUID_TO_BIN('76572de1-aa8c-435b-afe4-8e260e19466b')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search