解决java传递参数是String类型,pgsql的numeric字段接收报错问题

来源:互联网 发布:网络药品销售 规定 编辑:程序博客网 时间:2024/05/29 11:47

postgresql对传入的参数类型匹配相当严格

如select * from user where id = #id#

假设id类型为numeric,而传入的id为string的话postgresql就会报错:

--- Cause: org.postgresql.util.PSQLException: ERROR: operator does not exist: numeric = character varying

  建议:No operator matches the given name and argument type(s). You might need to add explicit type
 casts.
  位置:125
Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: numeric = character varying
  建议:No operator matches the given name and argument type(s). You might need to add explicit type
 casts.

暂时想到的解决方法:

select * from user where id = cast(#id# as numeric)

如果哪位大神有更好的方法请告知!

原创粉丝点击