Skip to main content
command CX Codex

write-query — Claude Code command: SQL from text

write-query turns plain language descriptions into SQL queries across BigQuery, PostgreSQL, MySQL and other dialects. Upload a schema or describe your tables, then ask your question.

MIT ★ 28,211 updated 2026-10-16

Install into Claude Code · Plugin marketplace All methods and platforms ↓
/plugin marketplace add phuryn/pm-skills
/plugin install pm-data-analytics@pm-skills
Open on GitHub

What write-query does

Tell the command what data you're after—daily active users by plan, signup-to-paid conversion by cohort, users who bounced at onboarding. It parses your question, figures out which tables and columns you need, generates a query, and explains what it does. If you provide a schema (diagram, DDL, or description), it maps your request directly. If not, it asks whether you're on BigQuery or PostgreSQL and infers reasonable table names.

The command works through four steps: understand the question, determine the schema, generate the query using the sql-queries skill, and present the result with assumptions and performance notes. All queries include comments so your analysts can follow the logic. It offers to tweak the query—add filters, build a companion metric, create a dashboard, or pivot to cohort analysis.

If a query might crawl on large datasets, the command flags it and suggests optimization paths.

What it helps with

  • Write SQL without memorizing every dialect's syntax
  • Turn a verbal question about data into a working query
  • Rewrite a query for a different database
  • Figure out which tables and joins you need

Example prompts for the agent

  • Show me daily active users for the last 30 days, split by plan tier
  • Find users who signed up last month but never completed onboarding
  • [upload schema] What's our trial-to-paid conversion by user cohort

How to install write-query

1Plugin marketplace

/plugin marketplace add phuryn/pm-skills
/plugin install pm-data-analytics@pm-skills

2Manually: put the files in place

.claude/commands/write-query.md

Call it with /write-query. For all projects use ~/.claude/commands/

Questions about write-query

How do I install write-query in Claude Code?

Run /plugin marketplace add phuryn/pm-skills, then /plugin install pm-data-analytics@pm-skills, then add the file .claude/commands/write-query.md to your project.

What does write-query do?

It translates plain language questions into SQL queries. Supports BigQuery, PostgreSQL, MySQL and other dialects, handles schema mapping, and returns optimized queries with comments and assumptions.

Do I need to provide a database schema?

Not required, but helpful. Without one, the command will ask which database you're using and confirm table structure with you before generating the query.

Source text

write-query.md · MIT
---
description: Generate SQL queries from natural language — supports BigQuery, PostgreSQL, MySQL, and more
argument-hint: "<what you want to know, in plain English>"
---

# /write-query -- SQL Query Generator

Describe what data you need in plain English and get an optimized SQL query. Supports multiple dialects and can read your schema from uploaded files.

## Invocation

```
/write-query Show me daily active users for the last 30 days, broken down by plan tier
/write-query Find users who signed up last month but never completed onboarding
/write-query [upload a schema diagram] What's the conversion rate from trial to paid by cohort?
```

## Workflow

### Step 1: Understand the Question

Parse the user's natural language request to identify:
- What data is being requested (metrics, dimensions, filters)
- Time range and granularity
- Grouping and ordering preferences
- Output expectations (raw data, aggregated, ranked)

### Step 2: Determine Schema

If a schema is available (uploaded diagram, DDL, or description):
- Map the request to specific tables and columns
- Identify necessary joins

If no schema is provided:
- Ask for the database type (BigQuery, PostgreSQL, MySQL, etc.)
- Infer a reasonable schema from the question and ask the user to confirm
- Use common SaaS data model conventions as defaults

### Step 3: Generate Query

Apply the **sql-queries** skill:

- Write the SQL query in the correct dialect
- Optimize for readability and performance
- Include comments explaining key logic
- Add CTEs for complex queries to improve readability
- Handle edge cases (NULLs, timezone considerations, duplicate handling)

### Step 4: Present and Iterate

```
## SQL Query: [What It Does]

**Dialect**: [BigQuery / PostgreSQL / MySQL / etc.]
**Tables used**: [list]

### Query
[SQL code block with comments]

### What This Returns
[Description of the output: columns, rows, expected result shape]

### Assumptions
- [Schema assumptions made]
- [Business logic assumptions]

### Notes
- [Performance considerations for large datasets]
- [Edge cases handled or flagged]
```

Offer:
- "Want me to **modify this** — add filters, change grouping, extend the time range?"
- "Should I **create a companion query** for a related metric?"
- "Want me to **build a dashboard** around this query?"
- "Need a **cohort analysis** version of this?"

## Notes

- Always include comments in the SQL — PMs share queries with analysts who need to understand intent
- Default to readable over clever — CTEs over nested subqueries
- Flag queries that might be slow on large datasets and suggest optimization
- If the request is ambiguous (e.g., "active users"), ask the user to define the metric precisely
- Offer to generate the query in multiple dialects if the user is unsure which database they're using

© Paweł Huryn · MIT · phuryn/pm-skills

Similar slash commands

All slash commands for Data and databases →

From the same set120

The whole set →
privacy-policy Drafts a privacy policy tailored to GDPR and CCPA, complete with compliance checklists and flags for legal review. Useful when launching new apps and web tools. CX Codex +1 ★ 28,211repo stars tailor-resume tailor-resume matches a resume to a target job description by aligning terms, reframing experience, and exposing gaps before an application. CX Codex +1 ★ 28,211repo stars red-team-prd The red-team-prd command for Claude Code extracts and challenges assumptions that could break a plan, then suggests the cheapest test for each. CX Codex +1 ★ 28,211repo stars generate-data generate-data generates realistic mock datasets in CSV, JSON, or SQL using Python scripts with custom distributions and constraints. CX Codex +1 ★ 28,211repo stars value-proposition value-proposition maps a product or feature to a six-part template: target user, their job, current friction, your solution, resulting outcome, and why you beat alternatives. CX Codex +1 ★ 28,211repo stars test-scenarios Turns user stories and feature specifications into structured test scenarios covering happy paths, edge cases, and errors. CX Codex +1 ★ 28,211repo stars meeting-notes Turns a transcript or rough meeting notes into structured minutes with decisions, assigned actions, open questions, and next steps. CX Codex +1 ★ 28,211repo stars review-resume review-resume is a Claude Code command that evaluates product manager resumes against best practices and gives three priority improvements with examples. CX Codex +1 ★ 28,211repo stars

Project sponsors

Companies that keep this analytics open