Elucidating Type Conversions in SQL Engines
Open Access
- 1 May 2025
- book chapter
- Published by Springer Nature
- p. 408-435
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 understand this problem, we present a formal typing semantics for SQL, named $$\textsf{TRAF} $$ , that explicitly captures both static and dynamic type behavior. The system $$\textsf{TRAF} $$ is expressed in terms of abstract operators that provide the necessary leeway to precisely model different SQL engines (PostgreSQL, MS SQL Server, MySQL, SQLite, and Oracle). We show that this formalism provides formal guarantees regarding the handling of types. We provide practical conditions on engines to prove type safety and soundness of queries. In this regard, $$\textsf{TRAF} $$ can serve as precise documentation of typing in existing engines and potentially guide their evolution, as well as provide a formal basis to study type-aware query optimizations, and design provably-correct query translators. Additionally, we test the adequacy of the formalism, implementing $$\textsf{TRAF} $$ in Python for these five engines, and tested them with thousands of randomly-generated queries.
Keywords
This publication has 25 references indexed in Scilit:
- 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
- Strong types for relational databases2006
- 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
- Formal semantics of SQL queriesACM Transactions on Database Systems, 1991
- Correcting user errors in SQLInternational Journal of Man-Machine Studies, 1985
- Translating SQL Into Relational Algebra: Optimization, Semantics, and Equivalence of SQL QueriesIEEE Transactions on Software Engineering, 1985