Scalar functions take one or more columns as parameters from a single intermediary data row and return a single scalar value. Scalar functions must be declared after the `CTEs` and `FROM` clauses and before the `SELECT` clause. The user-assigned scalar name may be used in any predicate or `SELECT` clause.
Aggregate functions operate on a single column of intermediary data rows. They are always declared inline in a `SELECT` clause or `HAVING` predicate by the function name, no space, open and close parenthesis which contain parameters specific to the function including the intermediary data column.
## Boolean Functions
Boolean funtions can be Scalar or Aggregate and depending on their context must follow rules for either type.
If `<expression>` is of loobean type (%.y, %.n) normal boolean evaluation proceeds. Evaluation of any other type evaluates as boolean TRUE unless `EXISTS <expression>` evaluates as FALSE.
```
AND ::=
AND(<expression1>, ..., <expressionn>)
```
```
OR ::=
OR(<expression1>, ..., <expressionn>)
```
```
XOR ::=
XOR(<expression1>, <expression2>)
```
```
NOT ::=
NOT(<expression)
```
## Scalar Functions
`<expression>` many be another scalar function, but not aggregate functions.
### arithmetic operators
```
<addition> ::=
<expression> + <expression>
```
```
<subtraction> ::=
<expression> - <expression>
```
```
<multiplication> ::=
<expression> * <expression>
```
```
<division> ::=
<expression> / <expression>
```
```
<modulo> ::=
<expression> % <expression>
```
Returns the integer remainder of a division.
```
<negation> ::=
NOT <expression>
```
NOT (-4) → 4
```
<exponentiation> ::=
<expression> ^ <expression>
```
2 ^ 3 → 8
Unlike typical mathematical practice, multiple uses of ^ will associate left to right by default:
2 ^ 3 ^ 3 → 512
2 ^ (3 ^ 3) → 134217728
### bitwise operators
```
<bitwiseAND> ::=
<expression>&<expression>
```
91 & 15 → 11
```
<bitwiseOR> ::=
<expression> | <expression>
```
32 | 3 → 35
```
<bitwiseExclusiveOR> ::=
<expression> # <expression>
```
17 # 5 → 20
```
<bitwiseNOT> ::=
_ <expression>
```
_ 1 → -2
```
<bitwiseshiftleft> ::=
<expression><<@ud
```
1 <<4→16
>> (Shift right)
```
<bitwiseshiftright> ::=
<expression> >> @ud
```
8 >> 2 → 2
### predicate
```
<predicate> ::=
<predicate>
```
A scalar returning a predicate follows the same construction rules as a `WHERE` predicate.