PATSQL: Efficient Synthesis of SQL Queries from Example Tables with Quick Inference of Projected Columns
Abstract
SQL is one of the most popular tools for data analysis, and it is now used by an increasing number of users without having expertise in databases. Several studies have proposed programming-by-example approaches to help such non-experts to write correct SQL queries. While existing methods support a variety of SQL features such as aggregation and nested query, they suffer a significant increase in computational cost as the scale of example tables increases. In this paper, we propose an efficient algorithm utilizing properties known in relational algebra to synthesize SQL queries from input and output tables. Our key insight is that a projection operator in a program sketch can be lifted above other operators by applying transformation rules in relational algebra, while preserving the semantics of the program. This enables a quick inference of appropriate columns in the projection operator, which is an essential component in synthesis but causes combinatorial explosions in prior work. We also introduce a novel form of constraints and its top-down propagation mechanism for efficient sketch completion. We implemented this algorithm in our tool PATSQL and evaluated it on 226 queries from prior benchmarks and Kaggle's tutorials. As a result, PATSQL solved 68% of the benchmarks and found 89% of the solutions within a second. Our tool is available at https://naist-se.github.io/patsql/ .
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
8 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
No credit card required.
Lineage
- Relational Query Synthesis ⋈ Decision Tree Learning cites Synthesizing analytical SQL queries from computation demonstration
- Automated Translation of Functional Big Data Queries to SQL cites Data Migration using Datalog Program Synthesis
Cited by top-tier papersTop 5 of 8 by citations
- Auto-Tables: Synthesizing Multi-Step Transformations to Relationalize Tables without Using ExamplesPeng Li, Yeye He, Cong Yan, Yue Wang et al.VLDB 2023 · 29 citations
- EQUI-VOCAL: Synthesizing Queries for Compositional Video Events from Limited User InteractionsEnhao Zhang, Maureen Daum, Dong He, Brandon Haynes et al.VLDB 2023 · 18 citations
- Synthesizing analytical SQL queries from computation demonstrationXiangyu Zhou, Rastislav Bodík, Alvin Cheung, Chenglong WangPLDI 2022 · 11 citations
- Automated Translation of Functional Big Data Queries to SQLGuoqiang Zhang, Benjamin Mariano, Xipeng Shen, Isil DilligOOPSLA 2023 · 5 citations
- Relational Query Synthesis ⋈ Decision Tree LearningAaditya Naik, Aalok Thakkar, Adam Stein, Rajeev Alur et al.VLDB 2024 · 2 citations
Builds on2
Related papers
- Example-guided synthesis of relational queriesAalok Thakkar, Aaditya Naik, Nathaniel Sands, Rajeev Alur et al.PLDI 2021 · 12 citations
- Pi-SQL: Enhancing Text-to-SQL with Fine-Grained Guidance from Pivot Programming LanguagesYongdong Chi, Hanqing Wang, Yun Chen, Yan Yang et al.EMNLP Findings 2025
- Guardrail: Automated Integrity Constraint Synthesis From Noisy DataPingchuan Ma, Zhaoyu Wang, Zhenlan Ji, Zongjie Li et al.SIGMOD 2026 · 1 citation
- SchemaRAG: A Schema-aware Retrieval-Augmented Generation Framework for Text-to-SQLDi Wu, Zetong Tang, Yi He, Xin LuoSIGMOD 2026 · 9 citations
- Visualization by exampleChenglong Wang, Yu Feng, Rastislav Bodík, Alvin Cheung et al.POPL 2020 · 36 citations
