Write SQL From Plain English
The schema is the part people forget to give. With it, the model writes a query that uses your real table and column names and explains each part.
Works with Claude, ChatGPT and Gemini3 fields
Write a PostgreSQL 16 query. Schema: ``` orders(id, user_id, total, created_at) users(id, country) ``` Question: revenue per country in the last 30 days, highest first Use only the tables and columns above. Explain each clause in one line. Point out anything that could be slow on large tables and the index that would help. If the question is ambiguous (for example time zones or NULLs), state the assumption you made.
Everything you type stays in your browser. Remove passwords, keys and personal data before pasting anything into an AI tool.
Why this prompt is written this way
- Real schema. Without it, the model invents table names you have to fix.
- Stated assumptions. Date ranges and NULL handling change results; you should see the choice.
- Performance note. A query that works on test data can be slow in production.
Example answer
Illustrative and shortened, to show the shape of a good answer. Real answers vary by model.
SELECT u.country, SUM(o.total) AS revenue FROM orders o JOIN users u ON u.id = o.user_id WHERE o.created_at >= now() - interval '30 days' GROUP BY u.country ORDER BY revenue DESC; Index: orders(created_at).
Tips
- Run the query with LIMIT first and check a few rows by hand.
- Paste the error back if the query fails; include the database version.
How to use it
- Replace the example values with your own. The prompt on the right updates as you type.
- Press Copy prompt and paste it into any AI chat, or open it straight in Claude or ChatGPT.
- Save it as prompt.md if you want to reuse it.