MySQL Forums
Forum List  »  Stored Procedures

Re: UUID column type
Posted by: Lawrence Holtsclaw
Date: October 19, 2005 07:28AM

That's because the UUID() function returns the uuid value in text format, not binary or other native type. You would have to parse that into binary in order to store it as such. Casting it will simply store the characters for the text into the binary "string," not convert it since the source is just a string. For casting to make sense, MySQL would have to provide a native UUID datatype.

I was assuming you were using this table in conjunction with an application and pumping the data in/out in binary. To freely convert string and binary UUID representations in a stored procedure, you'll need to write a pair of conversion functions to parse and decode. To encode it to binary, I'd suggest something like the following:

CONCAT(UNHEX(LEFT(my_uuid,8)),UNHEX(MID(my_uuid,10,4)),UNHEX(MID(my_uuid,15,4)),UNHEX(MID(my_uuid,20,4)),UNHEX(RIGHT(my_uuid,12)))

Converting back to text is similar using HEX() and then inserting the hyphens at the appropriate points.

Clear as mud?

Options: ReplyQuote


Subject
Views
Written By
Posted
66171
October 16, 2005 10:15AM
28990
October 18, 2005 09:03AM
21880
October 18, 2005 07:47PM
Re: UUID column type
27935
October 19, 2005 07:28AM
18719
October 28, 2005 03:58AM
17235
September 08, 2007 03:46PM
15764
November 04, 2005 09:22AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.