sql: fix implicit cast from STRING to INTEGER
Prior to this patch, STRING, which contains the DOUBLE value, could be implicitly cast to INTEGER. This was done by converting STRING to DOUBLE and then converting this DOUBLE value to INTEGER. This may affect the accuracy of CAST(), so it was forbidden. It is worth noting that these changes will not affect the comparison, since the implicit cast in this case has different mechanics. Example: box.execute("CREATE TABLE t(i INT PRIMARY KEY);") Before patch: box.execute("INSERT INTO t VALUES ('111.1');") box.execute("SELECT * FROM t;") Result: 111 After patch: box.execute("INSERT INTO t VALUES ('1.1');") Result: 'Type mismatch: can not convert 1.1 to integer' box.execute("INSERT INTO t VALUES ('1.0');") Result: 'Type mismatch: can not convert 1.0 to integer' box.execute("INSERT INTO t VALUES ('1.');") Result: 'Type mismatch: can not convert 1. to integer' @TarantoolBot document Title: disallow cast from STRING contains DOUBLE to INTEGER After the last two patches, explicit and implicit casting from the string containing DOUBLE to INTEGER directly will be prohibited. The user must use the explicit cast to DOUBLE before the explicit or implicit cast to INTEGER. The reason for this is that before these patches, such STRINGs were implicitly cast to DOUBLE, and then this DOUBLE was implicitly or explicitly cast to INTEGER. Because of this, the result of such a cast may differ from what the user expects, and the user may not know why. It is worth noting that these changes will not affect the comparison, since the implicit cast in this case has different mechanics. Example for implicit cast: box.execute("CREATE TABLE t(i INT PRIMARY KEY);") -- Does not work anymore: box.execute("INSERT INTO t VALUES ('1.1');") -- Right way: box.execute("INSERT INTO t VALUES (CAST('1.1' AS DOUBLE));") Example for explicit cast: -- Does not work anymore: box.execute("SELECT CAST('1.1' AS INTEGER);") -- Right way: box.execute("SELECT CAST(CAST('1.1' AS DOUBLE) AS INTEGER);")
Showing
- src/box/sql/vdbe.c 9 additions, 2 deletionssrc/box/sql/vdbe.c
- src/box/sql/vdbeInt.h 0 additions, 1 deletionsrc/box/sql/vdbeInt.h
- src/box/sql/vdbemem.c 0 additions, 29 deletionssrc/box/sql/vdbemem.c
- test/sql-tap/e_select1.test.lua 1 addition, 1 deletiontest/sql-tap/e_select1.test.lua
- test/sql-tap/intpkey.test.lua 1 addition, 1 deletiontest/sql-tap/intpkey.test.lua
- test/sql-tap/join.test.lua 2 additions, 2 deletionstest/sql-tap/join.test.lua
- test/sql-tap/subquery.test.lua 3 additions, 3 deletionstest/sql-tap/subquery.test.lua
- test/sql-tap/tkt-9a8b09f8e6.test.lua 2 additions, 2 deletionstest/sql-tap/tkt-9a8b09f8e6.test.lua
Loading
Please register or sign in to comment