Skip to content
Snippets Groups Projects
Commit 7bfcf57e authored by Roman Khabibov's avatar Roman Khabibov Committed by Nikita Pettik
Browse files

sql: unify pattern for column names

Name resulting columns generated by an expression or <VALUES>
construction by the "COLUMN_N" pattern.

Closes #3962

@TarantoolBot document
Title: Column naming in SQL

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 <VALUES>
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 <ORDER BY> 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]
...
```
parent c2d8c03e
No related branches found
No related tags found
No related merge requests found
Showing
with 531 additions and 352 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment