microsoft / microsoft/mssql-python

Separate Type Contructors for (var)char and n(var)char

オープン
#174 コメント 2 件 リアクション 0 件 担当者 1 名 GitHub で見る

@gargsaumya がすでに取り組んでいます。

2025年8月15日 から。

area: data-types enhancement inADO triage needed
主要言語
Python
スター
473
フォーク
60
平均マージ
2日 11時間
マージ済み PR(30日)
36

説明

Is your feature request related to a problem? Please describe.

Python strings don't have 2 distinct data types like SQL Server (which has (var)char and n(var)char); you define a string with single quotes (') or double quote (") and they have the same inferred data type. This poses a problem with SQL Server parameters as the "safer" option is to assume the string is an nvarchar, however, this causes problems with SARGability as if the column the parameter is compared to is varchar, at the column must be implicitly converted and thus can result in (significant) performance issues due to indexes not being about to be used for seek operations.

For those using UTF-8 collations, this could be even more of a "gotcha", as UTF-8 and UTF-16 will support the same characters (unlike Windows-1252, for example, which only supports 1 byte characters), but varchar values would be UTF-8 while nvarchar UTF-16. Many users are likely writing their Python files in UTF-8 so the strings they see are also UTF-8; if they are using a UTF-8 collated database then one would assume they would want varchar parameters, not nvarchar, as it's unlikely they would be using any nvarchar columns.

Describe the solution you'd like

Provide type objects and constructors for both varchar and nvarchar datatypes. This might copy types found else where, such as the String and WString ("Wide String") objects/constructors.

Describe alternatives you've considered

The alternative is that developers would need to be explicit and CAST/CONVERT the value to a varchar in the appropriate clause(s); i.e. MyColumn = CONVERT(varchar(30), ?). Otherwise they could assign the parameter to a variable first: DECLARE @MyColumn varchar(30) = ?;. This, however, might look odd if the query has to be ported to a different language that doesn't use inferred data types, and is likely to be less obvious to do to the "inexperience" developer.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。