[tarantool-patches] [PATCH v2 1/1] sql: ANSI aliases for LENGTH()
imeevma at tarantool.org
imeevma at tarantool.org
Sat Jul 6 13:46:03 MSK 2019
This patch creates aliases CHARACTER_LENGTH() and CHAR_LENGTH()
for LENGTH(). These functions are added because they are described
in ANSI.
Closes #3929
@TarantoolBot document
Title: SQL functions CHAR_LENGTH() and CHARACTER_LENGTH()
The SQL functions CHAR_LENGTH() and CHARACTER_LENGTH() work the
same as the LENGTH() function. They take exactly one argument. If
an argument of type TEXT or can be cast to a TEXT value using
internal casting rules, these functions return the length of the
TEXT value that represents the argument. They throw an error if
the argument cannot be cast to a TEXT value.
---
https://github.com/tarantool/tarantool/issues/3929
https://github.com/tarantool/tarantool/tree/imeevma/gh-3929-character-length-functions
src/box/sql/func.c | 3 +++
test/sql-tap/func3.test.lua | 23 ++++++++++++++++++++++-
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 761a3ab..98cad51 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -1893,6 +1893,9 @@ sqlRegisterBuiltinFunctions(void)
FIELD_TYPE_STRING),
FUNCTION2(length, 1, 0, 0, lengthFunc, SQL_FUNC_LENGTH,
FIELD_TYPE_INTEGER),
+ FUNCTION(char_length, 1, 0, 0, lengthFunc, FIELD_TYPE_INTEGER),
+ FUNCTION(character_length, 1, 0, 0, lengthFunc,
+ FIELD_TYPE_INTEGER),
FUNCTION(position, 2, 0, 1, position_func, FIELD_TYPE_INTEGER),
FUNCTION(printf, -1, 0, 0, printfFunc, FIELD_TYPE_STRING),
FUNCTION(unicode, 1, 0, 0, unicodeFunc, FIELD_TYPE_STRING),
diff --git a/test/sql-tap/func3.test.lua b/test/sql-tap/func3.test.lua
index 6d6411c..2d0579d 100755
--- a/test/sql-tap/func3.test.lua
+++ b/test/sql-tap/func3.test.lua
@@ -1,6 +1,6 @@
#!/usr/bin/env tarantool
test = require("sqltester")
-test:plan(25)
+test:plan(35)
--!./tcltestrunner.lua
-- 2010 August 27
@@ -285,5 +285,26 @@ test:do_test(
end, test:execsql "EXPLAIN SELECT min(1.0+'2.0',4*11)")
+--
+-- gh-3929: sql: ANSI aliases for LENGTH().
+--
+suits = {}
+suits[1] = {str = '123456789', len = 9}
+suits[2] = {str = '\x80', len = 1}
+suits[3] = {str = '\x61\x62\x63', len = 3}
+suits[4] = {str = '\x7f\x80\x81', len = 3}
+suits[5] = {str = '\x61\xc0', len = 2}
+suits[6] = {str = '\x61\xc0\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80', len = 12}
+suits[7] = {str = '\xc0\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80', len = 11}
+suits[8] = {str = '\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80', len = 10}
+suits[9] = {str = '\x80\x80\x80\x80\x80\xf0\x80\x80\x80\x80', len = 7}
+suits[10] = {str = '\x80\x80\x80\x80\x80\xf0\x80\x80\x80\xff', len = 7}
+
+for k,v in pairs(suits) do
+ test:do_execsql_test(
+ "func3-6."..k,
+ "SELECT CHAR_LENGTH('"..v.str.."'), CHARACTER_LENGTH('"..v.str.."');",
+ {v.len, v.len})
+end
test:finish_test()
--
2.7.4
More information about the Tarantool-patches
mailing list