What is Text-to-SQL?

Text-to-SQL is the task of converting a question written in plain language into a SQL query that answers it.

Text-to-SQL explained

Modern language models can do this by reading the question together with the database schema. The hard parts are the same ones a human analyst faces: knowing which table and column hold the concept, how tables join and what the business means by a term.

Because errors can look plausible, good text-to-SQL products show the query, run it read-only and make the results checkable. How accurate any system is depends on your schema and questions, so test it on questions whose answers you already know.

Example

'Total revenue by month for 2026' becomes a SELECT with DATE_TRUNC, SUM and GROUP BY against an orders table.

Frequently asked questions

What is Text-to-SQL?
Text-to-SQL is the task of converting a question written in plain language into a SQL query that answers it.
Can you give an example of Text-to-SQL?
'Total revenue by month for 2026' becomes a SELECT with DATE_TRUNC, SUM and GROUP BY against an orders table.