Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: Roman Khabibov <roman.habibov@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH v3 1/2] sql: use unify pattern for column names
Date: Mon, 29 Jun 2020 22:08:39 +0200	[thread overview]
Message-ID: <b73befda-b7f4-5e6c-beb3-2af17b839397@tarantool.org> (raw)
In-Reply-To: <E2127215-5EF3-4315-9A05-262D3AC83783@tarantool.org>

Hi! Thanks for the patch!

> In my patch, I used the zName field of the struct ExprList_item,
> which is also used for aliases. But I did not find words in the
> code that this field is only for aliases (<AS> clause), therefore
> I considered it legitimate to put auto names in it.
> 
> PostgreSQL would throw an error in the case above: "ambiguous names”.
> But it works for us. Is it a bug or not? Perhaps yes. In any case,
> this does not apply to the patch and requires a separate discussion,
> so I just delete this test.

I wouldn't consider it a bug. And it is totally not related to this
patchset. So I would leave it as is now.

Please, don't delete any tests unless they are duplicate, or useless.

See 2 comments below.

> commit ed196a4446177eb14aa1b86a382c32416edb5794
> Author: Roman Khabibov <roman.habibov@tarantool.org>
> Date:   Thu Mar 5 12:48:58 2020 +0300
> 
>     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 COLLATE "unicode_ci" FROM test;

1. In my only comment to the previous patch I asked not to use
COLLATE for numbers, and make the example more representative.
Here if I remove 'COLLATE "unicode_ci"', the result won't change.
That makes the example close to useless.

Please, reconsider my comment from the previous email.

>     ---
>     - metadata:
>       - name: COLUMN_1
>         type: scalar
>       - name: COLUMN_1
>         type: scalar
>       rows:
>       - [1, 1]
>     ...
>     ```
> 
> diff --git a/test/sql-tap/colname.test.lua b/test/sql-tap/colname.test.lua
> index caa61a07a..f27ffe413 100755
> --- a/test/sql-tap/colname.test.lua
> +++ b/test/sql-tap/colname.test.lua
> @@ -635,4 +635,133 @@ test:do_catchsql_test(> +
> +test:do_execsql2_test(
> +    "colname-12.14",
> +    [[
> +        CREATE TABLE j_1 (column_1 SCALAR PRIMARY KEY, column_2 SCALAR);
> +        INSERT INTO j_1 VALUES(1, 1);
> +    ]], {})
> +
> +test:do_execsql2_test(
> +    "colname-12.15",
> +    [[
> +        SELECT column_1, column_1 COLLATE "unicode_ci", column_2, 1 FROM j_1;
> +    ]], {
> +        "COLUMN_1",1,"COLUMN_1",1,"COLUMN_2",1,"COLUMN_2",1

2. Ditto.

> +    })
> +

  reply	other threads:[~2020-06-29 20:08 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-11 15:18 [Tarantool-patches] [PATCH v3 0/2] Use-unify-pattern-for-column-names Roman Khabibov
2020-06-11 15:18 ` [Tarantool-patches] [PATCH v3 1/2] sql: use unify pattern for column names Roman Khabibov
2020-06-15 21:59   ` Vladislav Shpilevoy
2020-06-22 21:14     ` roman
2020-06-23 23:12       ` Vladislav Shpilevoy
2020-06-25 14:35         ` Roman Khabibov
2020-06-25 21:25           ` Vladislav Shpilevoy
2020-06-27 11:50             ` Roman Khabibov
2020-06-29 20:08               ` Vladislav Shpilevoy [this message]
2020-06-29 23:46                 ` Roman Khabibov
2020-06-30 21:23                   ` Vladislav Shpilevoy
2020-07-01 12:45                     ` Roman Khabibov
2020-07-01 21:25                       ` Vladislav Shpilevoy
2020-07-02 15:55                         ` Roman Khabibov
2020-06-11 15:18 ` [Tarantool-patches] [PATCH v3 2/2] sql: print span more properly Roman Khabibov
2020-06-15 22:18   ` Vladislav Shpilevoy
2020-06-22 21:14     ` roman
2020-06-23 23:12       ` Vladislav Shpilevoy
2020-07-02 15:55         ` Roman Khabibov
2020-07-02 19:06           ` Nikita Pettik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b73befda-b7f4-5e6c-beb3-2af17b839397@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=roman.habibov@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v3 1/2] sql: use unify pattern for column names' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox