Write SQL Your Way: Dual Parameter Style Benefits in mssql-python
mssql-python, Microsoft's Python driver for SQL Server and Azure SQL, now accepts both DB-API qmark (?) and pyformat (%(name)s) parameter styles, choosing between them by whether a tuple/list or a dict is passed. For dicts, the driver scans the SQL for named placeholders (skipping string literals, comments and bracketed identifiers), validates keys, builds a positional tuple that duplicates reused values, and rewrites the query to ? before ODBC binding, so there is no change in database communication or SQL-injection safety. Named parameters help with self-documenting queries, value reuse, dynamic filter building and sharing one dict across queries. Extra dict keys are ignored, mixing styles in one query fails, %% escapes literal patterns, and module paramstyle reports "pyformat".
Related posts
- Even Friendlier SQL with DuckDB
DuckDB mediumAdeptDuckDB extends SQL syntax with features that simplify everyday queries and enable dynamic analysis. Additions include reusable column aliases within a SELECT, COLUMNS() for selecting and transforming columns by regex, EXCLUDE/REPLACE or lambda, automatic JSON-to-nested-type conversion with dot notation, FROM-first queries, dot-operator function chaining, UNION/INSERT BY NAME, and dynamic PIVOT/UNPIVOT that need no hardcoded column values. Each feature is shown next to the verbose standard-SQL equivalent it replaces.
- Gems of DuckDB 2.0.0
DuckDB mediumAdeptDuckDB 2.0.0 LTS includes a set of smaller features beyond its headline items. The Python client gains an appender for buffered row inserts, though INSERT INTO ... SELECT remains faster for DataFrames and Arrow tables. The CLI adds pretty-printed .schema, a .manual function reference, calculator-style expressions and queryable command history via shell_history(). New SQL features include SHOW for settings, CREATE SECURE VIEW to hide statistics and plans, regexp_extract options, setval for sequences, session variables as prepared-statement defaults, custom PARTITION_PATH and ORDER_BY in COPY, GeoJSON writing, and extension-defined window functions.
- Introducing Apache Arrow Support in mssql-python
Microsoft for Python Developers mediumAdeptmssql-python can now fetch SQL Server result sets directly into Apache Arrow buffers, filled by a C++ fetch loop, so no Python object is created per row. Polars, Pandas (ArrowDtype) and DuckDB can then consume the data zero-copy through the Arrow C Data Interface. Three new cursor methods cover the main patterns: arrow_batch returns one RecordBatch, arrow returns a full Table (watch peak memory), and arrow_reader streams batches lazily, with batch_size trading throughput against memory. Gains are largest for temporal types like DATETIMEOFFSET, but NVARCHAR is currently slower on Linux because of the UTF-16 to UTF-8 conversion path, and a fix is planned.
- Ducks in a Column
DuckDB mediumAdeptDuckDB stores data by column and processes it in vectors of 2,048 values, which drives its compression, projection pushdown and aggregation speed. A tour built on a duck-sightings dataset shows querying CSV, Parquet, S3 and Hive-partitioned files in place (with zonemap row-group skipping and CSV type sniffing), column-level friendly SQL (EXCLUDE, REPLACE, COLUMNS() with regex or lambdas, FROM-first, STRUCT unpacking, SUMMARIZE), and aggregation shortcuts such as GROUP BY ALL, FILTER, arg_max, PIVOT/UNPIVOT and approximate aggregates. Window functions, QUALIFY, ASOF joins for aligning mismatched time series, and list aggregation round out the examples.
- Why SQL template tags are not vulnerable to SQL injection attacks
Neon mediumAdept
SQL template tags like Neon's `sql` function look like string interpolation but are safe from SQL injection because they are JavaScript tagged template functions. The tag receives the literal string fragments and the interpolated values separately, rebuilds the query with `$1`, `$2` placeholders, and passes the values as a parameter array to a parameterized query. The same pattern appears in Kysely and Postgres.js. A plain template literal passed to `client.query` remains vulnerable.