mysql列别名不起作用,必须创建一个空的串联以使其起作用 [英] mysql column alias not working, have to create an empty concatenation to make it work

查看:216
本文介绍了mysql列别名不起作用,必须创建一个空的串联以使其起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我这样做:

SELECT PEvent.publicID AS 'ID'...

结果显示为"publicID"而不是"ID"

Results come as "publicID" not as "ID"

要使其正常工作,我必须做:

to make it work i have to do:

SELECT concat(PEvent.publicID, '') AS 'ID'

为什么?

<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver"
maxActive="10" maxIdle="3" maxWait="1000" type="javax.sql.DataSource"
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver"
maxActive="10" maxIdle="3" maxWait="1000" type="javax.sql.DataSource"
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver"
maxActive="10" maxIdle="3" maxWait="1000" type="javax.sql.DataSource"
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver"
maxActive="10" maxIdle="3" maxWait="1000" type="javax.sql.DataSource"

一件很糟糕的事情,像列别名这样简单的东西不起作用...

a very bad thing that something as simple as a column alias does not work...

推荐答案

当我从ubuntu mysql命令行和适用于Windows的MySQL Workbench对它进行测试时,对我来说效果很好.我发现这可能是jdbc的事情,并四处搜寻. MySQL认为这不是错误.

It works fine for me when I tested this from my ubuntu mysql command line, and MySQL Workbench for Windows. I figured it might be a jdbc thing, and searched around. MySQL doesn't consider this as a bug.

http://bugs.mysql.com/bug.php?id=21596

在BZ上的评论中,

这是符合JDBC要求的更改.需要RSMD.getColumnName()才能返回实际的列名.别名通过RSMD.getColumnLabel()返回.

This is a change required for JDBC-compliance. RSMD.getColumnName() is required to return the actual column name. Aliases are returned via RSMD.getColumnLabel().

如果要从Connector/J 3.1中获得较旧的不兼容行为,请使用夜间版本5.0中存在的"useOldAliasMetadataBehavior"配置参数,并将其设置为"true".

If you want the older non-compliant behavior from Connector/J 3.1, use the "useOldAliasMetadataBehavior" configuration parameter present in the 5.0 nightly builds, and set it to "true".

这篇关于mysql列别名不起作用,必须创建一个空的串联以使其起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆