From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id C03874696C0 for ; Thu, 5 Dec 2019 14:51:21 +0300 (MSK) Date: Thu, 5 Dec 2019 14:51:21 +0300 From: Nikita Pettik Message-ID: <20191205115121.GA4490@tarantool.org> References: <8652d840-2b81-9e49-eb5a-1133673b11bf@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <8652d840-2b81-9e49-eb5a-1133673b11bf@tarantool.org> Subject: Re: [Tarantool-patches] [PATCH 6/6] sql: extend result set with alias List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org On 28 Nov 23:41, Vladislav Shpilevoy wrote: > Thanks for the patch! > > On 27/11/2019 13:15, Nikita Pettik wrote: > > Each column of result set can feature its name alias. For instance: > > > > SELECT x + 1 AS add FROM ...; > > > > In this case real name of resulting set column is "x + 1" meanwhile > > "add" is its alias. This patch extends metadata with optional metadata > > member which corresponds to column's alias. > > I was always thinking that the alias should be returned as a > name. And the real name should be returned as meta. And looks > like it is so: > > tarantool> box.execute('SELECT 1 AS kek') > --- > - metadata: > - name: KEK > type: integer > rows: > - [1] > ... > > That makes me think we should not break it. And > meta should return the real name in case there is > an alias. Because otherwise the aliases are useless > in meta. (ANSI parts which concern Java and CLI are quite complicated to read and understand, so I refer to Oracle docs). https://docs.oracle.com/javase/8/docs/api/java/sql/ResultSetMetaData.html#getColumnLabel-int- 'The suggested title is usually specified by the SQL AS clause.' https://stackoverflow.com/questions/4271152/getcolumnlabel-vs-getcolumnname I assume that :getColumnLabel() returns name of label, not real name (at least it seems to be rational). > Btw the example above is executed on this commit. So > now the results are inconsistent. Some queries return > alias in 'name'. Some return a real name in 'name'. I > think we should keep it as was, and return alias in > 'name'. Sorry, now it is fixed: - metadata: - type: integer name: '1' alias: KEK rows: - [1] ... I've extended commit message with doc bot request: sql: extend result set with alias Each column of result set can feature its name alias. For instance: SELECT x + 1 AS add FROM ...; In this case real name of resulting set column is "x + 1" meanwhile "add" is its alias. This patch extends metadata with optional metadata member which corresponds to column's alias. Closes #4407 @TarantoolBot document Title: extended SQL metadata Before this patch metadata for SQL DQL contained only two fields: name and type of each column of result set. Now it may contain following properties: - collation (in case type of resulting set column is string and collation is different from default "none"); is encoded with IPROTO_FIELD_COLL key in IPROTO_METADATA map; - is_nullable (in case column of result set corresponds to space's field; for expressions like x+1 for the sake of simplicity nullability is omitted); is encoded with IPROTO_FIELD_IS_NULLABLE key in IPROTO_METADATA; - is_autoincrement (is set only for autoincrement column in result set); is encoded with IPROTO_FIELD_IS_AUNTOINCREMENT key in IPROTO_METADATA; - alias (if column of result set is specified with AS label); is encoded with IPROTO_FIELD_ALIAS key in IPROTO_METADATA map.