@@ -169,7 +169,7 @@ but for readability one would usually use spaces to separate tokens: |br|
169
169
Literals
170
170
********************************************************************************
171
171
172
- There are eight kinds of literals: BOOLEAN INTEGER DOUBLE DECIMAL STRING VARBINARY ARRAY MAP.
172
+ There are eight kinds of literals: BOOLEAN INTEGER DOUBLE DECIMAL STRING VARBINARY MAP ARRAY .
173
173
174
174
BOOLEAN literals: |br |
175
175
TRUE | FALSE | UNKNOWN |br |
@@ -221,27 +221,20 @@ Example: ``X'414243'``, which will be displayed as ``'ABC'``. |br|
221
221
A literal has :ref: `data type = VARBINARY <sql_data_type_varbinary >`
222
222
("variable-length binary") if it is the letter X followed by quotes containing pairs of hexadecimal digits, representing byte values.
223
223
224
- ARRAY expressions: |br |
225
- [left square bracket] [comma-separated list of values] [right square bracket] |br |
226
- Examples: ``[1,2,3,4] ``, ``[1,[2,3],4] ``, ``X['a','22',uuid()] `` |br |
227
- An expression has data type = ARRAY if it is a sequence of zero or more values
228
- enclosed in square brackets (``[ `` and ``] ``).
229
- Values may be of any type; values may be expressions; arrays may be nested.
230
- In formal terms we should say that ``[ `` and ``] `` are actually "operators"
231
- and the values are "elements", but most of the examples we have used are in
232
- fact arrays of literals.
233
-
234
- MAP expressions: |br |
235
- [left curly bracket] key [colon] value [right curly bracket] |br |
236
- Examples: ``{'a':1} ``, ``{ "column_1" : X'1234' } `` |br |
237
- An expression has data type = MAP if it is enclosed in curly brackets
238
- (also called braces) ``{ `` and ``} `` and contains a key for identification,
239
- then a colon ``: ``, then a value for what the key identifies.
240
- As with ARRAY expressions, the ``{ `` and ``} `` are actually operators
241
- so the key and the value are not necessarily literals themselves.
242
- It is not uncommon to have an array of maps, for example
243
- ``[{'a':1},{'b':2}] ``, which can be called an associative array and can
244
- be converted to a `Lua table <https://www.lua.org/pil/2.5.html >`_.
224
+ MAP literals: |br |
225
+ [left curly bracket] key [colon] value [right square bracket] |br |
226
+ Examples: ``{'a':1} ``, ``{1:'a'} `` |br |
227
+ A map literal a pair of curly brackets (also called "braces")
228
+ enclosing a STRING or INTEGER or UUID literal (called the map "key")
229
+ followed by a colon
230
+ followed by any type of literal (called the map "value").
231
+ This is a minimal form of a :ref: `MAP expression <sql_map_expression >`.
232
+
233
+ ARRAY literals: |br |
234
+ [left square bracket] [literal] [right square bracket] |br |
235
+ Examples: ``[1] ``, ``['a'] `` |br |
236
+ An ARRAY literal is a literal value which is enclosed inside square brackets.
237
+ This is a minimal form of an :ref: `ARRAY expression <sql_array_expression >`.
245
238
246
239
Here are four ways to put non-ASCII characters,such as the Greek letter α alpha, in string literals: |br |
247
240
First make sure that your shell program is set to accept characters as UTF-8. A simple way to check is |br |
@@ -495,10 +488,12 @@ and minimum / maximum literal examples.
495
488
+-----------+------------+------------+----------------------+-------------------------+
496
489
| SCALAR | (varies) | (none) | FALSE | maximum UUID value |
497
490
+-----------+------------+------------+----------------------+-------------------------+
498
- | ARRAY | array | (none) | [] | ``many values `` |
499
- +-----------+------------+------------+----------------------+-------------------------+
500
491
| MAP | map | (none) | ``{'':''} `` | ``big-key:big-value `` |
501
492
+-----------+------------+------------+----------------------+-------------------------+
493
+ | ARRAY | array | (none) | [] | ``[many values] `` |
494
+ +-----------+------------+------------+----------------------+-------------------------+
495
+ | ANY | any | (none) | FALSE | ``[many values] `` |
496
+ +-----------+------------+------------+----------------------+-------------------------+
502
497
503
498
504
499
.. _sql_data_type_boolean :
@@ -589,27 +584,33 @@ Prior to Tarantool version 2.10.1, individual column values had
589
584
one of the preceding types -- BOOLEAN, INTEGER, DOUBLE, DECIMAL, STRING, VARBINARY, or UUID.
590
585
Starting in Tarantool version 2.10.1, all values have type SCALAR.
591
586
592
- .. _ sql_data_type_array :
587
+ .. _ sql_data_type_map :
593
588
594
- ARRAY values are lists of values of any type, including other ARRAY values
595
- -- that is, arrays can be "nested". Tarantool does
596
- not require that all values in an array must have the same type.
597
- Arrays cannot be used in arithmetic or comparison (except `` IS [NOT] NULL ``), and the only
589
+ MAP values are key:value combinations which can be produced with
590
+ :ref: ` MAP expressions < sql_map_expression >`.
591
+ Maps cannot be used in arithmetic or comparison (except `` IS [NOT] NULL ``),
592
+ and the only
598
593
functions where they are allowed are :ref: `CAST <sql_function_cast >`,
599
594
:ref: `QUOTE <sql_function_quote >`,
600
595
:ref: `TYPEOF <sql_function_typeof >`, and functions involving NULL comparisons.
601
596
602
- .. _ sql_data_type_map :
597
+ .. _ sql_data_type_array :
603
598
604
- MAP values are key:value combinations which can be produced with expressions
605
- like ``LUA('return {a=1}') ``, although the SQL literal will look more like
606
- ``{'a':1} ``.
607
- Maps cannot be used in arithmetic or comparison (except ``IS [NOT] NULL ``),
608
- and the only
599
+ ARRAY values are lists which can be produced with
600
+ :ref: `ARRAY expressions <sql_array_expression >`.
601
+ Arrays cannot be used in arithmetic or comparison (except ``IS [NOT] NULL ``), and the only
609
602
functions where they are allowed are :ref: `CAST <sql_function_cast >`,
610
603
:ref: `QUOTE <sql_function_quote >`,
611
604
:ref: `TYPEOF <sql_function_typeof >`, and functions involving NULL comparisons.
612
605
606
+ .. _sql_data_type_any :
607
+
608
+ ANY can be used for
609
+ :ref: `column definitions <sql_column_def_data_type >` and the individual column values have
610
+ type ANY.
611
+ The difference between SCALAR and ANY is:
612
+ SCALAR columns may not contain MAP or ARRAY values, but ANY columns may contain them.
613
+
613
614
Any value of any data type may be NULL. Ordinarily NULL will be cast to the
614
615
data type of any operand it is being compared to or to the data type of the
615
616
column it is in. If the data type of NULL cannot be determined from context,
@@ -865,6 +866,40 @@ value IS [NOT] NULL |br|
865
866
CASE ... WHEN ... THEN ... ELSE ... END |br |
866
867
... for setting a series of conditions.
867
868
869
+ .. _sql_map_expression :
870
+
871
+ { key : value } |br |
872
+ ... for MAP expressions. |br |
873
+ Literal Examples: ``{'a':1} ``, ``{ "column_1" : X'1234' } `` |br |
874
+ Non-literal Examples: ``{"a":"a"} ``, ``{UUID(), (SELECT 1) + 1} `` |br |
875
+ An expression has data type = MAP if it is enclosed in curly brackets
876
+ (also called braces) ``{ `` and ``} `` and contains a key for identification,
877
+ then a colon ``: ``, then a value for what the key identifies.
878
+ The key data type must be INTEGER or STRING or UUID.
879
+ The value data type may be anything.
880
+ The Lua equivalent type is 'map' but the syntax is slightly different,
881
+ for example the SQL value ``{'a': 1} `` is represented in Lua as ``{a = 1} ``.
882
+
883
+ .. _sql_array_expression :
884
+
885
+ [ value ... ] |br |
886
+ ... for ARRAY expressions. |br |
887
+ Examples: ``[1,2,3,4] ``, ``[1,[2,3],4] ``, ``['a', "column_1", uuid()] `` |br |
888
+ An expression has data type = ARRAY if it is a sequence of zero or more values
889
+ enclosed in square brackets (``[ `` and ``] ``).
890
+ Often the values in the sequence are called "elements".
891
+ The element data type may be anything, including ARRAY -- that is, ARRAYs may be nested.
892
+ Different elements may have different types.
893
+ The Lua equivalent type is `'array' <https://www.lua.org/pil/11.1.html >`_.
894
+
895
+ .. _sql_array_index_expression :
896
+
897
+ ARRAY index expression: |br |
898
+ array-value [square bracket] index [square bracket] |br |
899
+ Example: ``['a', 'b', 'c'] [2] `` (this equals 'b') |br |
900
+ As in other languages, an element of an array can be referenced with an
901
+ integer inside square brackets.
902
+
868
903
See also: :ref: `subquery <sql_subquery >`.
869
904
870
905
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
0 commit comments