ITPub博客

首页 > 数据库 > 数据库开发技术 > 乌龙问题, 关于 负数的不等于问题的乌龙.

乌龙问题, 关于 负数的不等于问题的乌龙.

原创 数据库开发技术 作者:babyyellow 时间:2017-03-28 10:34:36 0 删除 编辑
最近出了一单乌龙问题.


bad SQL grammar [select * from workflow_model_pic t0  where 1=1  and  ( ( t0.receive_user='cc01' and t0.status !=-1) or t0.status=1 ) and ( exists(select 1 from model m where t0.model_id=m.id and m.deleted=0 and  m.hidden=0 and m.state!=-1 and m.state !=2   and m.seq!=710 ) or t0.model_color_id is not null ) and  receive_user = 'cc01' order by  receive_time asc,upload_time asc,finish_time asc,id asc  LIMIT 25 OFFSET 0]; nested exception is org.postgresql.util.PSQLException: ERROR: operator does not exist: bigint !=- integer



乍一看 蒙圈了,   bigint 不能等于 负的整数 em1003

类型转换问题? 

where status !=(-1):;bigint 是没有问题, 然后就更蒙圈了. 


实际情况就很乌龙了. 

看看数据库的饱什么错

autoprice_app=> select * from ap_workflow_model_pic where status !=-1 ;  
ERROR:  operator does not exist: bigint !=- integer
μú1DDselect * from ap_workflow_model_pic where status !=-1 ;
                                                      ^



问题出在哪里呢? 



实际问题是既不是 类型转换问题也不是 什么操作符的问题, 而是


!=  跟  -1 之间 没有空格   


导致 sql 认为  !=-  是一个操作符   1 是整数  . 而数据库里没有为数字定义   !=-  这样的操作符. 所以就报这个错误了. 




知道问题所在, 就很容易搞了.  加多一个空格就好了. 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/133735/viewspace-2136166/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
oracle MySQL Postgresql 专职数据库dba。 系统架构师。 mysql 官方认知dba 。 15年专职dba 经验。 潜意识沟通实证者 心理咨询师。 禅修布道者, 禅修指导员。 禅定实证者。

注册时间:2010-12-02

  • 博文量
    367
  • 访问量
    1908813