diff options
author | Leonel Atencio <leo.atencio@gmail.com> | 2019-08-09 17:16:13 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-08-12 21:22:04 -0400 |
commit | 7e0dfd2ad4141289a992adc65d2a6641f46dc82d (patch) | |
tree | 8d1be9d1047bff9a1fc946d5efbfc8a8bbfce59e /test/dialect/mssql/test_compiler.py | |
parent | 8f43a770199845abe47c0b8479e846cffbace51a (diff) | |
download | sqlalchemy-7e0dfd2ad4141289a992adc65d2a6641f46dc82d.tar.gz |
Add support for try_cast function on sqlalchemy.dialects.mssql
Added new :func:`.mssql.try_cast` construct for SQL Server which emits
"TRY_CAST" syntax. Pull request courtesy Leonel Atencio.
Fixes: #4782
Closes: #4785
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4785
Pull-request-sha: cf13303a9d1c0cc0233a82a5d2ca01f438b6fb9b
Change-Id: I74a71ff5e587353f67472534aabe0d54ae8039ae
Diffstat (limited to 'test/dialect/mssql/test_compiler.py')
-rw-r--r-- | test/dialect/mssql/test_compiler.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test/dialect/mssql/test_compiler.py b/test/dialect/mssql/test_compiler.py index 498de763c..642cee4cd 100644 --- a/test/dialect/mssql/test_compiler.py +++ b/test/dialect/mssql/test_compiler.py @@ -22,6 +22,7 @@ from sqlalchemy import update from sqlalchemy.dialects import mssql from sqlalchemy.dialects.mssql import base from sqlalchemy.dialects.mssql import mxodbc +from sqlalchemy.dialects.mssql.base import try_cast from sqlalchemy.sql import column from sqlalchemy.sql import quoted_name from sqlalchemy.sql import table @@ -1196,6 +1197,15 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): schema.CreateIndex(idx), "CREATE INDEX foo ON test (x) INCLUDE (y)" ) + def test_try_cast(self): + metadata = MetaData() + t1 = Table("t1", metadata, Column("id", Integer, primary_key=True)) + + self.assert_compile( + select([try_cast(t1.c.id, Integer)]), + "SELECT TRY_CAST (t1.id AS INTEGER) AS anon_1 FROM t1", + ) + class SchemaTest(fixtures.TestBase): def setup(self): |