Text to SQL

Turn a plain-English question into correct SQL: schema-grounded, dialect-aware, edge cases handled, and the query explained back.

Write SQL to answer my question.

My schema (tables, columns, types, plus 2-3 sample rows per table if available; samples resolve ambiguity better than descriptions):
"""
[PASTE CREATE TABLE STATEMENTS OR SCHEMA DUMP]
"""

Dialect: [POSTGRES / MYSQL / SQLITE / BIGQUERY / SNOWFLAKE]
The question, in plain English: [WHAT YOU WANT TO KNOW, e.g. "monthly revenue per plan for the last 6 months, including months with zero"]
Definitions that matter: [BUSINESS RULES, e.g. "'active' means status='active' AND deleted_at IS NULL", "revenue excludes refunds", or "none, use your judgment and state it"]

Produce:
1. **Interpretation check**: restate the question as you understood it, including every judgment call you're making (which timestamp column means "when it happened", how you're treating NULLs, timezone assumptions). If the question is genuinely ambiguous between two readings with different answers, show both readings and ask: a fast wrong query costs more than a clarifying question.
2. **The query**: clean, formatted, CTEs over nested subqueries for readability, dialect-correct functions only. SELECT queries only: never write UPDATE/DELETE/DDL unless I explicitly ask, and even then wrap destructive statements in a transaction with a row-count check first.
3. **Line-by-line explanation**: brief, so I can verify the logic matches my intent without being a SQL expert.
4. **Edge cases handled**: state explicitly how the query behaves on: empty groups (months with no sales, included or missing?), NULLs in joined columns, ties in rankings, duplicates from one-to-many joins (the classic silent row-multiplication bug; confirm the join grain).
5. **The sanity check**: one cheap verification query I can run to confirm the result is plausible (e.g. "this total should roughly match SELECT SUM(...), if it's 3x bigger, the join is fanning out").

Rules: use only tables and columns that exist in my schema. If the question needs data the schema doesn't hold, say exactly what's missing instead of inventing a plausible column name.

How to use

The two failure modes of AI-written SQL are hallucinated columns and silent join fan-out: the schema-grounding rule kills the first, the join-grain check in step 4 catches the second. Paste real sample rows whenever you can; they resolve naming ambiguity ('is amount in cents or dollars?') that schema alone can't. Run the sanity check before trusting any number in a report.

Originated fromStan SedberryUpdated
Code generationbeginner

More coding prompts

Write the commit message for this change.

Diff:
"""
[PASTE THE STAGED DIFF]
"""

Why I made this change: [THE REASON, THE TICKET, THE BUG REPORT, or "you infer it"]
Convention: [Conventional Commits / this repo's existing style, pasted below / plain]
Recent commits from this repo, to match style:
"""
[PASTE 5-10 RECENT COMMIT SUBJECT LIN

Commit Message

Write a commit message that explains why the change was made, in Conventional Commits format, split into separate commits when needed.

Codingbeginner
Help me recover from a git mistake without making it worse.

What I was trying to do: [THE GOAL]
What I ran: [THE EXACT COMMANDS, IN ORDER]
What happened instead: [THE OUTPUT OR THE STATE NOW]
Has this been pushed or shared: [YES/NO, and to which branch and whether anyone else has pulled]
Uncommitted work I cannot lose: [WHAT AND WHERE, o

Undo a Git Mistake

Recover from a bad commit, force push, wrong branch, or lost work with a reversible plan and the exact commands, explained before you run them.

Codingintermediate
Handler code, routes, and models:
"""
[PASTE THE ROUTE DEFINITIONS, HANDLERS, REQUEST AND RESPONSE TYPES, VALIDATION SCHEMAS, AND MIDDLEWARE]
"""

Generate an OpenAPI 3.1 specification from the code above.

API name, version, and base URL: [DETAILS]
Auth scheme: [BEARER JWT / API KEY / OAUTH / SESSION COOKIE, and where it is enforced]
Con

OpenAPI Spec From Code

Generate an accurate OpenAPI 3.1 spec from handler code, including error responses and auth, with gaps flagged instead of invented.

Codingintermediate

Search prompts

Find a prompt by title, description, tag, or category.