Query editor
-- GLOBAL GEM HUNTER v9-lite-fix2 -- BNB + SOLANA-- =============================================================================---- CHANGES vs v9-lite-fix:---- FIX-A Removed '%{{%' placeholder guards (caused the parse crash)-- '%{{%' inside a string literal triggers Dune's preprocessor greedy scan.-- Dune finds '{{' then scans forward for '}}', consuming everything up to-- the NEXT '}}' in the file (the closing brace of '{{Run Mode}}' on the ELSE-- branch). The garbled token breaks the CASE expression so Trino receives-- END outside any CASE -- error: mismatched input 'END' at line 44 col 61.-- Fix: removed all CASE WHEN ... LIKE '%{{%' wrappers. Dune always resolves-- {{...}} before execution so these guards solved a non-existent problem.-- try_cast handles blank numeric params. lower(trim()) handles blank text.---- FIX-B Strict mode structural zero-result fixes-- 1. urgency bypass: added freshness_label IN ('JUST_LAUNCHED','VERY_FRESH')-- AND momentum_phase IN ('PUMPING','IGNITING') as a third OR branch so-- quiet-period runs with genuinely fresh+active tokens always surface.-- 2. gem_score bypass lowered 65 -> 60 (more achievable in calm markets).-- 3. min_urgency default lowered 40 -> 25 (kept from fix1).-- 4. mcap band widened: default min 5k->2k, max 250k->500k.-- 5. thin_liquidity_flag: mcap threshold raised 50k->100k, trader floor-- tightened 8->5. Stops early concentrated-whale tokens being killed.-- 6. stale_tokens exclusion window shortened 4h->2h so re-igniting tokens-- that consolidated briefly can re-enter the scan.-- 7. risk_score trader-count component discounted for JUST_LAUNCHED tokens:-- low trader count is expected at birth, not a rug signal.---- All v9-lite-fix fixes retained:-- FIX 1 min_urgency default 25, OR gem_score bypass-- FIX 2 to_hex() only on BNB (varbinary), Solana cast as varchar-- FIX 3 stale_tokens carries chain column, anti-join on (chain, address)-- FIX 4 Expanded Solana base token list + NULL symbol guard---- All v9-lite performance improvements retained:-- Single raw scan, anti-join stale exclusion, UNNEST for BNB,-- $25 floor, $1k HAVING, params-as-columns (no repeated CROSS JOINs).-- =============================================================================WITH raw_params AS (-- FIX-A: removed all '%{{%' LIKE guards -- Dune always resolves params-- before Trino sees the SQL. The guards caused a greedy preprocessor match-- that swallowed everything between '{{' in the LIKE string and the next-- '}}' in the file, producing a parse error at the END keyword.SELECTreplace(replace(lower(trim('{{Run Mode}}')), ' ','_'),'-','_') AS raw_run_mode,replace(replace(lower(trim('{{Region}}')), ' ','_'),'-','_') AS raw_region_filter,replace(replace(lower(trim('{{Narrative Type}}')), ' ','_'),'-','_') AS raw_narrative_filter,replace(replace(lower(trim('{{Chain}}')), ' ','_'),'-','_') AS raw_chain_filter,coalesce(try_cast('{{Max Age Minutes}}' AS double), 240.0) AS max_age_minutes,-- FIX-B4: widened default mcap band for better quiet-market coveragecoalesce(try_cast('{{Min Mcap USD}}' AS double), 2000.0) AS min_mcap_usd,coalesce(try_cast('{{Max Mcap USD}}' AS double), 500000.0) AS max_mcap_usd,coalesce(try_cast('{{Min Fees BNB}}' AS double), 0.005) AS min_fees_bnb,coalesce(try_cast('{{Min Volume USD}}' AS double), 3000.0) AS min_volume_usd,coalesce(try_cast('{{Min Gem Score}}' AS double), 38.0) AS min_gem_score,coalesce(try_cast('{{Max Risk Score}}' AS double), 62.0) AS max_risk_score,-- FIX-B (FIX 1 retained): default 25 so quiet runs still surface results