适用于: 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 及更高版本(具有 或 Pandas datetime.datetime 类型的 NumPy 数组pandas.Timestamp)。
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 |