Skip to content
Snippets Groups Projects
Commit 2885cf84 authored by Mergen Imeev's avatar Mergen Imeev Committed by Kirill Yukhin
Browse files

sql: ANSI aliases for LENGTH()

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.
parent 31a26448
No related branches found
No related tags found
No related merge requests found
......@@ -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),
......
#!/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()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment