Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Data Type Conversion

Sumit Sarabhai edited this pageJul 1, 2025 ·7 revisions

Python 3

Python Parameters Sent to the Database
The following table explains how Python objects passed to Cursor.execute() as parameters are formatted and sent to the driver/database.

DescriptionPython DatatypeODBC Datatype
nullNoneSQL_VARCHAR
booleanboolBIT
integerintSQL_TINYINT, SQL_SMALLINT, SQL_INTEGER, SQL_BIGINT
floating pointfloatSQL_DOUBLE
decimaldecimal.DecimalSQL_NUMERIC
stringstrSQL_VARCHAR or SQL_LONGVARCHAR
binarybytes, bytearraySQL_BINARY or SQL_VARBINARY
datedatetime.dateSQL_TYPE_DATE
timedatetime.timeSQL_TYPE_TIME
timestampdatetime.datetimeSQL_TYPE_TIMESTAMP
UUID / GUIDuuid.UUIDSQL_GUID

Note on Description Column:

The "Description" column in the table is intended to provide a generic label for the type, and does not always reflect the exact SQL Server data type name. Please refer to the SQL Server column type for precise behavior and compatibility.

Note on SQL Server's timestamp and rowversion types

  • In SQL Server, thetimestamp type is a deprecated alias forrowversion, which is a binary type (binary(8)) used for version-stamping table rows.It does not represent a date or time value.
  • The mapping table above may refer to "timestamp" as a generic type label, but this shouldnot be confused with SQL Server'stimestamp/rowversion type.
  • At this time,rowversion/timestamp columns are not mapped to Python'sdatetime.datetime type; they should be treated as unsupported or as binary data.
  • For actual date/time values, use SQL Server types such asdatetime,datetime2,smalldatetime, ordate.

Caution

If you need to use SQL Server'srowversion/timestamp, handle these columns as binary data in your Python code. They do not carry any date or time information.


SQL Values Received from the Database
The following table describes how database results are converted to Python objects.

DescriptionODBC DatatypePython Datatype
NULLanyNone
bitSQL_BITbool
integersSQL_TINYINT, SQL_SMALLINT, SQL_INTEGER, SQL_BIGINTint
floating pointSQL_REAL, SQL_FLOAT, SQL_DOUBLEfloat
decimal, numericSQL_DECIMAL, SQL_NUMERICdecimal.Decimal
1-byte textSQL_CHARstr via UTF-8
2-byte textSQL_WCHARstr via UTF-16LE
binarySQL_BINARY, SQL_VARBINARYbytes
dateSQL_TYPE_DATEdatetime.date
timeSQL_TYPE_TIMEdatetime.time
timestampSQL_TIMESTAMPdatetime.datetime
UUID / GUIDSQL_GUIDstr or uuid.UUID
Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp