Streaming SQL
Amp updates derived tables incrementally. SQL inside a derived table definition must be incrementally computable.
Supported Operations
Section titled “Supported Operations”Filtering
Section titled “Filtering”SELECT * FROM anvil.logs WHERE value > 0Projections & Renaming
Section titled “Projections & Renaming”SELECT block_num, hash AS block_hash FROM anvil.blocksTransformations
Section titled “Transformations”SELECT gas_used * 100 / gas_limit AS pct FROM anvil.blocksJoins (Dependency Tables Only)
Section titled “Joins (Dependency Tables Only)”SELECT t.hash, b.timestampFROM anvil.transactions tJOIN anvil.blocks b ON t.block_num = b.block_numUNION ALL
Section titled “UNION ALL”SELECT * FROM a.transfersUNION ALLSELECT * FROM b.transfersCASE Expressions
Section titled “CASE Expressions”SELECT gas_used, CASE WHEN gas_used < 21000 THEN 'minimal' END AS complexityFROM anvil.transactionsUnsupported Operations
Section titled “Unsupported Operations”Not allowed inside derived table definitions:
LIMIT/OFFSETORDER BY(global)GROUP BYwith aggregatesDISTINCT- Window functions
- Non-deterministic functions
- Self-referencing tables
Use these at query time instead.
Example Derived Table Definition
Section titled “Example Derived Table Definition”active_blocks: { sql: ` SELECT block_num, hash AS block_hash, timestamp, gas_used FROM anvil.blocks WHERE gas_used > 0 `,}Need Help?
Section titled “Need Help?”- SQL syntax reference: DuckDB SQL — https://duckdb.org/docs/sql/introduction
- Performance tuning: See Performance Tips in (Streaming SQL Guide)[]