Basic Expressions and Operators¶
These building blocks are split into arithmetic and boolean expressions and operators.
Arithmetic Expressions and Operators¶
A SQL developer can use arithmetic operators to construct arithmetic expressions.
For instance, 10 + 5
is an expression that has two operands (10
and 5
) with the addition operator (+
) in between them, which is referred to as infix position.
Another possible position is postfix, which applies, for instance, to the factorial operation, like 10!
.
Finally, the prefix position is used by, for instance, the bitwise NOT operator, such as ~1
.
The following table shows the basic operators that Okera supports.
Operator | Position | Description |
---|---|---|
* |
Infix | Multiply operator |
/ |
Infix | Division operator |
% |
Infix | Module operator |
DIV |
Infix | Integer division operator |
+ |
Infix | Addition operator |
- |
Infix | Subtraction operator |
! |
Postfix | Factorial operator |
& |
Infix | Bitwise AND operator |
| |
Infix | Bitwise OR operator |
^ |
Infix | Bitwise XOR operator |
~ |
Prefix | Bitwise NOT operator |
Example: Simple arithmetic expressions
> select 10 * 10;
100
> select 10!;
3628800
> SELECT 5 & ~1;
4
SQL is quite limited in its available operators, but is commonly extended to more complex ones using functions.
Boolean Expressions and Operators¶
In Boolean algebra, instead of using numbers, the allowed values are only true
and false
.
The Okera-supported Boolean operators are shown in the following table, using the same position notation as explained in the previous section.
Operator | Position | Description |
---|---|---|
AND |
Infix | Boolean AND operator |
OR |
Infix | Boolean OR operator |
NOT |
Prefix | Boolean NOT operator |
Example: Boolean expressions
> SELECT true AND true;
true
> SELECT true AND false;
false
> SELECT (10 < 100) AND ("foo" = "foo");
true