ChronusQLFundamentals

Scripts, streams, and CTEs

Compose named inputs, reusable intermediate streams, and multiple outputs in one temporal program.

Fundamentals

8 min read

Language reference

Named streams are the contract

FROM names an input or an earlier CTE. INTO names an output. These identifiers bind the language to connections supplied by the host; they are not file paths embedded in SQL.

Input recordsJSON
{"ts":"2026-08-23T10:00:00Z","device":{"id":"A-17"},"reading":42.5}
{"ts":"2026-08-23T10:00:01Z","device":{"id":"A-17"},"reading":43.1}
Nested field projectionChronusQL
SELECT ts,
       device.id AS device_id,
       reading
INTO output
FROM input TIMESTAMP BY ts

Reuse work with WITH

A CTE is a named stream transformation. Later CTEs and output statements can consume it without repeating the definition.

Execution sketchOne input, shared logic, several outputs
FROMInput
WHEREClean CTE
reuseFast CTE
fan-outoutput_all
fan-outoutput_fast
CTEs form an acyclic flow. Final SELECT statements materialize only the outputs each consumer needs.
Filter once and fan outChronusQL
WITH Clean AS (
  SELECT ts, driver, speed
  FROM telemetry
  WHERE speed > 0
), Fast AS (
  SELECT ts, driver, speed
  FROM Clean TIMESTAMP BY ts
  WHERE speed > 300
)
SELECT * INTO output_all FROM Clean;
SELECT * INTO output_fast FROM Fast;

Script rules

  • Declare WITH definitions before final output statements.
  • Separate final output statements with semicolons.
  • A CTE can read a physical input or a previously declared CTE.
  • A script may write to multiple named outputs.
  • Field names projected by a CTE become the schema visible to downstream statements.