--- /dev/null
+.. change::
+ :tags: bug, postgresql
+ :tickets: 5518
+
+ Adjusted the :meth:`_types.ARRAY.Comparator.any` and
+ :meth:`_types.ARRAY.Comparator.all` methods to implement a straight "NOT"
+ operation for negation, rather than negating the comparison operator.
\ No newline at end of file
"""
elements = util.preloaded.sql_elements
operator = operator if operator else operators.eq
- return operator(
+
+ # send plain BinaryExpression so that negate remains at None,
+ # leading to NOT expr for negation.
+ return elements.BinaryExpression(
coercions.expect(roles.ExpressionElementRole, other),
elements.CollectionAggregate._create_any(self.expr),
+ operator,
)
@util.preload_module("sqlalchemy.sql.elements")
"""
elements = util.preloaded.sql_elements
operator = operator if operator else operators.eq
- return operator(
+
+ # send plain BinaryExpression so that negate remains at None,
+ # leading to NOT expr for negation.
+ return elements.BinaryExpression(
coercions.expect(roles.ExpressionElementRole, other),
elements.CollectionAggregate._create_all(self.expr),
+ operator,
)
comparator_factory = Comparator
"%(param_1)s = ANY (x)",
checkparams={"param_1": 4},
)
+
+ self.assert_compile(
+ c.any(5), "%(param_1)s = ANY (x)", checkparams={"param_1": 5},
+ )
+
+ self.assert_compile(
+ ~c.any(5),
+ "NOT (%(param_1)s = ANY (x))",
+ checkparams={"param_1": 5},
+ )
+
+ self.assert_compile(
+ c.all(5), "%(param_1)s = ALL (x)", checkparams={"param_1": 5},
+ )
+
+ self.assert_compile(
+ ~c.all(5),
+ "NOT (%(param_1)s = ALL (x))",
+ checkparams={"param_1": 5},
+ )
+
self.assert_compile(
c.any(5, operator=operators.ne),
"%(param_1)s != ANY (x)",
checkparams={"param_1": 5},
)
+ def test_any_array_comparator_negate_accessor(self, t_fixture):
+ t = t_fixture
+
+ self.assert_compile(
+ ~t.c.arrval.any(5, operator.gt),
+ "NOT (:param_1 > ANY (tab1.arrval))",
+ checkparams={"param_1": 5},
+ )
+
def test_all_array_comparator_accessor(self, t_fixture):
t = t_fixture
checkparams={"param_1": 5},
)
+ def test_all_array_comparator_negate_accessor(self, t_fixture):
+ t = t_fixture
+
+ self.assert_compile(
+ ~t.c.arrval.all(5, operator.gt),
+ "NOT (:param_1 > ALL (tab1.arrval))",
+ checkparams={"param_1": 5},
+ )
+
def test_any_array_expression(self, t_fixture):
t = t_fixture