Function reference#
SQL queries may only call functions on this allowlist. Anything else is rejected before execution with Function not allowed: <name>.
The live list is served by the REST API, so it is the authoritative answer if this page and your deployment disagree:
curl --request GET '{API_URL}/sql/v1/catalog' \
--header 'Authorization: Bearer <your-api-key>'
Where each function works#
Queries route to one of two backends depending on which tables they read: the telemetry tables (points_double, points_int, points_string, points_struct, logs, channels) or the metadata tables (assets, runs, run_assets, datasets, events, event_assets).
Most functions work on both. Some work only on the telemetry backend, and calling one against metadata tables fails with Function <NAME> is not supported for metadata-only queries. Those are marked Telemetry only below.
One function, CURRENT_TIME, is the reverse: it works only on the metadata backend, and calling it over telemetry tables fails with Function CURRENT_TIME is not supported for telemetry queries. It is marked Metadata only below.
The check applies per subtree, not per query, so in a query spanning both backends a telemetry-only function is fine over the telemetry side.
Aggregate functions#
Function |
Notes |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
Population standard deviation. |
|
Sample standard deviation. |
|
Synonym for |
|
Population variance. |
|
Sample variance. |
|
Root mean square. |
|
Continuous percentile. |
|
Telemetry only. Returns |
|
Telemetry only. Returns |
|
Concatenates |
|
Telemetry only. Collects |
MIN_BY and MAX_BY answer “what was the reading when something else was at its highest or lowest,” which plain MIN and MAX cannot express:
SELECT MAX_BY(value, ts) AS last_value
FROM points_double
WHERE dataset_rid = '<dataset-rid>'
PERCENTILE_CONT takes its column in a WITHIN GROUP clause rather than as an argument:
SELECT channel,
PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY value) AS median_value,
PERCENTILE_CONT(0.95) WITHIN GROUP (ORDER BY value) AS p95_value
FROM points_double
WHERE dataset_rid = '<dataset-rid>'
GROUP BY channel
Numeric functions#
Function |
Notes |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rounds to the nearest integer, or to |
|
|
|
Returns whether the value is NaN. |
|
Telemetry only. Parses a hexadecimal string and returns |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String functions#
Function |
Notes |
|---|---|
|
|
|
Synonym for |
|
Telemetry only. Returns the hexadecimal representation. Numeric arguments are cast to a 64-bit integer first, so a value that doesn’t fit returns |
|
|
|
|
|
Returns the keys of a map column as an array of strings. |
|
|
|
|
|
Telemetry only. Returns the first match of the regular expression |
|
Telemetry only. Returns whether the regular expression |
|
|
|
|
|
Date and time functions#
Function |
Notes |
|---|---|
|
|
|
Metadata only. Not available over telemetry tables. |
|
|
|
|
|
Telemetry only. Truncates |
|
Truncates |
|
Returns the whole number of |
DATE_BIN takes the interval first, which is easy to get backwards:
SELECT DATE_BIN(INTERVAL '1' MINUTE, ts, TIMESTAMP '1970-01-01 00:00:00') AS bucket,
AVG(value) AS mean_value
FROM points_double
WHERE dataset_rid = '<dataset-rid>'
GROUP BY bucket
ORDER BY bucket
Use TIMESTAMPDIFF for the time between two timestamps. Subtracting one timestamp from another is rejected.
Conditional functions#
Function |
Notes |
|---|---|
|
|
|
Returns the first non-null argument. |
|
Returns the largest argument, ignoring nulls. |
|
Returns the smallest argument, ignoring nulls. |
Window functions#
These are called with an OVER clause, and every one of them requires an ORDER BY inside it.
Function |
Notes |
|---|---|
|
Value from a preceding row in the window. |
|
Value from a following row in the window. |
|
Value from the first row in the window. |
|
Value from the last row in the window. |
|
Sequential number within the window. |
|
Telemetry only. Rate of change of the value per second. |
|
Telemetry only. Accumulated area under the value over time. |
DERIVATIVE and INTEGRAL compute over the ordered window rather than a single row. Their ORDER BY must be a single timestamp column:
SELECT ts,
DERIVATIVE(value) OVER (ORDER BY ts) AS rate
FROM points_double
WHERE dataset_rid = '<dataset-rid>'
ORDER BY ts
INTEGRAL defaults to trapezoidal integration. Pass a method keyword to select a different rule:
SELECT ts,
INTEGRAL(value) OVER (ORDER BY ts) AS area_trapezoid,
INTEGRAL(value, L_RIEMANN) OVER (ORDER BY ts) AS area_left,
INTEGRAL(value, R_RIEMANN) OVER (ORDER BY ts) AS area_right
FROM points_double
WHERE dataset_rid = '<dataset-rid>'
ORDER BY ts
Bitwise functions#
All bitwise functions are telemetry only, take integer-domain operands, and return BIGINT.
Function |
Notes |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
Tests the bit at |
These are two-operand scalar functions, not aggregates. That differs from the SQL standard, where BIT_AND and BIT_OR aggregate over a group. To combine bits across rows, aggregate the result yourself.
Operators#
Standard SQL operators and clauses are unaffected by the function allowlist: comparison and arithmetic operators, AND, OR, NOT, IN, BETWEEN, LIKE, IS NULL, CASE, and CAST are all available.
On the telemetry tables, ~ and !~ test a string against a regular expression. Write casts as CAST(expr AS type), since Postgres-style :: casts are rejected.
Next steps#
Writing queries: query patterns and examples.
SQL REST API: the endpoint contract and error codes.