How can I force the value of a MySQL query to use a particular collation?

試著忘記壹切 提交于 2019-12-11 00:29:19

问题


I want to use UUID() to generate primary keys.

After some investigation, I thought this should work:

INSERT INTO aTable (`id`) VALUES (UNHEX(REPLACE(UUID(),'-','')));

Where id is of the type BINARY(16).

Unfortunately, UUID() returns a value which uses the utf8_general_ci collation. The rest of my database uses utf8_unicode_ci, which means I get the following error:

#1270 - Illegal mix of collations (utf8_general_ci,COERCIBLE), (utf8_unicode_ci,COERCIBLE), (utf8_unicode_ci,COERCIBLE) for operation 'replace'

How can I persuade UUID() to play nicely and use utf8_unicode_ci?


回答1:


INSERT INTO aTable (`id`) VALUES (UNHEX(REPLACE(UUID() COLLATE utf8_unicode_ci,'-','')));


来源:https://stackoverflow.com/questions/6668989/how-can-i-force-the-value-of-a-mysql-query-to-use-a-particular-collation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!