Skip to content

Commit 1fd8aa6

Browse files
committed
Fixes gh-1410 Column naming in SQL
1 parent ce2e9ca commit 1fd8aa6

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

doc/reference/reference_sql/sql_beginners_guide.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -607,11 +607,11 @@ The result will look like this:
607607

608608
.. code-block:: none
609609
610-
+--------------+-----------+-----------+-----------+-------------+
611-
| AVG(size) | SUM(size) | MIN(size) | MAX(size) | COUNT(size) |
612-
+--------------+-----------+-----------+-----------+-------------|
613-
| 5.413333E+02 | 1624 | 4 | 1432 | 3 |
614-
+--------------+-----------+-----------+-----------+-------------+
610+
+--------------+-----------+-----------+-----------+-----------+
611+
| COLUMN_1 | COLUMN_2 | COLUMN_3 | COLUMN_4 | COLUMN_5 |
612+
+--------------+-----------+-----------+-----------+-----------|
613+
| 5.413333E+02 | 1624 | 4 | 1432 | 3 |
614+
+--------------+-----------+-----------+-----------+-----------+
615615
616616
Suppose that we want aggregations, but aggregations of rows that have some common characteristic.
617617
Supposing further, we want to divide the rows into two groups, the ones whose names
@@ -628,12 +628,12 @@ The result will look like this:
628628

629629
.. code-block:: none
630630
631-
+--------------------+--------------+-----------+-----------+-----------+-------------+
632-
| SUBSTR(name, 1, 1) | AVG(size) | SUM(size) | MIN(size) | MAX(size) | CoUNT(size) |
633-
+--------------------+--------------+-----------+-----------+-----------|-------------|
634-
| b | 1432 | 1432 | 1432 | 1432 | 1 |
635-
| c | 96 | 192 | 4 | 188 | 2 |
636-
+--------------------+--------------+-----------+-----------+-----------|-------------+
631+
+------------+--------------+-----------+-----------+-----------+-------------+
632+
| COLUMN_1 | COLUMN_2 | COLUMN_3 | COLUMN_4 | COLUMN_5 | COLUMN_6 |
633+
+------------+--------------+-----------+-----------+-----------|-------------|
634+
| b | 1432 | 1432 | 1432 | 1432 | 1 |
635+
| c | 96 | 192 | 4 | 188 | 2 |
636+
+------------+--------------+-----------+-----------+-----------|-------------+
637637
638638
639639
**Select with common table expression**

doc/reference/reference_sql/sql_statements_and_clauses.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,10 +1813,16 @@ The column name is useful for two reasons:
18131813
then
18141814
the column names in the new table will be the column names in the *select list*.
18151815

1816-
If ``[[AS] column-name]`` is missing, Tarantool makes a name equal to the
1817-
expression, for example ``SELECT 5 * 88`` will cause the column name to be
1818-
``5 * 88``, but such names may be ambiguous or illegal in other contexts,
1819-
so it is better to say, for example, ``SELECT 5 * 88 AS column1``.
1816+
If ``[[AS] column-name]`` is missing, and the expression is not simply
1817+
the name of a column in the table, then Tarantool makes a name
1818+
:samp:`COLUMN_{n}` where :samp:`{n}` is the number of the non-simple
1819+
expression within the select list, for example
1820+
``SELECT 5.88, table1.x, 'b' COLLATE "unicode_ci" FROM table1;``
1821+
will cause the column names to be COLUMN_1, X, COLUMN_2.
1822+
This is a behavior change in Tarantool 2.6, in earlier versions
1823+
the name would be equal to the expression,
1824+
see `Issue#3962 <https://github.com/tarantool/tarantool/issues/3962>`_.
1825+
It is still legal to define tables with column names like ``COLUMN_1`` but not recommended.
18201826

18211827
Examples:
18221828

@@ -1833,10 +1839,6 @@ Examples:
18331839
-- as a list:
18341840
SELECT 1 AS a, 2 AS b, table1.* FROM table1;
18351841
1836-
Limitations: (`Issue#3962 <https://github.com/tarantool/tarantool/issues/3962>`_) |br|
1837-
* Names for expressions will change in a future version.
1838-
1839-
18401842
.. _sql_from:
18411843

18421844
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

doc/reference/reference_sql/sql_user_guide.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ The bottom of the screen should now look like this:
5151
tarantool> box.execute([[VALUES ('hello');]])
5252
---
5353
- metadata:
54-
- name: column1
54+
- name: COLUMN_1
5555
type: string
5656
rows:
5757
- ['hello']

0 commit comments

Comments
 (0)