else:
return ""
+ def visit_try_cast(self, element, **kw):
+ return "TRY_CAST (%s AS %s)" % (
+ self.process(element.clause, **kw),
+ self.process(element.typeclause, **kw),
+ )
+
def translate_select_structure(self, select_stmt, **kwargs):
"""Look for ``LIMIT`` and OFFSET in a select statement, and if
so tries to wrap it in a subquery with ``row_number()`` criterion.
from sqlalchemy import Table
from sqlalchemy import testing
from sqlalchemy import text
+from sqlalchemy import try_cast
from sqlalchemy import union
from sqlalchemy import UniqueConstraint
from sqlalchemy import update
"CREATE INDEX foo ON test (x) INCLUDE (y) WHERE y > 1",
)
+ def test_try_cast(self):
+ 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 id FROM t1",
+ )
+
@testing.combinations(
("no_persisted", "", "ignore"),
("persisted_none", "", None),