使用 python 从 MSSQL 读取 uniqueidentifier 字段

发布于 2024-10-29 13:12:28 字数 283 浏览 9 评论 0原文

我使用 pyodbc 访问我的 MSSQL 数据库。

当从 MSSQL 读取 uniqueidentifier 字段时,在我的 MacOS 中,我可以打印 udid 字段的正确值(例如 4C444660-6003-13CE-CBD5-8478B3C9C984),但是当我在 Linux CentOS 上运行相同的代码时,我只看到非常奇怪的字符串像“???E??6??????c”,值的类型是“buffer”,而不是MacOS中的“str”。

你能解释一下为什么会这样吗?我怎样才能在Linux上获得正确的uidi值?谢谢

I used pyodbc to access my MSSQL database.

When reading uniqueidentifier field from MSSQL, in my MacOS, I can print the correct value of udid field (e.g 4C444660-6003-13CE-CBD5-8478B3C9C984), however when I run the same code on Linux CentOS, i just see very strange string like "???E??6??????c", and the type of value is "buffer", not "str" as in MacOS.

Could you explain me why it is and how can i get correct value of uidi on linux? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

dawn曙光 2024-11-05 13:12:28

在linux中,我使用str(uuid.UUID(bytes_le=value)).upper()来获取像4C444660-6003-13CE-CBD5-8478B3C9C984这样的uniqueidentifier字段的字符串

In linux i use str(uuid.UUID(bytes_le=value)).upper() to get string like 4C444660-6003-13CE-CBD5-8478B3C9C984 of uniqueidentifier field

作业与我同在 2024-11-05 13:12:28

这已经有几年了,但我最近不得不解决同样的问题。我的解决方案是简单地将唯一标识符转换为 VARCHAR,这使我的 Python 代码保持整洁:

SELECT CAST(unique_id_column AS VARCHAR(36)) AS my_id FROM...

然后在 Python 中,只需输出 row.my_id。

This is a few years old, but I've had to tackle this same problem recently. My solution was to simply CAST the unique identifier as a VARCHAR, which kept my Python code nice and tidy:

SELECT CAST(unique_id_column AS VARCHAR(36)) AS my_id FROM...

Then in Python, simply output row.my_id.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文