Skip to content

Fixes gh-2206 Behavior changes in SQL #2350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/reference/reference_sql/data_type.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ stack (
choice(
line(' BOOL '),
line(' BOOLEAN '),
line(' DECIMAL '),
line(' DOUBLE '),
line(' INT '),
line(' INTEGER '),
Expand Down
259 changes: 133 additions & 126 deletions doc/reference/reference_sql/data_type.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions doc/reference/reference_sql/sql-features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ marked "Okay" will probably be balanced by tests which are unfairly marked "Fail
| | | | columns (created from Lua) from FLOAT/DOUBLE/REAL ones |
| | | | (created from SQL). |
+------------+-----------------------------------------------+----------------------------------------------------------+---------------------------------------------------------+
| E011-03 | DECIMAL and NUMERIC data types | ``CREATE TABLE td (s1 NUMERIC PRIMARY KEY);`` | Fail, DECIMAL and NUMERIC data types are not supported |
| E011-03 | DECIMAL and NUMERIC data types | ``CREATE TABLE td (s1 NUMERIC PRIMARY KEY);`` | Fail, NUMERIC data types are not supported |
| | | | and a number containing post-decimal digits will be |
| | | | treated as approximate numeric. |
+------------+-----------------------------------------------+----------------------------------------------------------+---------------------------------------------------------+
Expand Down Expand Up @@ -308,9 +308,9 @@ marked "Okay" will probably be balanced by tests which are unfairly marked "Fail
| F031-03 | GRANT statement | | Fail. Tarantool doesn't support privileges except |
| | | | via NoSQL. |
+------------+-----------------------------------------------+----------------------------------------------------------+---------------------------------------------------------+
| F031-04 | ALTER TABLE statement: add column | ``ALTER TABLE t7 ADD COLUMN t7_2 VARCHAR DEFAULT 'q';`` | Fail. Tarantool supports |
| | | | :ref:`ALTER TABLE <sql_alter_table>` but not |
| | | | this clause. |
| F031-04 | ALTER TABLE statement: add column | ``ALTER TABLE t7 ADD COLUMN t7_2 VARCHAR(1) | Okay. Tarantool supports |
| | | DEFAULT 'q';`` | :ref:`ALTER TABLE <sql_alter_table>` and support for |
| | | | ADD COLUMN was added in Tarantool version 2.7. |
+------------+-----------------------------------------------+----------------------------------------------------------+---------------------------------------------------------+
| F031-13 | DROP TABLE statement: RESTRICT clause | ``DROP TABLE t20 RESTRICT;`` | Fail. Tarantool supports |
| | | | :ref:`DROP TABLE <sql_drop_table>` but not this |
Expand Down Expand Up @@ -448,9 +448,9 @@ marked "Okay" will probably be balanced by tests which are unfairly marked "Fail
| | | | name (not counted in the final score). |
+------------+-----------------------------------------------+----------------------------------------------------------+---------------------------------------------------------+

Total number of items marked "Fail": 68
Total number of items marked "Fail": 67

Total number of items marked "Okay": 78
Total number of items marked "Okay": 79



62 changes: 31 additions & 31 deletions doc/reference/reference_sql/sql_beginners_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ we prefer to pick out specific items by their contents. In that spirit, this is

.. code-block:: none

modules
MODULES

+-----------------+------+---------------------+
| name | size | purpose |
+-----------------|------|---------------------|
| NAME | SIZE | PURPOSE |
+-----------------+------+---------------------+
| box | 1432 | Database Management |
| clock | 188 | Seconds |
| crypto | 4 | Cryptography |
Expand Down Expand Up @@ -165,8 +165,8 @@ A primary-key column automatically has a UNIQUE index.

data domain -- if a column is defined as having data type INTEGER, it is illegal to put a non-number into it.
More generally, if a value doesn't correspond to the data type of the definition, it is illegal.
However, some database management systems (DBMSs) are very forgiving and will try to
make allowances for bad values rather than reject them; Tarantool is one of those DBMSs.
Some database management systems (DBMSs) are very forgiving and will try to
make allowances for bad values rather than reject them; Tarantool is a bit more strict than those DBMSs.

Now, here are other types of constraints ...

Expand Down Expand Up @@ -216,7 +216,7 @@ By default searches in Tarantool's SQL use a binary collation. This will work:
``INSERT INTO submodules`` |br|
|nbsp| |nbsp| ``VALUES ('space', 'box', 10000, 'insert etc.');``

Now try to delete the new row from the modules table:
Now try to delete the corresponding row from the modules table:

``DELETE FROM modules WHERE name = 'box';``

Expand Down Expand Up @@ -352,9 +352,9 @@ but displayed as a table the result will look like
.. code-block:: none

+----------------+------------------------+
| double_size | concatenated_literals |
| DOUBLE_SIZE | CONCATENATED_LITERALS |
+----------------+------------------------+
| 8| XY |
| 8 | XY |
+----------------+------------------------+

**Selecting with a select list with asterisk**
Expand Down Expand Up @@ -411,7 +411,7 @@ The result will look like this:
.. code-block:: none

+-------------------+------------------------+--------------------+
| submodules_name | modules_purpose | submodules_purpose |
| SUBMODULES_NAME | MODULES_PURPOSE | SUBMODULES_PURPOSE |
+-------------------+------------------------+--------------------+
| space | Database Management | insert etc. |
+-------------------+------------------------+--------------------+
Expand All @@ -437,11 +437,11 @@ That is legal. Usually it is not what you want, but it is a learning aid. The re

{ columns from modules table } { columns from submodules table }
+--------+------+---------------------+-------+-------------+-------+-------------+
| name | size | purpose | name | module_name | size | purpose |
| NAME | SIZE | PURPOSE | NAME | MODULE_NAME | SIZE | PURPOSE |
+--------+------+---------------------+-------+-------------+-------+-------------+
| box | 1432 | Database Management | space | box | 10000 | insert etc. |
| clock | 188 | Seconds | space | box | 10000 | insert etc. |
| crypto | 4 | Cryptography | space | box | 10000 | insert etc. |
| clock | 188 | Seconds | space | box | 10000 | insert etc. |
| crypto | 4 | Cryptography | space | box | 10000 | insert etc. |
+--------+------+---------------------+-------+-------------+-------+-------------+

It is not an error. The meaning of this type of join is "combine every row in table-1 with every row in table-2".
Expand Down Expand Up @@ -469,12 +469,12 @@ The result will be:
.. code-block:: none

+----------+-----------+------------+--------+---------+-------+-------------+
| modules_ | modules_ | modules_ | name | module_ | size | purpose |
| name | size | purpose | | name | | |
+----------+-----------+--------- --+--------+---------+-------+-------------|
| box | 1432 | Database | space | box | 10000 | insert etc. |
| MODULES_ | MODULES_ | MODULES_ | NAME | MODULE_ | SIZE | PURPOSE |
| NAME | SIZE | PURPOSE | | NAME | | |
+----------+-----------+--------- --+--------+---------+-------+-------------+
| box | 1432 | Database | space | box | 10000 | insert etc. |
| | | Management | | | | |
+----------+-----------+------------+--------+---------+-------+-------------|
+----------+-----------+------------+--------+---------+-------+-------------+

In other words, you can specify a Cartesian join in the FROM clause,
then you can filter out the irrelevant rows in the WHERE clause,
Expand Down Expand Up @@ -556,11 +556,11 @@ which returns:

{ columns from modules table } { columns from submodules table }
+--------+------+---------------------+-------+-------------+-------+-------------+
| name | size | purpose | name | module_name | size | purpose |
| NAME | SIZE | PURPOSE | NAME | MODULE_NAME | SIZE | PURPOSE |
+--------+------+---------------------+-------+-------------+-------+-------------+
| box | 1432 | Database Management | space | box | 10000 | insert etc. |
| clock | 188 | Seconds | NULL | NULL | NULL | NULL |
| crypto | 4 | Cryptography | NULL | NULL | NULL | NULL |
| clock | 188 | Seconds | NULL | NULL | NULL | NULL |
| crypto | 4 | Cryptography | NULL | NULL | NULL | NULL |
+--------+------+---------------------+-------+-------------+-------+-------------+

Thus, for the submodules of the clock module and the submodules of the crypto
Expand All @@ -585,11 +585,11 @@ Remember that our modules table looks like this:

.. code-block:: none

modules
MODULES

+-----------------+------+---------------------+
| name | size | purpose |
+-----------------|------|---------------------|
| NAME | SIZE | PURPOSE |
+-----------------+------+---------------------+
| box | 1432 | Database Management |
| clock | 188 | Seconds |
| crypto | 4 | Cryptography |
Expand All @@ -598,7 +598,7 @@ Remember that our modules table looks like this:

Suppose that we do not want to know all the individual size values,
we just want to know about their aggregation, that is, take the attributes of the collection.
SQL allows five aggregation functions: AVG (average), SUM, MIN (minimum), MAX (maximum), and COUNT.
SQL allows aggregation functions including: AVG (average), SUM, MIN (minimum), MAX (maximum), and COUNT.
For example

``SELECT AVG(size), SUM(size), MIN(size), MAX(size), COUNT(size) FROM modules;``
Expand All @@ -607,11 +607,11 @@ The result will look like this:

.. code-block:: none

+--------------+-----------+-----------+-----------+-----------+
| COLUMN_1 | COLUMN_2 | COLUMN_3 | COLUMN_4 | COLUMN_5 |
+--------------+-----------+-----------+-----------+-----------|
| 5.413333E+02 | 1624 | 4 | 1432 | 3 |
+--------------+-----------+-----------+-----------+-----------+
+-----------+-----------+-----------+-----------+-----------+
| COLUMN_1 | COLUMN_2 | COLUMN_3 | COLUMN_4 | COLUMN_5 |
+-----------+-----------+-----------+-----------+-----------|
| 541 | 1624 | 4 | 1432 | 3 |
+-----------+-----------+-----------+-----------+-----------+

Suppose that we want aggregations, but aggregations of rows that have some common characteristic.
Supposing further, we want to divide the rows into two groups, the ones whose names
Expand All @@ -630,10 +630,10 @@ The result will look like this:

+------------+--------------+-----------+-----------+-----------+-------------+
| COLUMN_1 | COLUMN_2 | COLUMN_3 | COLUMN_4 | COLUMN_5 | COLUMN_6 |
+------------+--------------+-----------+-----------+-----------|-------------|
+------------+--------------+-----------+-----------+-----------+-------------+
| b | 1432 | 1432 | 1432 | 1432 | 1 |
| c | 96 | 192 | 4 | 188 | 2 |
+------------+--------------+-----------+-----------+-----------|-------------+
+------------+--------------+-----------+-----------+-----------+-------------+


**Select with common table expression**
Expand Down
3 changes: 2 additions & 1 deletion doc/reference/reference_sql/sql_plus_lua.rst
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ If there were no Lua functions, we would have to treat it as a VARBINARY
and look for ``POSITION(X'A476696577C3',"flags") > 0`` (A4 is a MsgPack signal
that a 4-byte string follows, 76696577 is UTF8 encoding for 'view',
C3 is a MsgPack code meaning true).
In any case, starting with Tarantool version 2.10, POSITION() does not work on VARBINARY operands.
But we have a more sophisticated way, we can create a function that
returns true if ``"flags".view`` is true.
So our way of making the function looks like this:
Expand Down Expand Up @@ -634,7 +635,7 @@ _COLUMNS view
********************************************************************************

This is also an example of how one can use :ref:`recursive views <sql_with>` to make temporary tables
with multiple rows for each tuple in the original ``"_vtable"`` space.
with multiple rows for each tuple in the original ``"_vspace"`` space.
It requires a global variable, _G.box.FORMATS, as a temporary static variable.

Warning: Use this code only with Tarantool version 2.3.2 or later.
Expand Down
Loading