]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add docs for bitwise operators
authorjazzthief <mynameisyegor@gmail.com>
Thu, 19 Jan 2023 14:41:33 +0000 (15:41 +0100)
committerjazzthief <mynameisyegor@gmail.com>
Thu, 19 Jan 2023 14:41:33 +0000 (15:41 +0100)
doc/build/core/operators.rst

index 9bf47ec6693f3b54ffc0c2da8d3a03efda94a58e..7813188342998ce048a35f6c6b42f2dcde66c33e 100644 (file)
@@ -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
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^