SELECT
The SELECT clause is mandatory and tells RioDB what fields should be gathered when query conditions are met. It also tells RioDB that the intent of your statement is to create a query.
What can you select?
- Any field from the current message that is passing through the stream, like: my_stock_stream.SYMBOL
You can use just the field name if it’s not found on multiple sources, like: SYMBOL
You cannot access fields from past messages. But all fields from the current message are accessible. - Any aggregation value from any window in the query data sources (FROM), like: last_10_bids.SUM
You can just use the aggregation name if it’s not found on multiple sources, like: SUM
You cannot select an aggregation from a window that is not running that aggregation. - Expressions, for example: (SUM – MAX) / 2
- Scalar functions, like: CONCAT( EXCHANGE, ‘-‘, SYMBOL )
- Hardcoded values, like: ‘USA’
Syntax
Selected fields are separated by commas. Newlines are ignored, but useful for code readability:
SELECT
<field 1>,
<field 2,
<...>,
<field n>
Optionally, fields can be given a name:
SELECT
<field 1> as <name 1>,
<field 2 as <name 2>,
<...>,
<field n> as <name n>
FROM ...
Example
SELECT
SYMBOL,
BID,
(SUM - MAX) / 2,
CONCAT(EXCHANGE, '-', SYMBOL),
'USA'
FROM ...
Using field names:
SELECT
SYMBOL as stock_symbol,
BID as bid_amount,
(SUM - MAX) / 2 as computed_ratio,
CONCAT(EXCHANGE, '-', SYMBOL) as unique_id,
'USA' as country
FROM ...