操作符不存在: integer = character varying


<delete id="deleteStudentByIds" parameterType="String">
    delete from student where id in 
    <foreach item="id" collection="array" open="(" separator="," close=")">
        #{id}
    </foreach>
</delete>

用MyBatis批量删除Postgresql数据记录的时候报错

### The error occurred while setting parameters
### SQL: delete from student where id in           (               ?          ,              ?          )
### Cause: org.postgresql.util.PSQLException: 错误: 操作符不存在: integer = character varying
  建议:没有匹配指定名称和参数类型的操作符. 您也许需要增加明确的类型转换.
  位置:32
; bad SQL grammar []; nested exception is org.postgresql.util.PSQLException: 错误: 操作符不存在: integer = character varying

传入的参数是: {“ids”:[“9,10”]}

这在Mysql里面是没有问题,但在Postgresql下面需要转换一下:

<delete id="deleteStudentByIds" parameterType="String">
    delete from student where id in 
    <foreach item="id" collection="array" open="(" separator="," close=")">
        CAST( #{id} as int )
    </foreach>
</delete>

或者把传入的参数改成: {“ids”:[9,10]} 也可以。

 

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注