Simple Query
A simple query retrieves raw time-series rows from CrateDB. You choose which columns to return and can apply filters, sorting, and time range restrictions. This is the most fundamental stream data query type — use it when you need individual data points rather than aggregated summaries.
Transient Simple Query
A transient query lets you specify query parameters directly in the request without saving a query definition first. Use the transientStreamDataQuery field under streamData.
Basic Usage
query {
streamData {
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage", "power"]
) {
totalCount
pageInfo {
hasNextPage
endCursor
}
items {
rtId
ckTypeId
timestamp
rtWellKnownName
cells {
items {
attributePath
value
}
}
}
}
}
}
Response:
{
"data": {
"streamData": {
"transientStreamDataQuery": {
"totalCount": 4826,
"pageInfo": {
"hasNextPage": true,
"endCursor": "YXJyYXljb25uZWN0aW9uOjI0"
},
"items": [
{
"rtId": "65dc6d24cc529cdc46c84fcc",
"ckTypeId": "Industry.Energy/EnergyMeter",
"timestamp": "2024-03-21T16:22:47.676Z",
"rtWellKnownName": "EnergyMeter-001",
"cells": {
"items": [
{ "attributePath": "voltage", "value": 230.5 },
{ "attributePath": "power", "value": 1450.2 }
]
}
},
{
"rtId": "65dc6d24cc529cdc46c84fcc",
"ckTypeId": "Industry.Energy/EnergyMeter",
"timestamp": "2024-03-21T16:23:50.675Z",
"rtWellKnownName": "EnergyMeter-001",
"cells": {
"items": [
{ "attributePath": "voltage", "value": 231.1 },
{ "attributePath": "power", "value": 1465.8 }
]
}
}
]
}
}
}
}
Each result row contains the system fields (rtId, ckTypeId, timestamp, rtWellKnownName) and a cells connection with the requested column values.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| ckId | String! | Yes | The CK type to query (e.g., "Industry.Energy/EnergyMeter") |
| columnPaths | [String!]! | Yes | Data stream attribute names to return (e.g., ["voltage", "power"]) |
| arg | StreamDataArguments | No | Time range and limit overrides |
| fieldFilter | [FieldFilter] | No | Field-level comparison filters |
| sortOrder | [Sort] | No | Sort specification |
| rtIds | [OctoObjectId] | No | Scope results to specific runtime entity IDs |
| first | Int | No | Maximum number of items to return (pagination) |
| after | String | No | Cursor for pagination (from pageInfo.endCursor) |
Column Paths
The columnPaths parameter specifies which data stream attributes to include in the result. Use the attribute names as defined in the CK type.
# Single column
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage"]
)
# Multiple columns
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage", "power", "current", "frequency"]
)
The system fields rtId, ckTypeId, timestamp, and rtWellKnownName are always included regardless of the column paths specified.
Anchor Columns
Every row of an archive points at the runtime entity it was measured for, its anchor (the rtId of the row). A column that starts with the reserved prefix anchor. shows an attribute of that anchor entity next to the measured values. This is how a row of a raw, time-range or rollup archive carries readable register data, for example the OBIS code and the unit of an energy measurement, without any change to the archive or the rollup.
transientStreamDataQuery {
simple(
archiveRtId: "65f1c0a2b3d4e5f6a7b8c9d0"
columnPaths: ["window_start", "amountvalue_sum", "anchor.obisCode", "anchor.amount.unit"]
) { ... }
}
- Syntax:
anchor.<attributePath>. The path after the prefix is an attribute path of the CK type the archive targets (record sub-attributes such asamount.unitwork; a whole record such asanchor.amountis not a column and is refused). An enum attribute is returned as the name of its value, for exampleKWh. It works in thecolumnPathsof a transient query and in thecolumnsof a persistedSimpleSdQuery, on raw, time-range and rollup archives. - Result: the cell of the column has the requested column as
attributePath, in the position where you listed it. Enum values are returned as names (kWh), or as the integer key withresolveEnumValuesToNames: falseoncells, like every other enum column. - Validation: a path that is not an attribute of the archive's CK type is refused with an error that names the column and the CK type; the query does not return an empty column. An attribute that is
Hiddenor a secret, or a record that contains one, is refused as well; no protected value is returned. - Display only: an anchor column cannot be used in a field filter, a sort order, an aggregation, a grouping or a downsampling query (including a simple query run in downsampling mode). Such a query is refused with a validation error that names the column and this limit.
- Permissions: the anchors of one page of rows are read with the data permissions of the caller. If the caller may not read an anchor entity, or the anchor does not exist (any more), the anchor cells of that row are
null; nothing else about the anchor is returned. The measured values of the row follow the existing stream-data rules. - Current value: the cell shows the current value of the anchor attribute, not the value at the time of the measurement. That fits attributes that identify a register, such as the OBIS code and the unit; do not use it for values that change over time.
- Cost: the anchors of a page are loaded with one query, not one per row.
Filtering
Use fieldFilter to restrict results based on attribute values. Each filter specifies an attribute path, an operator, and a comparison value.
Filter by Attribute Value
query {
streamData {
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage", "power"]
fieldFilter: [
{
attributePath: "voltage"
operator: GREATER_THAN
comparisonValue: 220
}
]
) {
totalCount
items {
timestamp
cells {
items {
attributePath
value
}
}
}
}
}
}
Multiple Filters
Multiple filters are combined with AND logic:
fieldFilter: [
{
attributePath: "voltage"
operator: GREATER_EQUAL_THAN
comparisonValue: 220
},
{
attributePath: "voltage"
operator: LESS_EQUAL_THAN
comparisonValue: 240
}
]
Available Filter Operators
| Operator | Description |
|---|---|
EQUALS | Exact match |
NOT_EQUALS | Not equal |
GREATER_THAN | Greater than |
GREATER_EQUAL_THAN | Greater than or equal |
LESS_THAN | Less than |
LESS_EQUAL_THAN | Less than or equal |
LIKE | Pattern match (use % as wildcard) |
MATCH_REG_EX | Regular expression match |
IN | Value in list |
NOT_IN | Value not in list |
ANY_EQ | Any element equals (for array fields) |
ANY_LIKE | Any element matches pattern (for array fields) |
Time Range Filtering
Use StreamDataArguments to restrict results to a specific time window:
query {
streamData {
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage"]
arg: {
queryMode: DEFAULT
from: "2024-03-21T00:00:00Z"
to: "2024-03-22T00:00:00Z"
limit: 1000
}
) {
totalCount
items {
timestamp
cells {
items {
attributePath
value
}
}
}
}
}
}
| Field | Description |
|---|---|
| from | Start of the time range (inclusive) |
| to | End of the time range (inclusive) |
| limit | Maximum number of data points to return from CrateDB |
| queryMode | DEFAULT returns raw rows. DOWNSAMPLING reduces the result to limit time buckets — see Downsampling a Simple Query below. |
The limit in StreamDataArguments controls how many rows CrateDB returns before pagination is applied. The first parameter on the query field controls how many items are returned per page.
Downsampling a Simple Query
Setting queryMode: DOWNSAMPLING (together with from, to, and limit) turns a simple query into a server-side downsample: instead of returning every raw row, the result is reduced to exactly limit equal-width time buckets — ideal for charts that only have room for a few hundred points.
Unlike the dedicated Downsampling Query — where you pick an aggregation per column — a simple query in downsampling mode lets the server choose a sensible default reducer for each requested column, based on its value type:
| Column value type | Reducer(s) applied |
|---|---|
| Numeric (integer, double) | AVG + MIN + MAX — the min/max pair forms an envelope that preserves peaks the average would smooth away |
| String / enum / boolean / timestamp | MAX — a stable representative value per bucket |
| Records, arrays, binaries | skipped (not reducible to a chartable value) |
Results are additionally grouped by the source runtime entity (rtId), so interleaved series stay separate — you get limit buckets per series rather than one merged series.
query {
streamData {
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage", "power"]
arg: {
queryMode: DOWNSAMPLING
from: "2024-03-21T00:00:00Z"
to: "2024-03-22T00:00:00Z"
limit: 300
}
) {
totalCount
items {
rtId
timestamp
cells {
items {
attributePath
value
}
}
}
}
}
}
Each result row is one bucket per series. The reduced cells carry a function suffix: the numeric envelope comes back as voltage_avg, voltage_min, and voltage_max; non-numeric columns as <column>_max. The bucket start time is on the row's timestamp. Empty buckets (no data in that interval) are returned with null cell values so clients can render gaps rather than interpolate.
from, to, and limit are all required for downsampling — without all three the query falls back to returning raw rows. Use the Downsampling Query instead when you need explicit control over which aggregation is applied to which column.
Sorting
Use sortOrder to control the order of results:
query {
streamData {
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage"]
sortOrder: [
{ attributePath: "timestamp", sortOrder: DESCENDING }
]
) {
items {
timestamp
cells {
items {
attributePath
value
}
}
}
}
}
}
This returns the most recent data points first. You can sort by any column in the result set. Without sortOrder the rows come in the default order (time axis, then rtId, then ckTypeId); see Row order and paging guarantee.
Scoping to Specific Entities
Use rtIds to limit results to data from specific runtime entities:
query {
streamData {
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage", "power"]
rtIds: [
"65dc6d24cc529cdc46c84fcc",
"65dc6d24cc529cdc46c84fcd"
]
) {
totalCount
items {
rtId
rtWellKnownName
timestamp
cells {
items {
attributePath
value
}
}
}
}
}
}
This returns stream data only for the two specified energy meters.
Pagination
All stream data queries use cursor-based pagination. Use first to set the page size and after to fetch subsequent pages.
First Page
query {
streamData {
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage"]
first: 50
) {
totalCount
pageInfo {
hasNextPage
endCursor
}
items {
timestamp
cells {
items {
attributePath
value
}
}
}
}
}
}
Next Page
Use the endCursor value from the previous response as the after parameter:
query {
streamData {
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage"]
first: 50
after: "YXJyYXljb25uZWN0aW9uOjQ5"
) {
totalCount
pageInfo {
hasNextPage
endCursor
}
items {
timestamp
cells {
items {
attributePath
value
}
}
}
}
}
}
Continue fetching pages until hasNextPage is false.
Row order and paging guarantee
While the data does not change, paging returns every row of the result exactly once: no row appears on two pages and none is skipped, also when several entities share the same timestamps. The platform gives every paged query a total row order:
| Query | Order |
|---|---|
Simple query without sortOrder | The time axis, then rtId, then ckTypeId. The time axis is timestamp on a raw archive and window_start, then window_end (returned as timestamp), on a time-range or rollup archive. |
Simple query with sortOrder | Your sort order first. The columns of the default order you did not name follow as tiebreakers, ascending, so rows that are equal in your sort columns still keep a fixed order. |
| Grouped aggregation | The groupByColumnPaths, ascending, in the order you listed them. |
| Downsampling | The time bin, then the series columns (groupByColumnPaths), ascending. |
| Aggregation | One row; no order needed. |
The same holds for the rows of a persisted stream data query. The order is stable as long as the data does not
change: rows written while you page can still move the rows behind them to the next page.
Each page is a separate query that sorts the result and skips the rows of the earlier pages. On a large archive
without a time range or entity filter, pages deep into the result are slow (seconds for an offset in the millions).
Narrow the query with a time range or rtIds instead of paging through a whole archive.
Combining Parameters
All parameters can be combined. This example queries the last 24 hours of voltage data for a specific energy meter, filtered to values above 220V, sorted by timestamp descending, with pagination:
query {
streamData {
transientStreamDataQuery(
ckId: "Industry.Energy/EnergyMeter"
columnPaths: ["voltage", "power"]
arg: {
queryMode: DEFAULT
from: "2024-03-20T16:00:00Z"
to: "2024-03-21T16:00:00Z"
limit: 5000
}
rtIds: ["65dc6d24cc529cdc46c84fcc"]
fieldFilter: [
{ attributePath: "voltage", operator: GREATER_THAN, comparisonValue: 220 }
]
sortOrder: [
{ attributePath: "timestamp", sortOrder: DESCENDING }
]
first: 100
) {
totalCount
pageInfo {
hasNextPage
endCursor
}
items {
rtId
rtWellKnownName
timestamp
cells {
items {
attributePath
value
}
}
}
}
}
}
Typed vs Transient
For a comparison of typed and transient query approaches, see the Stream Data Access overview. In summary:
| Typed | Transient | |
|---|---|---|
| Column selection | All attributes of the type | Explicit columnPaths parameter |
| Result format | Named fields (e.g., voltage) | cells with attributePath / value pairs |
| Type safety | GraphQL schema validation | Runtime validation |
| Use case | Known type, all attributes needed | Dynamic column selection, ad-hoc analysis |