A Formal Framework for Typing and Cast Semantics in SQL Engines
Open Access
- 28 July 2026
- journal article
- Published by Association for Computing Machinery (ACM) in ACM Transactions on Programming Languages and Systems
Abstract
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.Keywords
This publication has 28 references indexed in Scilit:
- Elucidating Type Conversions in SQL Engines2025
- A Formalization of SQL with NullsJournal of Automated Reasoning, 2022
- Error messages in relational database management systems: A comparison of effectiveness, usefulness, and user confidenceJournal of Systems and Software, 2021
- JDBC checker: a static analysis tool for SQL/JDBC applications2004
- Polymorphic Type Inference for the Relational AlgebraJournal of Computer and System Sciences, 2002
- User errors in database query compositionInternational Journal of Human-Computer Studies, 1995
- Comprehending monadsMathematical Structures in Computer Science, 1992
- Many-Valued Logics1992
- Formal semantics of SQL queriesACM Transactions on Database Systems, 1991
- Correcting user errors in SQLInternational Journal of Man-Machine Studies, 1985