4

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
1

2 Answers 2

15

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'

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. I've tried that as well, but this just throws an Syntax error when trying to run that Query in phpMyAdmin.
Just edited to remove the hyphens from the guid, which are not valid syntax of course
I just found out about the function SELECT ... WHERE uuid = UNHEX(76572de1aa8c435bafe48e260e19466b)
4

Use BIN_TO_UUID() and UUID_TO_BIN() functions.

SELECT ... WHERE uuid = UUID_TO_BIN('76572de1-aa8c-435b-afe4-8e260e19466b')

4 Comments

Thank you very much. At least on my current server the BIN_TO_UUID function is not defined, so I'm going with the X'76572de1aa8c435bafe48e260e19466b' approach.
If you already know the binary value, why didn't you just use what you have? 0x76572de1aa8c435bafe48e260e19466b
what do you mean? The queries above aren't working, but it's working with the X.
I mean: WHERE uuid = 0x76572de1aa8c435bafe48e260e19466b - But never mind. Its the same as X'...'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.