sql: introduce DOUBLE type
This patch introduces type DOUBLE in SQL. Closes #3812 Needed for #4233 @TarantoolBot document Title: Tarantool DOUBLE field type and DOUBLE type in SQL The DOUBLE field type was added to Tarantool mainly for adding the DOUBLE type to SQL. Values of this type are stored as MP_DOUBLE in msgpack. The size of the encoded value is always 9 bytes. In Lua, only non-integer numbers and CDATA of type DOUBLE can be inserted in this field. You cannot insert integers of type Lua NUMBER or CDATA of type int64 or uint64 in this field. The same rules apply to key in get(), select(), update() and upsert() methods. It was done this way to avoid unwanted implicit casts that could affect performance. It is important to note that you can use the ffi.cast() function to cast numbers to CDATA of type DOUBLE. An example of this can be seen below. Another very important point is that CDATA of type DOUBLE in lua can be used in arithmetic, but arithmetic for them does not work correctly. This comes from LuaJIT and most likely will not be fixed. Example of usage in Lua: s = box.schema.space.create('s', {format = {{'d', 'double'}}}) _ = s:create_index('ii') s:insert({1.1}) ffi = require('ffi') s:insert({ffi.cast('double', 1)}) s:insert({ffi.cast('double', tonumber('123'))}) s:select(1.1) s:select({ffi.cast('double', 1)}) In SQL, DOUBLE type behavior is different due to implicit casting. In a column of type DOUBLE, the number of any supported type can be inserted. However, it is possible that the number that will be inserted will be different from that which is inserted due to the rules for casting to DOUBLE. In addition, after this patch, all floating point literals will be recognized as DOUBLE. Prior to that, they were considered as NUMBER. Example of usage in SQL: box.execute('CREATE TABLE t (d DOUBLE PRIMARY KEY);') box.execute('INSERT INTO t VALUES (10), (-2.0), (3.3);') box.execute('SELECT * FROM t;') box.execute('SELECT d / 100 FROM t;') box.execute('SELECT * from t WHERE d < 15;') box.execute('SELECT * from t WHERE d = 3.3;')
Showing
- extra/mkkeywordhash.c 1 addition, 1 deletionextra/mkkeywordhash.c
- src/box/sql/expr.c 4 additions, 2 deletionssrc/box/sql/expr.c
- src/box/sql/parse.y 2 additions, 1 deletionsrc/box/sql/parse.y
- src/box/sql/sqlInt.h 2 additions, 1 deletionsrc/box/sql/sqlInt.h
- src/box/sql/vdbe.c 4 additions, 0 deletionssrc/box/sql/vdbe.c
- src/box/sql/vdbemem.c 1 addition, 14 deletionssrc/box/sql/vdbemem.c
- test/sql/gh-3888-values-blob-assert.result 2 additions, 2 deletionstest/sql/gh-3888-values-blob-assert.result
- test/sql/misc.result 2 additions, 2 deletionstest/sql/misc.result
- test/sql/types.result 389 additions, 1 deletiontest/sql/types.result
- test/sql/types.test.lua 66 additions, 0 deletionstest/sql/types.test.lua
Loading
Please register or sign in to comment