SQL Generator

SQL Generator: Describe the question, get the query.

Write the question in English, get a production-shaped query with an explicit schema assumption you can correct.

Question
0 words0 / 4,000
ask a question first
SQL

No query yet

Describe the question in English. You get a formatted query plus the schema it assumed, so a wrong column name is visible rather than buried.

idle

Read a generated UPDATE or DELETE before running it against anything that matters. There is no transaction wrapping it.

What this instrument does

Describe the question in English, get a formatted query with its schema assumptions written out so you can correct them.

The assumptions block is not decoration. Generated SQL is usually wrong because the model guessed at your schema. Fixing a stated assumption is much cheaper than debugging a wrong column name.

How it works

The schema assumption is shown
A default commerce schema is used unless your question overrides it, and every deviation from it is listed. You can paste your real column names into the question to steer it.
Filters go in WHERE where possible
Non-aggregate conditions belong in WHERE, not HAVING. Getting this wrong silently changes results once you add a GROUP BY, because HAVING is evaluated after aggregation.
Indexes are suggested against your actual query
The notes include CREATE INDEX statements for the columns this specific query filters, joins and sorts on.

Questions about SQL Generator

Questions
Which SQL dialect does it generate?
ANSI SQL with explicit JOINs and qualified column names. Where a dialect-specific function is unavoidable, such as date truncation, the notes call it out.
Why does it not know my table names?
It has no connection to your database and no schema to read. It works from a default commerce schema and from whatever your question states. Paste your column definitions into the question for a closer result.
What is the difference between WHERE and HAVING?
WHERE filters rows before grouping and cannot reference aggregates. HAVING filters groups after aggregation and can. Using HAVING for a condition that does not involve an aggregate is not equivalent once a GROUP BY is present, it evaluates against the grouped result set, which is a different set of rows.
Will it write an UPDATE or DELETE?
It will, if that is what you ask for. Read the query before running it against anything that matters. A generated statement has not been checked against your data.

All instruments

Other instruments