fix: quote reserved keyword 'window' in trend query, add Top Movers sample, make seed upsert
This commit is contained in:
@@ -17,7 +17,7 @@ INSERT INTO saved_queries (name, description, sql_text) VALUES
|
||||
'SELECT ticker, confidence, mode, thesis, generated_at FROM recommendations WHERE action = ''buy'' AND confidence >= 0.75 ORDER BY confidence DESC LIMIT 50'),
|
||||
|
||||
('Trend Windows Summary', 'Current trend direction and strength by ticker',
|
||||
'SELECT entity_id AS ticker, window, trend_direction, trend_strength, confidence FROM trend_windows ORDER BY trend_strength DESC LIMIT 100'),
|
||||
'SELECT entity_id AS ticker, "window", trend_direction, trend_strength, confidence FROM trend_windows ORDER BY trend_strength DESC LIMIT 100'),
|
||||
|
||||
('Market Prices', 'Latest close prices for tracked companies',
|
||||
'SELECT DISTINCT ON (ticker) ticker, (data->>''c'')::float AS close, (data->>''o'')::float AS open, (data->>''h'')::float AS high, (data->>''l'')::float AS low, (data->>''v'')::float AS volume, captured_at FROM market_snapshots WHERE snapshot_type = ''bar'' ORDER BY ticker, captured_at DESC'),
|
||||
@@ -41,5 +41,8 @@ INSERT INTO saved_queries (name, description, sql_text) VALUES
|
||||
'SELECT c.sector, count(*) AS positions, sum((ms.data->>''c'')::float) AS total_close_price FROM companies c JOIN market_snapshots ms ON c.ticker = ms.ticker WHERE ms.snapshot_type = ''bar'' GROUP BY c.sector ORDER BY total_close_price DESC'),
|
||||
|
||||
('Source Coverage Matrix', 'Active sources per company',
|
||||
'SELECT c.ticker, c.legal_name, count(*) FILTER (WHERE s.source_type = ''market_api'') AS market, count(*) FILTER (WHERE s.source_type = ''news_api'') AS news, count(*) FILTER (WHERE s.source_type = ''filings_api'') AS filings, count(*) AS total FROM companies c LEFT JOIN sources s ON c.id = s.company_id AND s.active = TRUE WHERE c.active = TRUE GROUP BY c.ticker, c.legal_name ORDER BY c.ticker')
|
||||
ON CONFLICT (name) DO NOTHING;
|
||||
'SELECT c.ticker, c.legal_name, count(*) FILTER (WHERE s.source_type = ''market_api'') AS market, count(*) FILTER (WHERE s.source_type = ''news_api'') AS news, count(*) FILTER (WHERE s.source_type = ''filings_api'') AS filings, count(*) AS total FROM companies c LEFT JOIN sources s ON c.id = s.company_id AND s.active = TRUE WHERE c.active = TRUE GROUP BY c.ticker, c.legal_name ORDER BY c.ticker'),
|
||||
|
||||
('Top Movers', 'Biggest price change vs previous day open',
|
||||
'SELECT DISTINCT ON (ticker) ticker, (data->>''c'')::numeric AS close, (data->>''o'')::numeric AS open, round(((data->>''c'')::numeric - (data->>''o'')::numeric) / NULLIF((data->>''o'')::numeric, 0) * 100, 2) AS change_pct FROM market_snapshots WHERE snapshot_type = ''bar'' AND (data->>''o'')::float > 0 ORDER BY ticker, captured_at DESC')
|
||||
ON CONFLICT (name) DO UPDATE SET sql_text = EXCLUDED.sql_text, description = EXCLUDED.description;
|
||||
|
||||
Reference in New Issue
Block a user