美文网首页
一个奇葩的问题,column 'x' not found

一个奇葩的问题,column 'x' not found

作者: 沐一同学 | 来源:发表于2020-12-10 14:33 被阅读0次

    一个奇葩的问题,column not found

    背景

    配合业务排查一个问题,业务反馈代理v3.1 升级代理y v3.3会报错误。开始以为代理或者后端mysql报错。
    DBA反馈mysql后端无报错,也排查了代理的日志。没有发现查询失败日志。

    绝地

    而且拿业务SQL执行,v3.1和v3.3都是可以正常执行,都能出结果。怀疑是接入组件问题,如果DAL有问题
    V3.1应该也有问题,不会只有v3.3才有?

    重生

    当走投无路的时候,又抽了一眼业务的报错,发现column 'xxx' not found。顺着这个思路google,找到
    有用的信息,或多遇到。
    https://stackoverflow.com/questions/19062453/java-sq-sqlexception-column-not-found
    关键信息:
    It is failing because you're trying to extract category_id from the ResultSet and it isn't there.

    在结果集中,找不到指定字段。

    验证

    复盘了一下v3.1和v3.3的返回结果

    v3.1

    select count(distinct uid) from t where uid = 1;
    | count(distinct uid)   |
    |                   0   |
    

    v3.3

    select count(distinct uid) from t where uid = 1;
    | count(distinct `uid`) |
    |                   0   |
    

    v3.3中为了安全,给列名,表名,库名都加了反引号。而v3.1没有改写。问处在,v3.1和v3.3的查询重写,逻辑变了。

    一般人不会这么写,都会加别名的。不会出现这个问题。

    处理

    业务添加别名,解决问题。

    相关文章

      网友评论

          本文标题:一个奇葩的问题,column 'x' not found

          本文链接:https://www.haomeiwen.com/subject/qntrgktx.html