/polymath-data:sql-writefrom polymath-data
Write a SQL query that answers a specific question; parameterized, dialect-aware, readable, with the assumed schema documented inline.
Ships in polymath-data. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Translate a question into a SQL query. Output the query, the schema assumptions, and how to verify the result.
Mode: analytical — judgment inside a fixed frame. Keep the output shape; every verdict cites its evidence; unknowns are marked [TBD] or [VERIFY], never filled in.
DATE_TRUNC vs DATE_FORMAT, INTERVAL '7 days' vs INTERVAL 7 DAY).DATE_TRUNC / window-function syntax.$1, ?, :name) — never string-concatenate user input.created_at >= now() - interval '7 days', not date(created_at) = …); predicate order in the SQL text doesn't matter to the planner.GROUP BY <columns>; don't rely on MySQL's loose grouping. Use HAVING for filtering aggregates, WHERE for filtering rows.NOT IN (subquery) returns nothing if the subquery yields a NULL — use NOT EXISTS; state the time zone of every date boundary (date_trunc('day', ts AT TIME ZONE 'UTC')).LIMIT and against a replica where one exists. Any INSERT/UPDATE/DELETE/DDL is shown to the user first, run only on explicit approval, inside a transaction.-- Active users in the last 7 days by country.
-- Dialect: Postgres 15. Grain: country code.
-- Tables: events(user_id, created_at, country_code).
-- Assumes country_code is indexed; (user_id, created_at) is indexed.
WITH recent_active AS (
SELECT DISTINCT user_id, country_code
FROM events
WHERE created_at >= now() - INTERVAL '7 days'
)
SELECT
country_code,
COUNT(*) AS active_users
FROM recent_active
GROUP BY country_code
ORDER BY active_users DESC;
Verification:
'1 day'); the count for the 7-day query should be ≥ the 1-day count for the same country.events.country_code is non-null for the rows you care about; otherwise add an IS NOT NULL predicate and discuss the bias.SELECT * in production queries.BETWEEN with timestamps when one side is exclusive in the intent.varchar = int).What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
4 skills in this plugin
/metrics-treeDecompose a North Star metric into a tree of input metrics so each team can see the lever they own; output is a tree, not a dashboard./run-experimentPlan an A/B (or A/B/n) experiment — hypothesis, primary + guardrail metrics, MDE + sample size + duration, randomization, stop conditions./sql-optimizeRead EXPLAIN ANALYZE output and propose targeted optimizations — index, predicate, join order, or query shape changes.npx claudepluginhub mohammadbafkar/polymath --plugin polymath-data