The q* stdlib docs
qarray: list operations
qarray is the stdlib function package that exposes the array.* built-ins: small, pure list operations you can call straight from QQL. Every function takes the list as its first positional argument and returns a single value under the result key, following the shared DMS value convention. The package depends only on the executor (qexec) and the value model (qvalue) — no database, no third-party crates.
What it gives you#
qarray registers five public built-ins on a qexec runtime. Each speaks the shared call convention: the input is a Record of positional arguments (the list lives at key "0"), and the output is a Record with a single "result" key. Because they follow that convention, you can invoke them inline from a QQL SELECT projection as array.fn(...).
| Function | Argument | Returns | Behavior |
|---|---|---|---|
| array.len | List | Int | Number of elements in the list. |
| array.first | List | Value | First element, or Null if the list is empty. |
| array.last | List | Value | Last element, or Null if the list is empty. |
| array.reverse | List | List | A new list with the elements in reverse order. |
| array.sum | List | Int or Float | Numeric sum of the elements (see coercion below). |
How summation coerces values#
array.sum walks the list and adds each element as an f64. Int, Float, Decimal, and BigInt are read as numbers (Decimal and BigInt are parsed from their string form, falling back to 0.0 if that parse fails); any other element type contributes 0.0. The result is returned as an Int when the total has no fractional part, otherwise as a Float.
- Int element
- Added as its exact integer value cast to f64.
- Float element
- Added as-is.
- Decimal / BigInt element
- Stringified then parsed to f64 (0.0 on parse failure).
- Any other type (Str, Bool, Null, Map, List, ...)
- Contributes 0.0 to the sum.
Resource budget#
Each call decodes the argument list and (for reverse) re-emits a list of the same length, so cost scales with the input. Every array.* function declares a fixed per-call memory budget of 4096 bytes (4 KB) and zero storage, which lets the executor bound how many array.* calls run concurrently under a memory cap.
Example#
The example below shows the wire convention directly: a call to array.sum with the list [1, 2, 3] at positional key "0". Because 6 has no fraction, the result comes back as an Int. The same input through array.len returns Int 3, array.first returns Int 1, array.last returns Int 3, and array.reverse returns [3, 2, 1].
Request
array.sum([1, 2, 3])
# wire form (positional args record):
{ "0": { "List": [ {"Int": 1}, {"Int": 2}, {"Int": 3} ] } }Response
{ "result": { "Int": 6 } }Output
6Request
SELECT array.reverse([1, 2, 3]) FROM tResponse
{ "result": { "List": [ {"Int": 3}, {"Int": 2}, {"Int": 1} ] } }Output
[3, 2, 1]