A Text-to-SQL System Based on ChatGPT

Authors

  • Piyapong Dangkham Faculty of Industrial Technology, Thepsatri Rajabhat University
  • Wadeenat Wannasawaskul Faculty of Industrial Technology, Thepsatri Rajabhat University

Keywords:

Text-to-SQL, Large Language Model, database, ChatGPT

Abstract

This research presents the development and evaluation of a prototype system capable of accurately translating Thai natural language queries into SQL statements. The system leverages a Large Language Model (LLM) implemented as a customized GPT on the ChatGPT platform and connected to a MySQL database through a Web API. Users interact with the system through a conversational interface by submitting queries in natural language. The system then translates these queries into executable SQL statements, executes them against the database, and returns the results in tabular form. The system was evaluated using a dataset of 30 Thai natural language queries. The experimental results demonstrated that the proposed system achieved an average SQL generation accuracy of 90.00%, a query execution success rate of 100.00%, and an average response time of 0.0045 seconds per query. These findings indicate the potential of the system for practical deployment, particularly in scenarios where users need efficient access to structured data without requiring specialized knowledge of database query languages.

References

Cagliero, L., Farinetti, L., Fior, J., & Manenti, A. I. (2024). ChatGPT, be my teaching assistant! automatic correction of SQL exercises. In L. O’Conner (Ed.), 2024 IEEE 48th Annual Computers, Software, and Applications Conference (COMPSAC) (pp. 81–86). IEEE.

Carr, N., Shawon, F. R., & Jamil, H. M. (2023). An experiment on leveraging ChatGPT for online teaching and assessment of database students. In M. Kuo & R. Sinha (Eds.), 2023 IEEE International Conference on Teaching, Assessment and Learning for Engineering (TALE) (pp. 1–8). IEEE.

Deshpande, A., Mane, P., Kothari, D., Salvi, A., & Kolhe, V. (2022). Querylizer: An interactive platform for database design and text to SQL conversion. In S. A. Thorat, A. Adamuthe & D. Gupta (Eds.), Proceedings of the International Conference on Advanced Technology (ICONAT) (pp. 1–6). IEEE.

Lan, Z., & Li, S. (2024). PS-SQL: Phrase-based schema-linking with pre-trained language models for Text-to-SQL parsing. In E. X. Wang & R. Minasian (Eds.), Proceedings of the 6th International Conference on Natural Language Processing (ICNLP) (pp. 31–34). IEEE.

Liu, S., Almohaimeed, S., & Wang, L. (2025). REFORMER: A ChatGPT-driven data synthesis framework elevating Text-to-SQL models. arXiv:2504.04363v1. https://doi.org/10.48550/arXiv.2504.04363

MySQLTutorial.org. (2025). MySQL sample database. https://www.mysqltutorial.org/getting-started-with-mysql/mysql-sample-database/

Nilsiam, Y., Khammaw, P., & Nuchitprasitchai, S. (2025). OpenAI-powered NLP for SQL generation: En hancing database access for non-technical users [In Thai]. In K. Chaiwong (Ed.), The 10th International Conference on Digital Arts, Media and Technology (DAMT) and 8th ECTI Northern Section Conference on Electrical, Electronics, Computer and Telecommunications Engineering (NCON) (pp. 423–428). IEEE.

Ning, Z., Zhang, D., Zhang, L., Yu, H., & Wan, F. (2022). Review of question answering technology based on Text-to-SQL. Proceedings of the IEEE International Conference on Computer Science Education and Informatization (CSEI) (pp. 167–172). IEEE.

OpenAI. (2022). Introducing ChatGPT. https://openai.com/index/chatgpt

OpenAI. (2023). Creating a GPT. https://help.openai.com/en/articles/8554397-creating-a-gpt

Pornphol, P., & Chittayasothorn, S. (2023). Verification of relational database languages codes generated by ChatGPT. In Y. Watanobe, G. Mogos & M. Rahman (Eds.), Proceedings of the 4th Asia Service Science and Software Engineering Conference (ASSE) (pp. 17–22). ACM.

Pornphol, P., & Chittayasothorn, S. (2024). Using LLM artificial intelligence systems as complex SQL programming assistants. In S. Yamaguchi & N. Funabiki (Eds.), Proceedings of the 12th International Conference on Information and Education Technology (ICIET) (pp. 187–190). IEEE.

Shen, H., Sun, G., Wang, Y., Shen, R., Li, Y., & Zhang, P. (2023). Sequential feature augmentation for robust Text-to-SQL. In L. Trinh (Ed.), Proceedings of the International Conference on Algorithms, Computing and Data Processing (ACDP) (pp. 217–221). IEEE.

Srisuruk, T., & Chittayasothorn, S. (2023). An approach for rapid source code development based on ChatGPT and prompt engineering. IEEE Access, 12, 53074–53087. https://doi.org/10.1109/ACCESS.2024.3385682

Downloads

Published

2026-08-19

How to Cite

Dangkham, P., & Wannasawaskul, W. (2026). A Text-to-SQL System Based on ChatGPT . EAU Heritage Journal Science and Technology (online), 20(2), 174–186. retrieved from https://he01.tci-thaijo.org/index.php/EAUHJSci/article/view/284279

Issue

Section

Research Articles