Glossary
What is text-to-SQL?
Text-to-SQL is a technique in which an AI model converts a question in plain language into an SQL query that is run on a database. The model writes the query; the database supplies the figures.
Text-to-SQL explained
A text-to-SQL system gives the language model your question and a description of the database: tables, columns, relationships and ideally a data dictionary. The model writes a query, the database runs it and the result comes from your own data. The model does not calculate anything itself, which is exactly why this approach suits figures.
The biggest risks are a query that runs but calculates something other than you meant, and questions with an unclear definition. "Revenue" can include or exclude VAT, and "customer" can mean active customers or all of them. Always show the query next to the answer, so someone can check what was calculated.
Text-to-SQL is not the same as RAG. RAG looks up text passages in documents and has the model summarise them, while text-to-SQL lets the database calculate on structured data. For questions such as "how many" and "what is the total", text-to-SQL is the more reliable route.
Example
An account manager at Acme Groothandel asks: "Which ten customers bought the most this quarter?" The model writes a query with SUM(total_amount), GROUP BY customer_id and LIMIT 10 on the orders table, and the account manager sees the query and the result side by side.
Text-to-SQL in ENABLE
The ENABLE SQL Explorer turns a plain-language question into read-only SQL on your own PostgreSQL data warehouse, using the OpenAI API. ENABLE checks the query with a read-only query plan, and it only runs when the user presses run. The AI can also explain or fix a query.
FAQ
Frequently asked questions
What is the difference between text-to-SQL and RAG?
Text-to-SQL has an AI model write a database query, after which the database calculates the figures. RAG looks up relevant text passages in documents and has the model build an answer from them. Text-to-SQL suits figures; RAG suits text.
How reliable is text-to-SQL?
It depends mainly on the data model, the data dictionary and whether someone checks the query. With clear names and descriptions and the query visible next to the answer, the chance of a wrong figure is much smaller.
Does the AI model see my data with text-to-SQL?
It does not have to. To write the query the model only needs metadata, such as table and column names. Whether data is sent anyway depends on how the tool is built.
Further reading
- ResourcesText-to-SQL explained: AI on your databaseText-to-SQL is a technique in which an AI model converts a question in plain language into an SQL query, which is then run on a database. The language model writes the query; the database supplies the figures. How well that works depends mainly on the quality of your metadata and on the safeguards around execution, such as read-only access, timeouts and row limits.Read more
- PlatformSQL Explorer with AI: ask your database questionsAsk your data warehouse in plain language. The AI writes the SQL, you stay in control.Read more
- ResourcesRAG or text-to-SQL: which AI should you choose?RAG and text-to-SQL are two ways to make AI work with your own data. RAG (retrieval-augmented generation) searches your documents for relevant text passages and lets the model formulate an answer from them; text-to-SQL lets the model write a query on a database, so that the database does the calculating. Use RAG for questions about documents and knowledge, and text-to-SQL for questions about figures.Read more
- SolutionAI on your own data: ask questions of business dataQuestion your data warehouse in plain language. The AI sees the structure, not your rows.Read more
Use AI on your own data. Securely, and without the headache.
In an online demo we show how ENABLE makes your data securely available and how you build on it: describing an app in the AI Builder, plain-language questions, dashboards and APIs. And how we set it up and manage it for you.