A Formal Framework for Typing and Cast Semantics in SQL Engines
Practical SQL engines differ in subtle ways in their handling of typing constraints and implicit type casts. These issues, usually not considered in formal accounts of SQL, directly affect the portability of queries between engines. To address this problem, we present a formal typing semantics for SQL, named TRAF , that explicitly captures both static and dynamic type behavior. The system TRAF is expressed in terms of abstract operators that provide the necessary leeway to systematically model the type and cast behavior of different SQL engines (PostgreSQL, MS SQL Server, MySQL, SQLite, and Oracle). We show that this formalism provides formal guarantees for the handling of types. We identify practical conditions under which engine instantiations satisfy type safety and type soundness. In this regard, TRAF can serve as an explicit and testable account of typing in existing engines, potentially guide their evolution, and provide a formal basis to study type-aware query optimizations and design provably-correct query translators. We also test the adequacy of the formalism by implementing TRAF in Python for these five engines and testing it with synthetic queries, SQLancer++- generated queries, and adapted Spider and Calcite benchmark queries.
Authors
- Wenjia Ye (ORCID: https://orcid.org/0000-0002-3968-6201)
- Claudio Gutiérrez (ORCID: https://orcid.org/0000-0002-4559-6544)
- Bruno C. d. S. Oliveira (ORCID: https://orcid.org/0000-0002-1846-7210)
- Matías Toro (ORCID: https://orcid.org/0000-0002-5315-0198)
- Éric Tanter (ORCID: https://orcid.org/0000-0002-7359-890X)
Institutions
- University of the West of England (GB)
- Fundación Chile (CL)
- University of Bristol (GB)
- University of Chile (CL)
- University of Hong Kong (HK)
Publication Details
- Journal
- ACM Transactions on Programming Languages and Systems
- Published
- 2026-07-28
- DOI
- https://doi.org/10.1145/3834861
- Primary Topic
- Advanced Database Systems and Queries
- Type
- article
- Field-Weighted Citation Impact
- 0.00