Skip to content

Commit 7167b7f

Browse files
committed
Fixes gh-1409 change implicit cast for assignment
1 parent bd352ee commit 7167b7f

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

doc/reference/reference_sql/sql.rst

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@ although it may exist in data created by Tarantool's NoSQL. In SQL, -nan is trea
15841584

15851585
A string will be converted to a number if it is used with an arithmetic operator and conversion is possible,
15861586
for example ``'7' + '7'`` = 14.
1587-
And for comparison or assignment, ``'7'`` = 7.
1587+
And for comparison, ``'7'`` = 7.
15881588
This is called implicit casting. It is applicable for STRINGs and all numeric data types.
15891589

15901590
Limitations: (`Issue#2346 <https://github.com/tarantool/tarantool/issues/2346>`_) |br|
@@ -1685,8 +1685,8 @@ The specific situations in this chart follow the general rules:
16851685
~ To BOOLEAN | To number | To STRING | To VARBINARY
16861686
--------------- ---------- ---------- --------- ------------
16871687
From BOOLEAN | AAA | S-- | A-- | ---
1688-
From number | A-- | SSA | AAA | ---
1689-
From STRING | S-- | SSS | AAA | A--
1688+
From number | A-- | SSA | A-A | ---
1689+
From STRING | S-- | S-S | AAA | A--
16901690
From VARBINARY | --- | --- | A-- | AAA
16911691
16921692
Where each entry in the chart has 3 characters: |br|
@@ -1728,6 +1728,12 @@ The result is TRUE.
17281728
column is AAA and the third letter of AAA is for implicit cast (comparison) and A means Always Allowed.
17291729
The result is TRUE. For detailed explanation see the following section.
17301730

1731+
``CAST('5' AS INTEGER)`` is legal because the intersection of the "From STRING" row with the "To number"
1732+
column is S-S and the first letter of S-S is for explicit cast and S means Sometimes Allowed.
1733+
However, ``CAST('5.5' AS INTEGER)`` is illegal because 5.5 is not an integer --
1734+
if the string contains post-decimal digits and the target is INTEGER or UNSIGNED,
1735+
the assignment will fail.
1736+
17311737
Implicit string/numeric cast
17321738

17331739
Special considerations may apply for casting STRINGs
@@ -1743,15 +1749,11 @@ Therefore ``1e400 < ''`` is TRUE. |br|
17431749
Exception: for BETWEEN the cast is to the data type of the first and last operands. |br|
17441750
Therefore ``'66' BETWEEN 5 AND '7'`` is TRUE.
17451751

1746-
For assignments, the cast is always from source to target.
1747-
Therefore ``INSERT INTO t (integer_column) VALUES ('5');`` inserts 5. |br|
1748-
If the cast fails, then the result is an error.
1749-
Due to a change in behavior starting with Tarantool 2.4.1,
1750-
if the string contains post-decimal digits and the target is INTEGER or UNSIGNED,
1751-
the assignment will fail.
1752-
Therefore ``INSERT INTO t (integer_column) VALUES ('5.5');`` causes an error. |br|
1752+
For assignments, due to a change in behavior starting with Tarantool 2.5.1,
1753+
implicit casts from strings to numbers are not legal. Therefore
1754+
``INSERT INTO t (integer_column) VALUES ('5');`` is an error.
17531755

1754-
Implicit cast also happens if STRINGS are used in arithmetic. |br|
1756+
Implicit cast does happen if STRINGS are used in arithmetic. |br|
17551757
Therefore ``'5' / '5' = 1``. If the cast fails, then the result is an error. |br|
17561758
Therefore ``'5' / ''`` is an error.
17571759

@@ -4787,7 +4789,7 @@ and returns:
47874789
- row_count: 1
47884790
...
47894791
4790-
It is functionally the same thing as an :ref:`UPDATE statement:
4792+
It is functionally the same thing as an :ref:`UPDATE Statement <sql_update>`:
47914793

47924794
.. code-block:: none
47934795

0 commit comments

Comments
 (0)