Closed
Description
Now, every auto generated column is named by the "COLUMN_N"
pattern, where N is the number of generated column in a query
(starting from 1). Auto generated column is a column in a query
result generated by an expression or a column from
construction.
Examples:
box.execute("VALUES(1, 2, 3);")
---
- metadata:
- name: COLUMN_1
type: integer
- name: COLUMN_2
type: integer
- name: COLUMN_3
type: integer
rows:
- [1, 2, 3]
...
box.execute("SELECT * FROM (VALUES (1+1, 1+1));")
---
- metadata:
- name: COLUMN_1
type: integer
- name: COLUMN_2
type: integer
rows:
- [2, 2]
...
box.execute("SELECT 1+1, 1+1;")
---
- metadata:
- name: COLUMN_1
type: integer
- name: COLUMN_2
type: integer
rows:
- [2, 2]
...
Here, the expression "mycol + 1" generates a new column, so that
it is the first auto generated resulting column will be named as
"COLUMN_1".
tarantool> CREATE TABLE test (mycol INT PRIMARY KEY);
---
- row_count: 1
...
tarantool> SELECT mycol, mycol + 1 FROM test;
---
- metadata:
- name: MYCOL
type: integer
- name: COLUMN_1
type: integer
rows: []
...
Note that you can use generated names already within the query,
e.g. in clause.
tarantool> SELECT mycol, mycol + 1 FROM test ORDER BY column_1;
---
- metadata:
- name: MYCOL
type: integer
- name: COLUMN_1
type: integer
rows: []
...
It should also be noted that if you use column names similar to
the "COLUMN_N" pattern, you can get the same names as a result:
tarantool> CREATE TABLE test (column_1 SCALAR PRIMARY KEY);
---
- row_count: 1
...
tarantool> INSERT INTO test VALUES(1);
---
- row_count: 1
...
tarantool> SELECT column_1, column_1 + 1 FROM test;
---
- metadata:
- name: COLUMN_1
type: scalar
- name: COLUMN_1
type: scalar
rows:
- [1, 2]
...
Requested by @romanhabibov in tarantool/tarantool@7bfcf57.