diff --git a/docs/wiki/documentation/Numeric Data Type & Arithmetic Operations.md b/docs/wiki/documentation/Numeric Data Type & Arithmetic Operations.md index 25318fd59e..eecacb1c41 100644 --- a/docs/wiki/documentation/Numeric Data Type & Arithmetic Operations.md +++ b/docs/wiki/documentation/Numeric Data Type & Arithmetic Operations.md @@ -206,4 +206,29 @@ Example CAST(5 as decimal(3,2)) % CAST(2 as DECIMAL(3,2)) -- 1 -- IN HONOR PARAMETER MODE CAST(5 as decimal(3,2)) % CAST(2 as DECIMAL(3,2)) -- 1.00 +``` + +### Bitwise And +Performs a bitwise logical AND operation between two integer values. + +Syntax +: `expression & expression` + +Example: +```sql + 2 & 6 -- 0010 & 0110 = 0010 = 2 +``` + +Return Type: +: If one operand is of `INT` type, returns `INT` type. +: Else if one operand is of INT8 type, returns `INT8` type. +: Else if one operand is of INT4 type, returns `INT4` type. +: Else return `INT2` type. + +Note: +: Type precedence of the bitwise operator is lower than the plus/minus operator and higher than the predicates. + +```sql + 2 & 6 + 1 -- 2 & (6 + 1) = 2 & 7 = 2 + (2 & 6) + 1 -- 2 + 1 = 3 ``` \ No newline at end of file diff --git a/partiql-parser/src/main/antlr/PartiQL.g4 b/partiql-parser/src/main/antlr/PartiQL.g4 index dc4b6c61fd..0e266cb2f8 100644 --- a/partiql-parser/src/main/antlr/PartiQL.g4 +++ b/partiql-parser/src/main/antlr/PartiQL.g4 @@ -491,7 +491,7 @@ joinType * 2. Unary plus, minus (ex: -a, +a) * 3. Multiplication, Division, Modulo (ex: a * b) * 4. Addition, Subtraction (ex: a + b) - * 5. Other operators (ex: a || b) + * 5. Other operators (ex: a || b, a & b) * 6. Predicates (ex: a LIKE b, a < b, a IN b, a = b) * 7. IS true/false. Not yet implemented in PartiQL, but defined in SQL-92. (ex: a IS TRUE) * 8. NOT (ex: NOT a)