DB
SQL reference

Views, materialized views, and streams

Define reusable queries, maintained results, and named stream routes.

Logical views

A logical view stores a query and expands it at read time:

CREATE VIEW large_trades AS
SELECT id, market, amount
FROM trades
WHERE amount >= 100000;

SELECT market, count()
FROM large_trades
GROUP BY market;

Views are read-only. CREATE OR REPLACE VIEW replaces an existing view but does not overwrite a table or another object kind.

Parameterized views

Declare typed placeholders in the view definition:

CREATE VIEW trades_for_market AS
SELECT id, market, amount
FROM trades
WHERE market = ${market:String};

SELECT * FROM trades_for_market(market => 'BTC-USD');
SELECT * FROM trades_for_market('ETH-USD');

Arguments can be named or positional and are type-checked before execution.

Materialized views

Status: Experimental

Materialized views maintain stored query results:

CREATE MATERIALIZED VIEW market_totals AS
SELECT market, sum(amount) AS total_amount
FROM trades
GROUP BY market;

SELECT * FROM market_totals ORDER BY market;

CREATE OR REPLACE MATERIALIZED VIEW is accepted. The binder validates the supported query shape; a query that is valid as an ordinary SELECT may still be rejected for incremental maintenance. Test replacement and rebuild behavior against the release you deploy.

Named streams

Create a named route from a source and key:

CREATE STREAM trade_changes
FROM trades
KEY (market, id);

The key is part of the route identity. Internally, handler chaining matches the full stream:key pair, never the stream name alone. Named streams do not create a broker, replication log, or cross-node transport.

Read live results with the statement prefix documented in Streaming queries:

STREAM SELECT *
FROM trades
WHERE market = 'BTC-USD';

Inspect views with SHOW VIEWS and SHOW MATERIALIZED VIEWS. Remove objects with DROP VIEW or DROP MATERIALIZED VIEW.

On this page