[Tarantool-patches] [PATCH v1 04/21] sql: refactor LENGTH() function

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Sat Oct 30 02:42:49 MSK 2021


>>> diff --git a/src/box/sql/func.c b/src/box/sql/func.c
>>> index e5d763be1..863dbf1c4 100644
>>> --- a/src/box/sql/func.c
>>> +++ b/src/box/sql/func.c
>>> @@ -833,6 +833,19 @@ func_hex(struct sql_context *ctx, int argc, struct Mem *argv)
>>>  	mem_set_str_allocated(ctx->pOut, str, size);
>>>  }
>>>  
>>> +/** Implementation of the OCTET_LENGTH() function. */
>>> +static void
>>> +func_octet_length(struct sql_context *ctx, int argc, struct Mem *argv)
>>
>> Why is the function LENGTH defined as 'octet_length' instead of just 'length'?
> ANSI defines two functions: CHAR_LENGTH() (with CHARACTER_LENGTH() as the other
> name) and OCTET_LENGTH(). The first accepts only STRING values and returns the
> length in characters or length in octets (depending on the USING clause). The
> second accepts VARBINARY or STRING and returns the length in octets.
> 
> We have a LENGTH() function that returns the character length if the argument is
> STRING, and the octet length if the argument is VARBINARY.
> 
> Since I am planning to introduce the USING clause, I find it better to use the
> CHAR_LENGTH() and OCTET_LENGTH() implementations for LENGTH() depending on the
> type of the argument. The func_octet_length() function will be used cases such
> as this:
> SELECT char_length(string_value USING OCTETS);
> 
> At the moment, I have no plans to introduce OCTET_LENGTH().

Does ANSI define 'USING' or 'OCTET_LENGTH'? Or both?


More information about the Tarantool-patches mailing list