Back to Skills

write-query

Write optimized SQL for your dialect with best practices. Use when translating a natural-language data need into SQL, building a multi-CTE query with joins and aggregations, optimizing a query against a large partitioned table, or getting dialect-specific syntax for Snowflake, BigQuery, Postgres, etc.

22,126stars2,591forksUpdated 6/29/2026

Security Assessment

Safe(100/100)
Security Score100/100

About write-query

A slash-command skill that turns a natural-language data need into an optimized SQL query for a specific dialect while following best practices. It is invoked as /write-query with a description of the data wanted, and it suits cases ranging from a simple aggregation to a multi-CTE query with joins and aggregations, an optimization against a large partitioned table, or getting dialect-specific syntax for warehouses such as Snowflake, BigQuery, or Postgres.

The workflow first parses the request to identify output columns, filters, aggregations, joins, ordering, and limits, then determines the SQL dialect, asking when it is not already known. Supported dialects named in the doc include PostgreSQL (with Aurora, RDS, Supabase, and Neon), Snowflake, BigQuery, Redshift, Databricks SQL, MySQL (including Aurora MySQL and PlanetScale), SQL Server, DuckDB, and SQLite, and the chosen dialect is remembered for the rest of the session. If a data warehouse MCP server is connected, it discovers schema by searching for relevant tables, inspecting columns and relationships, checking partitioning or clustering keys, and looking for pre-built or materialized views that simplify the query.

Query construction follows explicit best practices: descriptive CTEs for multi-step logic, avoiding SELECT * in production, filtering early, using partition filters, preferring EXISTS over IN for large subqueries, choosing correct JOIN types, avoiding correlated subqueries when a JOIN or window function works, and watching for exploding many-to-many joins. Readability conventions cover comments explaining the why, consistent indentation, and meaningful table aliases. The query is presented with an explanation of each section, performance notes where relevant, and suggestions for common variations, and when a warehouse is connected the skill offers to run the query and analyze the results. Deeper dialect specifics are deferred to the related sql-queries skill.

FAQ

How do I invoke this skill?

Run /write-query followed by a description of the data you need, for example a count of orders by status for the last 30 days or a cohort retention analysis.

Which SQL dialects are supported?

The doc names PostgreSQL (including Aurora, RDS, Supabase, Neon), Snowflake, BigQuery, Redshift, Databricks SQL, MySQL (including Aurora MySQL and PlanetScale), SQL Server, DuckDB, and SQLite, plus an option to specify another.

Does it need a database connection to work?

No. It can write the query from your description alone, but if a data warehouse MCP server is connected it will discover schema, check partitioning, look for useful views, and can offer to run the query and analyze results.

What performance practices does it follow?

It avoids SELECT * in production, filters early, uses partition filters when available, prefers EXISTS over IN for large subqueries, chooses appropriate JOIN types, avoids correlated subqueries where a JOIN or window function works, and watches for exploding many-to-many joins.

Does it remember my dialect during a session?

Yes. Once the dialect is known it is remembered for future queries in the same session, so you only need to state it once.

Install write-query

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill