docs/en/sql-reference/sql-functions/bit-functions/bit_shift_right.md
Shifts the binary representation of a numeric expression to the right by a specified number of bits.
This function performs a logical right shift, during which the bit length does not change, the low bit is dropped, and 0 is appended to the high bit despite whether the original bit is positive or negative. Logical shifts are unsigned shifts. For example, shifting 10101 by one bit results in 00101.
bit_shift_right() and bit_shift_right_logical() return the same result for a positive value.
bit_shift_right_logical(value, shift)
value: the value or numeric expression to shift. Supported data types are TINYINT, SMALLINT, INT, BIGINT, and LARGEINT.
shift: the number of bits to shift. The supported data type is BIGINT.
Returns a value of the same type as value.
shift is less than 0, 0 is returned.value by 0 always results in the original value.0 by a shift always results in 0.value is numeric but not an integer, that value will be cast to an integer. See Examples.value is a string, the value will be cast to an integer if possible. For example, the string "2.3" will be cast to 2. If the value cannot be cast to an integer, the value will be treated as NULL. See Examples.Use this function to shift numeric values.
SELECT bit_shift_right_logical(2, 1);
+-------------------------------+
| bit_shift_right_logical(2, 1) |
+-------------------------------+
| 1 |
+-------------------------------+
SELECT bit_shift_right_logical(2.2, 1);
+---------------------------------+
| bit_shift_right_logical(2.2, 1) |
+---------------------------------+
| 1 |
+---------------------------------+
SELECT bit_shift_right_logical("2", 1);
+---------------------------------+
| bit_shift_right_logical('2', 1) |
+---------------------------------+
| 1 |
+---------------------------------+
SELECT bit_shift_right_logical(cast('-2' AS INTEGER(32)), 1);
+-----------------------------------------------+
| bit_shift_right_logical(CAST('-2' AS INT), 1) |
+-----------------------------------------------+
| 2147483647 |
+-----------------------------------------------+