[tarantool-patches] [PATCH 2/2] sql: make default type of NULL be boolean

Nikita Pettik korablev at tarantool.org
Sat Jul 27 21:45:36 MSK 2019


It was decided that null value in SQL by default should be of type
boolean. Justification of such change is that according to ANSI boolean
type in fact has three different values: true, false and unknown. The
latter is basically an alias to null value.
---
 src/box/sql/func.c          |  3 ++-
 test/sql-tap/cast.test.lua  |  4 ++--
 test/sql-tap/func.test.lua  | 12 ++++++------
 test/sql-tap/table.test.lua |  2 +-
 test/sql/types.result       |  2 +-
 5 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index f50df105d..06904e082 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -133,10 +133,11 @@ typeofFunc(sql_context * context, int NotUsed, sql_value ** argv)
 		z = "scalar";
 		break;
 	case MP_BOOL:
+	case MP_NIL:
 		z = "boolean";
 		break;
 	default:
-		z = "null";
+		unreachable();
 		break;
 	}
 	sql_result_text(context, z, -1, SQL_STATIC);
diff --git a/test/sql-tap/cast.test.lua b/test/sql-tap/cast.test.lua
index f06cc81d6..96162639c 100755
--- a/test/sql-tap/cast.test.lua
+++ b/test/sql-tap/cast.test.lua
@@ -120,7 +120,7 @@ test:do_execsql_test(
         SELECT typeof(NULL)
     ]], {
         -- <cast-1.12>
-        "null"
+        "boolean"
         -- </cast-1.12>
     })
 
@@ -180,7 +180,7 @@ test:do_execsql_test(
         SELECT typeof(CAST(NULL AS SCALAR))
     ]], {
         -- <cast-1.18>
-        "null"
+        "boolean"
         -- </cast-1.18>
     })
 
diff --git a/test/sql-tap/func.test.lua b/test/sql-tap/func.test.lua
index 961fd350a..09407d3fa 100755
--- a/test/sql-tap/func.test.lua
+++ b/test/sql-tap/func.test.lua
@@ -1802,7 +1802,7 @@ test:do_execsql_test(
         SELECT typeof(replace('This is the main test string', NULL, 'ALT'));
     ]], {
         -- <func-21.3>
-        "null"
+        "boolean"
         -- </func-21.3>
     })
 
@@ -1812,7 +1812,7 @@ test:do_execsql_test(
         SELECT typeof(replace(NULL, 'main', 'ALT'));
     ]], {
         -- <func-21.4>
-        "null"
+        "boolean"
         -- </func-21.4>
     })
 
@@ -1822,7 +1822,7 @@ test:do_execsql_test(
         SELECT typeof(replace('This is the main test string', 'main', NULL));
     ]], {
         -- <func-21.5>
-        "null"
+        "boolean"
         -- </func-21.5>
     })
 
@@ -2043,7 +2043,7 @@ test:do_execsql_test(
         SELECT typeof(trim(NULL));
     ]], {
         -- <func-22.20>
-        "null"
+        "boolean"
         -- </func-22.20>
     })
 
@@ -2053,7 +2053,7 @@ test:do_execsql_test(
         SELECT typeof(TRIM('xyz' FROM NULL));
     ]], {
         -- <func-22.21>
-        "null"
+        "boolean"
         -- </func-22.21>
     })
 
@@ -2063,7 +2063,7 @@ test:do_execsql_test(
         SELECT typeof(TRIM(NULL FROM 'hello'));
     ]], {
         -- <func-22.22>
-        "null"
+        "boolean"
         -- </func-22.22>
     })
 
diff --git a/test/sql-tap/table.test.lua b/test/sql-tap/table.test.lua
index 7f4b15e72..18adf70a9 100755
--- a/test/sql-tap/table.test.lua
+++ b/test/sql-tap/table.test.lua
@@ -906,7 +906,7 @@ test:do_execsql_test(
         FROM t7 LIMIT 1;
     ]], {
         -- <table-11.1>
-        "integer", "number", "string", "string", "null", "null", "string", "string"
+        "integer", "number", "string", "string", "boolean", "boolean", "string", "string"
         -- </table-11.1>
     })
 
diff --git a/test/sql/types.result b/test/sql/types.result
index 6e7fffa42..3750ed2a3 100644
--- a/test/sql/types.result
+++ b/test/sql/types.result
@@ -1771,7 +1771,7 @@ box.execute("SELECT typeof(a), typeof(s) FROM t;")
     type: string
   rows:
   - ['integer', 'integer']
-  - ['integer', 'null']
+  - ['integer', 'boolean']
 ...
 box.execute("SELECT typeof(CAST(0 AS UNSIGNED));")
 ---
-- 
2.15.1





More information about the Tarantool-patches mailing list