5.1 Functions and Operators

EventQL provides a large number of functions and operators for the built-in data types. Users can also define their own functions and operators.

Control Flow Functions
if an if statement with lazy evalutation if(1 == 2, "foo", "bar")
String Functions
REGEXP REGEXP operator 'foobar' REGEXP '^foo'
endswith check string end endswith("eventql", "ql")
startswith check string start startswith("eventql", "event")
uppercase convert to uppercase uppercase("hello world")
ucase alias for uppercase ucase("hello world")
lowercase convert to lowercase lowercase("hello world")
lcase alias for lowercase lcase("hello world")
substring Extract substring as specified. substring("foobar", 2, 3)
substr alias for substring substr("foobar", 3)
concat Add two strings. concat("event", "ql")
Numeric Functions
+ Sum of two values 2 + 2
* Multiply two numbers 4 * 2
/ Division operator 4 / 2
pow Power operator pow(2, 32)
round Round a number round(0.234, 2)
truncate Truncate a number truncate(0.234, 2)
Boolean Functions
! Logical Negation operator !true
== 'Equal' operator 2 == 2
!= 'Not equal' operator 2 != 3
< 'Less than' operator 2 < 4
<= 'Less or equal than' operator 2 <= 4
> 'Greather than' operator 4 > 2
>= 'Greather or equal than' operator 4 >= 2
AND Logical and 1 < 2 AND 2 < 3
OR Logical or 1 < 2 OR 2 < 3
isnull Check if value is null isnull(null)
DateTime Functions
from_timestamp Convert a timestamp to a DateTime value from_timestamp(1462125626)
date_trunc Truncate to specified precision date_trunc("d", 1462125626)
date_add Add interval date_add(1462125626, '1', 'DAY')
time_at Get DateTime value for interval from now time_at('-12hours')
Aggregate Functions
sum Sum of all values in the result set sum(price)
count Number of values in the result set count(1)
min Minimum of values in the result set min(price)
max Maximum of values in the result set max(price)
mean mean of values in the result set mean(price)
Conversion Functions
to_str Convert to string to_str(1)
to_int Convert to integer to_int(142.23)
to_float Convert to float to_float(12)
to_bool Convert to string to_bool(1)
Miscellaneous Functions
fnv32 Calculate a FNV32 hash. fnv32("test")
usleep Sleep for a number of microseconds usleep(1000)

Operator Precedence

Operator precedences are shown in the following list, from highest precedence to the lowest. Operators that are shown together on a line have the same precedence.

- (unary minus), ~ (unary bit inversion)
*, /, DIV, %, MOD
-, +
<<, >>
= (comparison), <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN
&&, AND
||, OR