SA-SQL: A Schema-Aligned Framework for Text-to-SQL Through Large Language Models

Yikai Shen,Xin Lin,Jiayu Liu,Zhenya Huang,Shijin Wang,Qi Liu
DOI: https://doi.org/10.1109/clnlp64123.2024.00021
2024-01-01
Abstract:Text-to-SQL is a important task for database-related applications, which automatically translates users’ questions into SQL queries for database. Recently, the large language models (LLMs) has demonstrated promising performances in the task. However, most existing methods do well in translating the question semantics into the SQL, but cannot correctly align the SQL with the database schema (e.g., the primary keys), which leads to several errors in the generated SQL. To tackle the problem, we design SA-SQL, a novel schema-aligned framework for text-to-SQL task following the draft-and-correction manner. First, we select the question-relevant tables and columns from the whole schema with a selector to exclude the noise for generating a concise SQL and reduce the input length. Next, based on the selected tables and columns, we generate a draft of the SQL with a generator to capture the question semantics. Last, considering the alignment between the SQL and the database schema, we design a corrector to detect and correct the possible errors in the draft. We conduct extensive experiments on two widely-used dataset for text-to-SQL, and our framework has achieved comparable execution accuracy to existing state-of-the-art methods on the Spider dataset and BIRD dataset, which proves the effectiveness of our framework.
What problem does this paper attempt to address?