also in 0.7.7.
- mssql
+ - [bug] removed legacy behavior whereby
+ a column comparison to a scalar SELECT via
+ == would coerce to an IN with the SQL server
+ dialect. This is implicit
+ behavior which fails in other scenarios
+ so is removed. Code which relies on this
+ needs to be modified to use column.in_(select)
+ explicitly. [ticket:2277]
+
- [feature] Added interim create_engine flag
supports_unicode_binds to PyODBC dialect,
to force whether or not the dialect
Background on SQL Server snapshot isolation is available at
http://msdn.microsoft.com/en-us/library/ms175095.aspx.
-Scalar Select Comparisons
--------------------------
-
-The MSSQL dialect contains a legacy behavior whereby comparing
-a scalar select to a value using the ``=`` or ``!=`` operator
-will resolve to IN or NOT IN, respectively. This behavior is
-deprecated and will be removed in 0.8 - the ``s.in_()``/``~s.in_()`` operators
-should be used when IN/NOT IN are desired.
-
-For the time being, the existing behavior prevents a comparison
-between scalar select and another value that actually wants to use ``=``.
-To remove this behavior in a forwards-compatible way, apply this
-compilation rule by placing the following code at the module import
-level::
-
- from sqlalchemy.ext.compiler import compiles
- from sqlalchemy.sql.expression import _BinaryExpression
- from sqlalchemy.sql.compiler import SQLCompiler
-
- @compiles(_BinaryExpression, 'mssql')
- def override_legacy_binary(element, compiler, **kw):
- return SQLCompiler.visit_binary(compiler, element, **kw)
-
Known Issues
------------
binary.left,
binary.operator),
**kwargs)
- else:
- if (
- (binary.operator is operator.eq or
- binary.operator is operator.ne)
- and (
- (isinstance(binary.left, expression._FromGrouping)
- and isinstance(binary.left.element,
- expression._ScalarSelect))
- or (isinstance(binary.right, expression._FromGrouping)
- and isinstance(binary.right.element,
- expression._ScalarSelect))
- or isinstance(binary.left, expression._ScalarSelect)
- or isinstance(binary.right, expression._ScalarSelect)
- )
- ):
- op = binary.operator == operator.eq and "IN" or "NOT IN"
- util.warn_deprecated("Comparing a scalar select using ``=``/``!=`` will "
- "no longer produce IN/NOT IN in 0.8. To remove this "
- "behavior immediately, use the recipe at "
- "http://www.sqlalchemy.org/docs/07/dialects/mssql.html#scalar-select-comparisons")
- return self.process(
- expression._BinaryExpression(binary.left,
- binary.right, op),
- **kwargs)
- return super(MSSQLCompiler, self).visit_binary(binary, **kwargs)
+ return super(MSSQLCompiler, self).visit_binary(binary, **kwargs)
def returning_clause(self, stmt, returning_cols):
]:
self.assert_compile(expr, compile, dialect=mxodbc_dialect)
- @testing.uses_deprecated
def test_in_with_subqueries(self):
- """Test that when using subqueries in a binary expression
- the == and != are changed to IN and NOT IN respectively.
+ """Test removal of legacy behavior that converted "x==subquery"
+ to use IN.
"""
self.assert_compile(t.select().where(t.c.somecolumn
== t.select()),
'SELECT sometable.somecolumn FROM '
- 'sometable WHERE sometable.somecolumn IN '
+ 'sometable WHERE sometable.somecolumn = '
'(SELECT sometable.somecolumn FROM '
'sometable)')
self.assert_compile(t.select().where(t.c.somecolumn
!= t.select()),
'SELECT sometable.somecolumn FROM '
- 'sometable WHERE sometable.somecolumn NOT '
- 'IN (SELECT sometable.somecolumn FROM '
+ 'sometable WHERE sometable.somecolumn != '
+ '(SELECT sometable.somecolumn FROM '
'sometable)')
def test_count(self):