【发布时间】:2021-12-05 18:03:48
【问题描述】:
我正忙于使用 Python 的 pymssql 查询 SQL Server 数据库,并从以下查询中得到一个奇怪的结果
cursor = conn.cursor()
cursor.execute("select current_value from sys.sequences where name = 'testSequence'")
currentValue = cursor.fetchone()[0]
cursor.close()
print(currentValue)
打印中的值显示为b'.\x00\x00\x00\x00\x00\x00\x00'
然后当我尝试将字节转换为整数时
currentValue = int.from_bytes(cursor.fetchone()[0], byteorder="big")
我得到了一个非常大的数字3530822107858468864
在 SQL Server Studio 中执行完全相同的查询,我可以看到实际的 current_value 只是 40。是我做错了转换还是有什么我没有看到?
注意
只是额外提及我正在使用 Python3(以防有人看不到标签)
【问题讨论】:
-
哪个数据类型有 current_value
-
它的数据类型是
long -
不,不是,我弄错是
bigint
标签: sql python-3.x byte pymssql