[tarantool-patches] Re: [PATCH 6/6] sql: discard numeric conversion by unary plus

n.pettik korablev at tarantool.org
Fri Oct 12 14:19:13 MSK 2018


> On 27 Sep 2018, at 23:24, Vladislav Shpilevoy <v.shpilevoy at tarantool.org> wrote:
> 
> See 1 comment below.
> 
> On 17/09/2018 23:32, Nikita Pettik wrote:
>> In SQLite unary plus behaves as implicit conversion to numeric type.
>> Consider following example:
>> CREATE TABLE t1 (id INT PRIMARY KEY, a TEXT, b BLOB);
>> INSERT INTO t1 VALUES (1, '99', '99');
>> SELECT * FROM t1 WHERE a = b; (*)
>> SELECT * FROM t1 WHERE +a = +b; (**)
>> Since BLOB and TEXT are incompatible, result of (*) would be empty set.
>> However, comparison in second query (**) would be of <NUMERIC> types,
>> and result set would consist of one tuple [1, '99', '99'].
>> Lets discard this conversion produced by unary plus, since it implicitly
>> affects result set of query and no one other DB support such behaviour.
>> Instead, simply use type of operand it is related to.
> 
> So unary minus is ok?

Yep, unary minus doesn’t affect types.
You can check it modifying example from commit message:

CREATE TABLE t1 (id INT PRIMARY KEY, a TEXT, b BLOB);
INSERT INTO t1 VALUES (1, '99', '99');
SELECT * FROM t1 WHERE a = b;
SELECT * FROM t1 WHERE -a = -b;

Result is the same.
Also, for the sake of clarity, added note to commit message
concerning this case:
...

    Lets discard this conversion produced by unary plus, since it implicitly
    affects result set of query and no one other DB support such behaviour.
    Instead, simply use type of operand it is related to.
    Note, that unary minus doesn't affect types in any way.



More information about the Tarantool-patches mailing list