self.process(element.stop, **kw),
)
+ def visit_bitwise_xor_op_binary(self, binary, operator, **kw):
+ return self._generate_generic_binary(binary, " # ", **kw)
+
def visit_json_getitem_op_binary(
self, binary, operator, _cast_applied=False, **kw
):
operators.asc_op: " ASC",
operators.nulls_first_op: " NULLS FIRST",
operators.nulls_last_op: " NULLS LAST",
+ # bitwise
+ operators.bitwise_xor_op: " ^ ",
}
FUNCTIONS: Dict[Type[Function[Any]], str] = {
"sub": (_binary_operate, util.EMPTY_DICT),
"div": (_binary_operate, util.EMPTY_DICT),
"mod": (_binary_operate, util.EMPTY_DICT),
+ "bitwise_xor_op": (_binary_operate, util.EMPTY_DICT),
"truediv": (_binary_operate, util.EMPTY_DICT),
"floordiv": (_binary_operate, util.EMPTY_DICT),
"custom_op": (_custom_op_operate, util.EMPTY_DICT),
"""
return self.operate(ilike_op, other, escape=escape)
+ def bitwise_xor(self, other):
+ """Return bitwise XOR operation"""
+
+ return self.operate(bitwise_xor_op, other)
+
def in_(self, other: Any) -> ColumnOperators:
"""Implement the ``in`` operator.
raise NotImplementedError()
+@_operator_fn
+def bitwise_xor_op(a: Any, b: Any) -> Any:
+ return a.bitwise_xor(b)
+
+
def is_comparison(op: OperatorType) -> bool:
return op in _comparison or isinstance(op, custom_op) and op.is_comparison
is_false: 5,
and_: 3,
or_: 2,
+ bitwise_xor_op: 1, # just guessing
comma_op: -1,
desc_op: 3,
asc_op: 3,
"WHERE usages.date <@ %(date_1)s::DATERANGE",
)
+ def test_dedicated_bit_xor(self):
+ c1 = column("c1", Integer)
+ c2 = column("c2", Integer)
+ self.assert_compile(
+ select(c1.bitwise_xor(c2)),
+ "SELECT c1 # c2 AS anon_1",
+ )
+
class InsertOnConflictTest(fixtures.TablesTest, AssertsCompiledSQL):
__dialect__ = postgresql.dialect()
r"use the .scalar_values\(\) method.",
):
fn(values(t.c.data).data([(1,), (42,)]))
+
+
+class BitOpTest(fixtures.TestBase, testing.AssertsCompiledSQL):
+ def test_generic_bit_xor(self):
+ c1 = column("c1", Integer)
+ c2 = column("c2", Integer)
+ self.assert_compile(
+ select(c1.op("^")(c2)),
+ "SELECT c1 ^ c2 AS anon_1",
+ )
+
+ def test_dedicated_bit_xor(self):
+ c1 = column("c1", Integer)
+ c2 = column("c2", Integer)
+ self.assert_compile(
+ select(c1.bitwise_xor(c2)),
+ "SELECT c1 ^ c2 AS anon_1",
+ )