Skip to Main content Skip to Navigation
Preprints, Working Papers, ...

Handling SQL Nulls with Two-Valued Logic

Abstract : The design of SQL is based on a three-valued logic (3VL), rather than the familiar Boolean logic with truth values true and false, to accommodate the additional truth value unknown for handling nulls. It is viewed as indispensable for SQL expressiveness, but is at the same time much criticized for leading to unintuitive behavior of queries and thus being a source of programmer mistakes. We show that, contrary to the widely held view, SQL could have been designed based on the standard Boolean logic, without any loss of expressiveness and without giving up nulls. The approach itself follows SQL’s evaluation which only retains tuples for which conditions in the WHERE clause evaluate to true. We show that conflating unknown, resulting from nulls, with false leads to an equally expressive version of SQL that does not use the third truth value. Queries written under the two-valued semantics can be efficiently translated into the standard SQL and thus executed on any existing RDBMS. These results cover the core of the SQL 1999 Standard, including SELECT-FROM-WHERE-GROUP BY-HAVING queries extended with subqueries and IN/EXISTS/ANY/ALL conditions, and recursive queries. We provide two extensions of this result showing that no other way of converting 3VL into Boolean logic, nor any other many-valued logic for treating nulls could have possibly led to a more expressive language. These results not only present small modifications of SQL that eliminate the source of many programmer errors without the need to reimplement database internals, but they also strongly suggest that new query languages for various data models do not have to follow the much criticized SQL’s three-valued approach.
Document type :
Preprints, Working Papers, ...
Complete list of metadatas
Contributor : Liat Peterfreund <>
Submitted on : Friday, January 8, 2021 - 4:36:23 PM
Last modification on : Sunday, January 10, 2021 - 3:24:11 AM


Files produced by the author(s)


  • HAL Id : hal-03104130, version 1



Leonid Libkin, Liat Peterfreund. Handling SQL Nulls with Two-Valued Logic. 2021. ⟨hal-03104130⟩



Record views


Files downloads