Q Language Manual
The Q language is a lightweight filtering language used to evaluate conditions on device objects. It is similar in spirit to SQL WHERE clauses.
1. Field References
- Field names are case-sensitive.
- Nested fields use
.(dot) notation.
Examples:
network.is_connected
tracking.closest_gateway.rssi
tracking.location_estimate.site
2. Comparison Operators
Fields may be compared using the following operators:
| Operator | Meaning |
|---|---|
= | Equal |
> | Greater than |
< | Less than |
>= | Greater than or equal |
<= | Less than or equal |
!= | Not equal |
Example:
tracking.closest_gateway.rssi >= -45
3. Boolean Evaluation
There are no true or false literals.
To evaluate a field's truthiness:
network.is_connected
To negate:
not network.is_connected
not evaluates to false or null.
4. Logical Operators
Logical operators are case-insensitive:
ANDOR
Precedence
AND has higher precedence than OR.
foo AND bar OR quux AND ruu
Is equivalent to:
(foo AND bar) OR (quux AND ruu)
5. Grouping
Parentheses may be used to control grouping:
(tracking.closest_gateway.rssi >= -45 AND network.is_connected)
OR tracking.location_estimate.site = "HQ"
6. Literals
6.1 Numbers
- Integers are written normally:
42
- Floats must contain a decimal point:
3.14
If a field is a float, the literal must include . to be treated as a float.
6.2 Strings
Strings are wrapped in double quotes:
tracking.location_estimate.site = "Warehouse A"
Quotes may be escaped:
"Device \"Alpha\""
6.3 Dates (UTC)
Date literals are written without quotes:
2025-05-01T00:00:00Z
- Always interpreted as UTC.
- Must use ISO-8601 format.
6.4 Durations
Durations are written without quotes:
5h
1h6m
10s
You may combine duration units:
h= hoursm= minutess= seconds
Timestamp Arithmetic
timestamp + duration→ timestamptimestamp - duration→ timestamptimestamp - timestamp→ durationtimestamp + timestamp→ invalid
Example:
update_time - @update_time > 300
7. Algebraic & Comparative Order of Operations
Arithmetic and comparison follow SQL-like precedence.
a = b + c
Is equivalent to:
a = (b + c)
8. The NOW Keyword
NOW KeywordNOW (case-insensitive) represents the current timestamp.
Example:
update_time < NOW - 5m
9. Summary of Precedence
From highest to lowest:
- Parentheses
(...) - Arithmetic operations
- Comparison operators (
=,>,<, etc.) ANDOR
Updated about 2 months ago
