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] ... ```
Showing
- src/box/sql/select.c 47 additions, 23 deletionssrc/box/sql/select.c
- src/box/sql/sqlInt.h 15 additions, 0 deletionssrc/box/sql/sqlInt.h
- test/box/function1.result 6 additions, 6 deletionstest/box/function1.result
- test/sql-tap/colname.test.lua 157 additions, 4 deletionstest/sql-tap/colname.test.lua
- test/sql-tap/select1.test.lua 11 additions, 10 deletionstest/sql-tap/select1.test.lua
- test/sql-tap/select6.test.lua 11 additions, 11 deletionstest/sql-tap/select6.test.lua
- test/sql-tap/view.test.lua 2 additions, 2 deletionstest/sql-tap/view.test.lua
- test/sql/bind.result 21 additions, 21 deletionstest/sql/bind.result
- test/sql/boolean.result 177 additions, 177 deletionstest/sql/boolean.result
- test/sql/collation.result 7 additions, 7 deletionstest/sql/collation.result
- test/sql/errinj.result 1 addition, 1 deletiontest/sql/errinj.result
- test/sql/foreign-keys.result 2 additions, 2 deletionstest/sql/foreign-keys.result
- test/sql/full_metadata.result 5 additions, 5 deletionstest/sql/full_metadata.result
- test/sql/func-recreate.result 1 addition, 1 deletiontest/sql/func-recreate.result
- test/sql/gh-3199-no-mem-leaks.result 12 additions, 12 deletionstest/sql/gh-3199-no-mem-leaks.result
- test/sql/gh-3888-values-blob-assert.result 4 additions, 4 deletionstest/sql/gh-3888-values-blob-assert.result
- test/sql/gh-4697-scalar-bool-sort-cmp.result 2 additions, 2 deletionstest/sql/gh-4697-scalar-bool-sort-cmp.result
- test/sql/icu-upper-lower.result 34 additions, 48 deletionstest/sql/icu-upper-lower.result
- test/sql/integer-overflow.result 7 additions, 7 deletionstest/sql/integer-overflow.result
- test/sql/iproto.result 9 additions, 9 deletionstest/sql/iproto.result
Loading
Please register or sign in to comment