在测试环境模糊查询的使用 的是Mybatis
模糊查询的写法是
select * from test
where
name like CONCAT('%',#{marketInsightDTO.drugName},'%')
测试环境没有报错
然后上到生产就报错
错误日志
### Cause: org.postgresql.util.PSQLException: ERROR: could not determine data type of parameter $7
; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: ERROR: could not determine data type of parameter $7
org.springframework.jdbc.BadSqlGrammarException:
拿到sql去生产数据库执行也是没问题的
初步分析应该是postgresql版本的原因,上面的错误也很明显 大致就是 无法确定参数类型,我们简单的做一个强制转换就可以了
使用 ::text
like CONCAT('%',#{marketInsightDTO.drugName}::text,'%')
然后去查询发现测试环境Postgresql 版本为:
PostgreSQL 11.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36), 64-bit
生产为:
PostgreSQL 10.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4), 64-bit
注意:本文归作者所有,未经作者允许,不得转载