From cb37b2a14fd1b252224dac0357451639799543f6 Mon Sep 17 00:00:00 2001 From: jazzthief Date: Thu, 19 Jan 2023 15:41:33 +0100 Subject: [PATCH] Add docs for bitwise operators --- doc/build/core/operators.rst | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/doc/build/core/operators.rst b/doc/build/core/operators.rst index 9bf47ec669..7813188342 100644 --- a/doc/build/core/operators.rst +++ b/doc/build/core/operators.rst @@ -590,6 +590,60 @@ Arithmetic Operators .. +Bitwise Operators +^^^^^^^^^^^^^^^^^ + +Bitwise operator functions provide uniform access to bitwise operators across different backends. + +* :meth:`_sql.ColumnOperators.bitwise_not`:: + + >>> from sqlalchemy import bitwise_not + >>> print(bitwise_not(column("x"))) + ~x + + .. + +* :meth:`_sql.ColumnOperators.bitwise_and`:: + + >>> from sqlalchemy import bitwise_and + >>> print(column("x").bitwise_and(5)) + x & :x_1 + + .. + +* :meth:`_sql.ColumnOperators.bitwise_or`:: + + >>> from sqlalchemy import bitwise_or + >>> print(column("x").bitwise_or(5)) + x | :x_1 + + .. + +* :meth:`_sql.ColumnOperators.bitwise_xor`:: + + >>> from sqlalchemy import bitwise_xor + >>> print(column("x").bitwise_xor(5)) + x ^ :x_1 + + Note that for PostgreSQL, which uses "#" to represent bitwise XOR, this function will produce an appropriate result:: + + >>> from sqlalchemy import bitwise_xor + >>> print(column("x").bitwise_xor(5)) + x # :x_1 + + .. + +* :meth:`_sql.ColumnOperators.bitwise_rshift`, :meth:`_sql.ColumnOperators.bitwise_lshift`:: + + >>> from sqlalchemy import bitwise_rshift, bitwise_lshift + >>> print(column("x").bitwise_rshift(5)) + x >> :x_1 + >>> print(column("x").bitwise_lshift(5)) + x << :x_1 + + .. + + Using Conjunctions and Negations ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- 2.47.3