Skip to content
Snippets Groups Projects
Commit 814befe8 authored by Mergen Imeev's avatar Mergen Imeev Committed by Kirill Yukhin
Browse files

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]
...
```
parent 5bcc785f
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment