Skip to content

SAMPLE BY

Downsampling with explicit fill semantics — the query-time twin of the storage fill policies.

SELECT ts, <agg>(<channel>), ... FROM <table>
  WHERE entity = '...' AND ts BETWEEN <a> AND <b>
  SAMPLE BY <duration> [FILL(PREV|NULL|LINEAR)];

Rules:

  • requires a single entity and a bounded ts range
  • every selected channel column must be aggregated (bare ts and entity are fine)
  • aggregates and SAMPLE BY come together or not at all

Aggregates

Function Input Result
count(c) any int
avg(c), sum(c), min(c), max(c) f64 f64
first(c), last(c) any channel type

FILL modes

Buckets with no samples are, by mode:

  • (no FILL) — absent from the result
  • FILL(NULL) — present, aggregate cells null
  • FILL(PREV) — carry the previous bucket's value (hold, at bucket granularity)
  • FILL(LINEAR) — linear interpolation between the nearest non-empty neighbors (numeric only; edges stay null)
SELECT ts, avg(speed) FROM telemetry
  WHERE entity = 'veh-1' AND ts BETWEEN 1700000000000 AND 1700086400000
  SAMPLE BY 5 m FILL(LINEAR);

Row ts is the bucket start (buckets align to floor(from / interval)).