PG提示could not determine data type of parameter $4

目录

场景: 

现象:

版本:

分析:

 解决方式:

场景: 

今天遇到现场环境连接Postgre数据库,日志提示could not determine data type of parameter $4,通过日志复制出完整sql,但是在pg数据库却能正常执行,本地测试没有遇到这个问题现记录一下。

现象:

日志打印sql如下:

select RES.* from ACT_RU_TASK RES 
left join ACT_BIZ_PROCINST M on RES.PROC_INST_ID_ = M.PROC_INST_ID_ 
WHERE M.F11_ like ? and M.F12_ like ? and (RES.ASSIGNEE_ = ? or (RES.ASSIGNEE_ ='-1' 
and ( M.XZQ_ LIKE CONCAT(CONCAT('%',?),'%') ) 

扫描二维码关注公众号,回复: 15534295 查看本文章

填充参数后:

select RES.* from ACT_RU_TASK RES 
left join ACT_BIZ_PROCINST M on RES.PROC_INST_ID_ = M.PROC_INST_ID_ 
WHERE M.F11_ like '5a1e92b3-a08f-11e7-9fa0-00163e0003d6' and M.F12_ like '48e3d33a-e600-11ea-a4e0-a6f87c2a5b07' and (RES.ASSIGNEE_ = 'heby' or (RES.ASSIGNEE_ ='-1' 
and ( M.XZQ_ LIKE CONCAT(CONCAT('%','330800'),'%') ) 

日志报错:

could not determine data type of parameter $4,

翻译意思是无法确定第四个参数的数据类型

第四个参数定位到:M.XZQ_ LIKE CONCAT(CONCAT('%','330800'),'%')这里报错

版本:

线上版本:

本地版本:

分析:

第一:发现数据的版本存在差异,本地的版本明显高,而线上的版本低

第二:发现数据库连接的方式也有差异

本地:jdbc.url=jdbc:postgresql://db.gisquest.com:5866/bdcpz?currentSchema=gisqbpm

线上:jdbc.url=jdbc:postgresql://db.gisquest.com:5866/bdcpz? stringtype=unspecified&currentSchema=gisqbpm

不加stringtype参数则将使用默认值stringtype=varchar则这意味着在处理字符串结果时将使用Java的String类型。

加stringtype参数设置为unspecified则意味着JDBC驱动程序在处理字符串结果时应该使用未指定的默认类型,这样可以防止一些潜在的类型转换问题

 解决方式:

第一:要么要求现场环境版本保持和本地环境版本一致且数据库的连接方式也保持一致。

第二:修改代码在查询时强转成text类型

 <choose>
     <when test='_databaseId == "postgres"'>
         <foreach item="item" index="index" collection="biz_xzqsLike" open="(" separator="or"
                                             close=")">
                         M.XZQ_ LIKE CONCAT(#{item}::text,'%')
          </foreach>
    </when>
  <otherwise>
       <foreach item="item" index="index" collection="biz_xzqsLike" open="(" separator="or"
                                             close=")">
          M.XZQ_ LIKE CONCAT(#{item},'%')
       </foreach>
   </otherwise>

</choose>

猜你喜欢

转载自blog.csdn.net/qq_38423256/article/details/130987031