sql: introduce operator []
This patch introduces operator [] that allows to get elements from MAP and ARRAY values. Closes #4762 Closes #4763 Part of #6251 @TarantoolBot document Title: Operator [] in SQL Operator `[]` allows to get an element of MAP and ARRAY values. Examples: ``` tarantool> box.execute([[SELECT [1, 2, 3, 4, 5][3];]]) --- - metadata: - name: COLUMN_1 type: any rows: - [3] ... tarantool> box.execute([[SELECT {'a' : 123, 7: 'asd'}['a'];]]) --- - metadata: - name: COLUMN_1 type: any rows: - [123] ... ``` The returned values is of type ANY. If the operator is applied to a value that is not a MAP or ARRAY or is NULL, an error is thrown. Example: ``` tarantool> box.execute([[SELECT 1[1];]]) --- - null - Selecting is only possible from map and array values ... ``` However, if there are two or more operators next to each other, the second or following operators do not throw an error, but instead return NULL. Example: ``` tarantool> box.execute([[select [1][1][2][3][4];]]) --- - metadata: - name: COLUMN_1 type: any rows: - [null] ... ```
Showing
- changelogs/unreleased/gh-6251-operator-brackets.md 3 additions, 0 deletionschangelogs/unreleased/gh-6251-operator-brackets.md
- extra/addopcodes.sh 1 addition, 0 deletionsextra/addopcodes.sh
- src/box/sql/expr.c 43 additions, 0 deletionssrc/box/sql/expr.c
- src/box/sql/mem.c 59 additions, 0 deletionssrc/box/sql/mem.c
- src/box/sql/mem.h 17 additions, 0 deletionssrc/box/sql/mem.h
- src/box/sql/parse.y 27 additions, 0 deletionssrc/box/sql/parse.y
- src/box/sql/vdbe.c 29 additions, 0 deletionssrc/box/sql/vdbe.c
- test/sql-luatest/containers_test.lua 134 additions, 0 deletionstest/sql-luatest/containers_test.lua
Loading