Giter Site home page Giter Site logo

rsmdtest's Introduction

ResultSetMetaData接口测试

表和视图定义

create table table0(t0c0 int, t0c1 int, t0c2 int);
create view view0(v0c0, v0c1, v0c2) as select t0c0, t0c1, t0c2 from table0;

查询语句

/* without alias*/
select * from view0;
/* with alias*/
select v0c0 as alias_v0c0, v0c1 as alias_v0c1, v0c2 as alias_v0c2 from view0;

在MySQL上的结果

ResultSetMetaData.getColumnName返回某一列在视图中定义的名字,而ResultSetMetaData.getColumnLabel返回查询时赋予的别名。

8.0.23-0ubuntu0.20.10.1
SELECT WITHOUT ALIAS
Index     	ColName   	ColLabel  
1         	v0c0      	v0c0      
2         	v0c1      	v0c1      
3         	v0c2      	v0c2      
SELECT WITH ALIAS
Index     	ColName   	ColLabel  
1         	v0c0      	alias_v0c0
2         	v0c1      	alias_v0c1
3         	v0c2      	alias_v0c2

在TiDB上的结果

ResultSetMetaData.getColumnName返回某一列在表中而非视图中定义的名字,而ResultSetMetaData.getColumnLabel返回查询时赋予的别名。
然而,考虑到用户查询视图时是将其当做一张抽象的表来看待的,并不关心具体是表还是视图,也许返回属性列在视图定义中的名字更为合理,MySQL的行为就是这样的。
而且,如果用户在查询视图时使用as关键字起了别名,似乎无法从ResultSetMetaData中获取视图中定义的属性名。

5.7.25-TiDB-v5.0.0
SELECT WITHOUT ALIAS
Index     	ColName   	ColLabel  
1         	t0c0      	v0c0      
2         	t0c1      	v0c1      
3         	t0c2      	v0c2      
SELECT WITH ALIAS
Index     	ColName   	ColLabel  
1         	t0c0      	alias_v0c0
2         	t0c1      	alias_v0c1
3         	t0c2      	alias_v0c2

rsmdtest's People

Contributors

peiyuanix avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.