[tarantool-patches] [PATCH 1/2] sql: add STRING alias to TEXT type

Nikita Pettik korablev at tarantool.org
Tue Jul 30 02:34:10 MSK 2019


TEXT type is called "string" in the original Tarantool NoSQL, so it would
be rational to allow using the same type name in SQL.
---
 extra/mkkeywordhash.c   |  1 +
 src/box/sql/parse.y     |  1 +
 test/sql/types.result   | 13 +++++++++++++
 test/sql/types.test.lua |  6 ++++++
 4 files changed, 21 insertions(+)

diff --git a/extra/mkkeywordhash.c b/extra/mkkeywordhash.c
index 64a5bbfc6..a353d4781 100644
--- a/extra/mkkeywordhash.c
+++ b/extra/mkkeywordhash.c
@@ -176,6 +176,7 @@ static Keyword aKeywordTable[] = {
   { "SET",                    "TK_SET",         ALWAYS,           true  },
   { "SIMPLE",                 "TK_SIMPLE",      ALWAYS,           true  },
   { "START",                  "TK_START",       ALWAYS,           true  },
+  { "STRING",                 "TK_STRING_KW",   ALWAYS,           true  },
   { "TABLE",                  "TK_TABLE",       ALWAYS,           true  },
   { "THEN",                   "TK_THEN",        ALWAYS,           true  },
   { "TO",                     "TK_TO",          ALWAYS,           true  },
diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
index d4e1ec859..3929ed9c6 100644
--- a/src/box/sql/parse.y
+++ b/src/box/sql/parse.y
@@ -1725,6 +1725,7 @@ wqlist(A) ::= wqlist(A) COMMA nm(X) eidlist_opt(Y) AS LP select(Z) RP. {
 ////////////////////////////// TYPE DECLARATION ///////////////////////////////
 %type typedef {struct type_def}
 typedef(A) ::= TEXT . { A.type = FIELD_TYPE_STRING; }
+typedef(A) ::= STRING_KW . { A.type = FIELD_TYPE_STRING; }
 typedef(A) ::= SCALAR . { A.type = FIELD_TYPE_SCALAR; }
 /** BOOL | BOOLEAN is not used due to possible bug in Lemon. */
 typedef(A) ::= BOOL . { A.type = FIELD_TYPE_BOOLEAN; }
diff --git a/test/sql/types.result b/test/sql/types.result
index 4589b2d58..0dc90d5a4 100644
--- a/test/sql/types.result
+++ b/test/sql/types.result
@@ -1751,3 +1751,16 @@ box.execute("SELECT CAST('-123' AS UNSIGNED);")
 box.space.T1:drop()
 ---
 ...
+-- Check that STRING is a valid alias to TEXT type.
+--
+box.execute("CREATE TABLE t (id STRING PRIMARY KEY);")
+---
+- row_count: 1
+...
+box.space.T:format()[1].type
+---
+- string
+...
+box.space.T:drop()
+---
+...
diff --git a/test/sql/types.test.lua b/test/sql/types.test.lua
index f07a90b37..06de8c977 100644
--- a/test/sql/types.test.lua
+++ b/test/sql/types.test.lua
@@ -399,3 +399,9 @@ box.execute("SELECT CAST('123' AS UNSIGNED);")
 box.execute("SELECT CAST('-123' AS UNSIGNED);")
 
 box.space.T1:drop()
+
+-- Check that STRING is a valid alias to TEXT type.
+--
+box.execute("CREATE TABLE t (id STRING PRIMARY KEY);")
+box.space.T:format()[1].type
+box.space.T:drop()
-- 
2.15.1





More information about the Tarantool-patches mailing list