]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Move try_cast() from mssql to base
authorNick Crews <nicholas.b.crews@gmail.com>
Thu, 18 May 2023 12:01:18 +0000 (08:01 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 18 May 2023 16:26:57 +0000 (12:26 -0400)
commitbe614e7a4e87054ff8d696ee7a3c496458f20b32
tree5a62d9ba2aa577321cc162ef619b01d3a9ec54df
parent0fe5ef94e381f045ab4e93684a64e8aa2d1f4f3b
Move try_cast() from mssql to base

Generalized the MSSQL :func:`_sql.try_cast` function into the
``sqlalchemy.`` import namespace so that it may be implemented by third
party dialects as well. Within SQLAlchemy, the :func:`_sql.try_cast`
function remains a SQL Server-only construct that will raise
:class:`.CompileError` if used with backends that don't support it.

:func:`_sql.try_cast` implements a CAST where un-castable conversions are
returned as NULL, instead of raising an error. Theoretically, the construct
could be implemented by third party dialects for Google BigQuery, DuckDB,
and Snowflake, and possibly others.

Pull request courtesy Nick Crews.

Fixes: #9752
Closes: #9753
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/9753
Pull-request-sha: 2e81b8d2c9314ca2cc5807fc807c35fefbe6ad2c

Change-Id: Ib57999b5947a2e34d5d305e294ff99dc08b01111
12 files changed:
doc/build/changelog/unreleased_20/9752.rst [new file with mode: 0644]
doc/build/core/sqlelement.rst
lib/sqlalchemy/__init__.py
lib/sqlalchemy/dialects/mssql/__init__.py
lib/sqlalchemy/dialects/mssql/base.py
lib/sqlalchemy/sql/__init__.py
lib/sqlalchemy/sql/_elements_constructors.py
lib/sqlalchemy/sql/compiler.py
lib/sqlalchemy/sql/elements.py
lib/sqlalchemy/sql/expression.py
test/dialect/mssql/test_compiler.py
test/sql/test_compiler.py