AIWiki
Malaysia
Back to all articles
Applicationstext-to-sqlnl2sqldatabases

Text-to-SQL

4 min readUpdated November 2026
Text-to-SQL
Type
Natural language processing task
Also called
NL2SQL, natural language to SQL, semantic parsing
Emerged
Mid-1990s (natural language interfaces to databases)
Key benchmarks
WikiSQL, Spider, BIRD, Spider 2.0
Key technique
Schema linking, retrieval, agent loops with execution feedback
Related
Large language models, SQL, business intelligence
Text-to-SQL is the task of automatically converting a question expressed in natural language into an SQL query that a relational database can execute. Also written NL2SQL, it is the technical basis for conversational analytics products that let business users ask questions of a database without writing code, and has become a standard capability of coding and analytics agents.[1]

History

Research on natural language interfaces to databases dates to the 1990s, when rule-based and grammar-driven systems translated restricted English into SQL with limited success outside narrow domains. Progress was slow for two decades: schemas are large and idiosyncratic, and ambiguous questions admit many valid queries.[1] The field's first widely reused benchmark, WikiSQL, was released in 2017 and covered single-table queries over 24,000 table–question pairs.[2] Spider (2018) raised the difficulty to cross-database, multi-table queries requiring joins, nesting and aggregation, and remains the standard test of generalisation to unseen schemas.[3]

Large language models transformed the task from 2023 onward. Rather than training a specialised parser, practitioners prompt or fine-tune a general model with the schema in context. Frameworks such as DIN-SQL and DAIL-SQL decomposed the problem into schema linking, query decomposition and self-verification, reaching human-level accuracy on Spider. Benchmarks then moved to realistic settings: BIRD introduced large, noisy databases requiring external knowledge, while Spider 2.0 (2025) targets enterprise warehouses with schemas that can exceed 1,000 columns, mixed dialects and queries spanning dozens of lines.[4]

Key Concepts and Technology

Modern text-to-SQL systems are built around three problems. Schema linking identifies which tables and columns are relevant to a question, since enterprise schemas are far too large to insert verbatim. Grounding resolves references that depend on data values or business terminology ("revenue" may be a derived expression, not a column). Execution feedback lets the system run the generated query, read the error or result, and revise — turning generation into an iterative agent loop rather than a single prediction.[4]

Current systems augment the model with semantic layers — curated, business-readable descriptions of measures and dimensions compiled deterministically into dialect-specific SQL — which decouple intent from physical schema and raise reliability on production data warehouses. Reported results illustrate the remaining gap: on Spider 2.0's enterprise tasks, the strongest agent systems reach roughly 70% execution accuracy, while one semantic-layer-mediated agent reported 94.15% on the Snowflake split of the benchmark.[5][6] Errors concentrate in predicate specification, schema grounding and joins rather than syntax.

Applications and Impact

Text-to-SQL underpins conversational business intelligence in tools such as Microsoft Fabric, Tableau and ThoughtSpot, "chat with your database" features in data platforms, and analytics sub-agents that write and validate queries as part of larger workflows. Its practical value is democratised data access: analysts and managers can explore data without waiting on SQL specialists, and agents can self-serve metrics with verification. Because queries can expose restricted rows, deployment requires the same access controls as direct SQL — generated queries run under the caller's permissions, and results must be governed accordingly.[1][4]

>See Also

🇲🇾Malaysian Context

🇲🇾 Relevance to Malaysia: text-to-SQL is one of the more immediately productive AI applications for Malaysian organisations that already run relational systems — from ERP and accounting platforms to banking and public-sector databases. Malaysian SMEs adopting cloud accounting and business-intelligence tools can query sales, stock and receivables in Bahasa Melayu or English, while analysts in Kuala Lumpur's shared-services and financial-services centres use NL2SQL to shorten reporting cycles. Public-sector data initiatives and MDEC's data-economy programmes benefit from natural language access to open and internal datasets, provided query workloads respect the Personal Data Protection Act 2010 and sector rules from Bank Negara Malaysia and the Securities Commission. Local universities, including Universiti Malaya and Universiti Sains Malaysia, contribute to Malay-language and code-switched text-to-SQL research — an area where off-the-shelf models remain weakest — while Malaysia's NAIO guidance on human oversight and audit trails applies directly to AI-generated queries touching sensitive records.[7]

References

  1. ↑Katsogiannis-Meimarakis, G. & Koutrika, G. (2023). A survey on deep learning approaches for text-to-SQL. The VLDB Journal. https://www.vldb.org/pvldb/vol16/p902-katsogiannis-meimarakis.pdf
  2. ↑Zhong, V., Xiong, C. & Socher, R. (2017). Seq2SQL: Generating Structured Queries from Natural Language using Reinforcement Learning. arXiv:1709.00177. https://arxiv.org/abs/1709.00177
  3. ↑Yu, T. et al. (2018). Spider: A Large-Scale Human-Labeled Dataset for Complex and Cross-Domain Semantic Parsing and Text-to-SQL Task. arXiv:1809.08887. https://arxiv.org/abs/1809.08887
  4. ↑Lei, K. et al. (2025). Spider 2.0: Evaluating Language Models on Real-World Enterprise Text-to-SQL Workflows. arXiv:2411.07763. https://arxiv.org/abs/2411.07763
  5. ↑PExA: Parallel Exploration Agent for Complex Text-to-SQL (2026). arXiv:2604.22934. https://arxiv.org/pdf/2604.22934
  6. ↑A Semantic-Layer-Mediated Agent for Natural Language to SQL over Heterogeneous Enterprise Databases (2026). arXiv:2606.31041. https://arxiv.org/html/2606.31041v1
  7. ↑National AI Office, Malaysia. AI governance guidance for Malaysian organisations. https://www.naio.gov.my/