Storing MySQL GUID/UUIDs(存储 MySQL GUID/UUID)
问题描述
这是我能想到的将 UUID() 生成的 MySQL GUID/UUID 转换为二进制 (16) 的最佳方法:
This is the best way I could come up with to convert a MySQL GUID/UUID generated by UUID() to a binary(16):
UNHEX(REPLACE(UUID(),'-',''))
然后将其存储在 BINARY(16) 中
And then storing it in a BINARY(16)
这样做有什么我应该知道的含义吗?
Are there any implications of doing it this way that I should know of?
推荐答案
影响不大.它会稍微减慢查询速度,但您几乎不会注意到它.
Not many implications. It will slow down the queries a little, but you will hardly notice it.
UNIQUEIDENTIFIER 无论如何都会在内部存储为 16 字节二进制.
UNIQUEIDENTIFIER is stored as 16-byte binary internally anyway.
如果您要将二进制文件加载到客户端并在那里解析,请注意 bit order,它可能具有不同于初始 NEWID() 的其他字符串表示.
If you are going to load the binary into a client and parse it there, note the bit order, it may have other string representation than the initial NEWID().
Oracle 的 SYS_GUID() 函数很容易出现这个问题,将其转换为字符串会在客户端和服务器上产生不同的结果.
Oracle's SYS_GUID() function is prone to this issue, converting it to a string gives different results on client and on server.
这篇关于存储 MySQL GUID/UUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:存储 MySQL GUID/UUID
基础教程推荐
- 带有WHERE子句的LAG()函数 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
