最近出了一单乌龙问题.
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 不能等于 负的整数
类型转换问题?
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 是整数 . 而数据库里没有为数字定义 !=- 这样的操作符. 所以就报这个错误了.
知道问题所在, 就很容易搞了. 加多一个空格就好了.
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 不能等于 负的整数

类型转换问题?
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博客 ” ,链接:http://blog.itpub.net/133735/viewspace-2136166/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/133735/viewspace-2136166/