[Tarantool-discussions] Check implicit cast between strings and numbers

Peter Gulutzan pgulutzan at ocelot.ca
Wed Jul 8 21:58:40 MSK 2020


Hi,

On 2020-07-08 10:58 a.m., Mergen Imeev wrote:
 > Hi,
 >
 > Thank you for testing! I added check types of arguments of the
 > functions, could you look once more?
 >
 > There are some functions in which we support both STRING and BLOB
 > as arguments, for example substr(). Do you think we should leave
 > them as they are now, or can we change them so that they support
 > only STRING arguments?
<cut>

I think those functions are
SELECT HEX('Г'), HEX(CAST('Г' AS VARBINARY));
SELECT LENGTH('Г'), LENGTH(CAST('Г' AS VARBINARY));
SELECT LOWER('Г'), LOWER(CAST('Г' AS VARBINARY));
SELECT POSITION('1', 'Г1'), POSITION('1', CAST('Г1' AS VARBINARY));
SELECT PRINTF('%s', 'Г'), PRINTF('%s', CAST('Г' AS VARBINARY));
SELECT QUOTE('Г'), QUOTE(CAST('Г' AS VARBINARY));
SELECT REPLACE('1Г1','1','2'), REPLACE(CAST('1Г1' AS VARBINARY),'1','2');
SELECT SOUNDEX('Г'), SOUNDEX(CAST('Г' AS VARBINARY));
SELECT SUBSTR('1Г1',2,1), SUBSTR(CAST('1Г1' AS VARBINARY),2,1);
SELECT TRIM(TRAILING '1' FROM '1Г1'), TRIM(TRAILING '1' FROM CAST('1Г1' 
AS VARBINARY));
SELECT UNICODE('Г'), UNICODE(CAST('Г' AS VARBINARY));
SELECT UPPER('Г'), UPPER(CAST('Г' AS VARBINARY));

They all work now.
I think that is good, we should leave them as they are now.

That does not mean they are all perfect, though.
Here are complaints, which are not relevant to
your question but which we should look at someday.

As you can see in the comments on issue#4145
sql: remake string value functions
https://github.com/tarantool/tarantool/issues/4145
sometimes functions with multiple parameters can
have multiple data types.

As you can see from the comments on issue#3929
Length functions for SQL character strings
https://github.com/tarantool/tarantool/issues/3929
As you know, I objected to the idea that CHARACTER_LENGTH()
should be applied to VARBINARY values, but
it was a firm order from Konstantin Osipov.

If we accepted that these functions should look
for bytes (rather than characters) when the values
are VARBINARY, then some of the results would differ.


Peter Gulutzan



More information about the Tarantool-discussions mailing list