title | description | author | ms.author | ms.date | ms.service | ms.subservice | ms.topic | monikerRange |
---|---|---|---|---|---|---|---|---|
Convert Python and SQL data types |
Review the implicit and explicit data type conversions between Python and SQL Server in data science and machine learning solutions. |
VanMSFT |
vanto |
10/06/2020 |
sql |
machine-learning-services |
conceptual |
>=sql-server-2017||>=sql-server-linux-ver15||=azuresqldb-mi-current |
[!INCLUDE SQL Server 2017 SQL MI]
This article lists the supported data types, and the data type conversions performed, when using the Python integration feature in SQL Server Machine Learning Services.
Python supports a limited number of data types in comparison to SQL Server. As a result, whenever you use data from SQL Server in Python scripts, SQL data might be implicitly converted to a compatible Python data type. However, often an exact conversion cannot be performed automatically and an error is returned.
This table lists the implicit conversions that are provided. Other data types are not supported.
SQL type | Python type | Description |
---|---|---|
bigint | float64 |
|
binary | bytes |
|
bit | bool |
|
char | str |
|
date | datetime |
|
datetime | datetime |
Supported with SQL Server 2017 CU6 and above (with NumPy arrays of type datetime.datetime or Pandas pandas.Timestamp ). sp_execute_external_script now supports datetime types with fractional seconds. |
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 |