Python 与 SQL Server 之间的数据类型映射
适用于: SQL Server 2017 (14.x) 及更高版本 Azure SQL 托管实例
本文列出了在 SQL Server 机器学习服务中使用 Python 集成功能时所支持的数据类型以及所执行的数据类型转换。
与 SQL Server 相比,Python 支持的数据类型数量有限。 因此,每当在 Python 脚本中使用 SQL Server 中的数据时,SQL 数据都可能会隐式转换为兼容的 Python 数据类型。 但是,通常无法自动执行精确的转换并将返回错误。
Python 和 SQL 数据类型
下表列出了提供的隐式转换。 不支持其他数据类型。
SQL 类型 | Python 类型 | 说明 |
---|---|---|
bigint | float64 |
|
binary | bytes |
|
bit | bool |
|
char | str |
|
date | datetime |
|
datetime | datetime |
支持 SQL Server 2017 CU6 及更高版本(具有 datetime.datetime 或 Pandaspandas.Timestamp 类型的 NumPy 数组)。 sp_execute_external_script 现在支持使用秒的小数形式的 datetime 类型。 |
float | float64 |
|
nchar | str |
|
nvarchar | str |
|
nvarchar(max) | str |
|
real | float64 |
|
smalldatetime | datetime |
|
smallint | int32 |
|
tinyint | int32 |
|
uniqueidentifier | str |
|
varbinary | bytes |
|
varbinary(max) | bytes |
|
varchar(n) | str |
|
varchar(max) | str |
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈