🤖 Introducing FlipAI Agents: Data Science in Your Pocket. Expert AI-assistants trained by data scientists to solve specific problems in minutes. Learn more →
Best practices for writing efficient queries against Flipside data shares
Flipside’s blockchain data is optimized for performance through strategic clustering and indexing.
Understanding how tables are organized will help you write faster, more cost-effective queries.
The timestamp when the row was last modified (for updates or corrections).Use for:
Detecting data corrections
Change data capture (CDC)
Audit trails
Clustered: ❌ No
Performance tip: Always include a block_timestamp filter, even when filtering on
_inserted_timestamp or _modified_timestamp. This leverages the clustering.
WITH recent_txs AS ( SELECT * FROM ethereum.core.fact_transactions WHERE block_timestamp >= CURRENT_DATE - 7 AND success = TRUE)SELECT DATE_TRUNC('day', block_timestamp) AS date, COUNT(*) AS tx_countFROM recent_txsGROUP BY 1;
For queries with multiple CTEs, consider using MATERIALIZED:
Copy
Ask AI
WITH base_data AS MATERIALIZED ( SELECT block_timestamp, from_address, to_address, eth_value FROM ethereum.core.fact_transactions WHERE block_timestamp >= CURRENT_DATE - 30 AND eth_value > 0)SELECT from_address, COUNT(*) AS tx_count, SUM(eth_value) AS total_ethFROM base_dataGROUP BY 1HAVING total_eth > 100ORDER BY total_eth DESC;
-- Daily transaction countsSELECT DATE_TRUNC('day', block_timestamp) AS date, COUNT(*) AS tx_count, COUNT(DISTINCT from_address) AS unique_sendersFROM ethereum.core.fact_transactionsWHERE block_timestamp >= CURRENT_DATE - 30GROUP BY 1ORDER BY 1;
-- All activity for an addressSELECT block_timestamp, tx_hash, from_address, to_address, eth_valueFROM ethereum.core.fact_transactionsWHERE block_timestamp >= CURRENT_DATE - 90 AND (from_address = LOWER('0x...') OR to_address = LOWER('0x...'))ORDER BY block_timestamp DESC;
Case sensitivity: Ethereum addresses are case-insensitive. Use LOWER() for comparisons to
ensure matches.