运算符不存在:整数 = 字符变化

Operator does not exist: integer = character varying

我因为异常而失去了理智,我需要你的帮助。

我已经将查询写入映射器,该映射器根据两个条件从 table 检索记录:"location" 在列表中,"skill" 在另一个列表中。

所以,基本上,如果用户选择了不止一种技能来查找,查询将恢复所有具有这些技能的记录...

如此简单但又如此扭曲,因为我使用了两个 foreach...一个有效,另一个无效...

这是查询:

<select id="selectAllByFilter" resultMap="BaseResultMap">
select distinct
<include refid="Base_Column_List" /><include refid="Join_Column_List" />
from "ANAG_REQS" A JOIN "ANAG_REQS_RISORSE" R ON A."ID_REQS_RDA"=R."ID_REQS" LEFT JOIN "SEC_USER" U ON R."ID_USER"=U."ID"
LEFT JOIN "USER_LOCATION" S ON S."ID_REQS_USER"= R."ID_REQS"
LEFT JOIN "USER_SKILL" RS ON RS."ID_REQS_USER"= R."ID_REQS"
LEFT JOIN "USER_CUSTOMER" RC ON RC."ID_REQS"= R."ID_REQS"
WHERE 1=1
<if test="filter.idREQS != null">
    AND A."ID_REQS_RDA" = #{filter.idREQS,jdbcType=INTEGER}
</if>
<if test="filter.states != null and filter.states.size()>0 and not statesuspended">
    AND A."state_RDA" IN 
    <foreach item="item" collection="filter.states" index="index"
        open="(" separator="," close=")">           
        #{item}
    </foreach>
    AND R."state" != 'suspended'
</if>
<if test="filter.states != null and filter.states.size()>0 and statesuspended">
    AND (A."state_RDA" IN 
    <foreach item="item" collection="filter.states" index="index"
        open="(" separator="," close=")">           
        #{item}
    </foreach>
    OR A."state_RDA" = 'published' AND R."state" = 'suspended')
</if>
<if test="filter.states.isEmpty() and statesuspended">
    AND A."state_RDA" = 'published' AND R."state" = 'suspended'
</if>
<if test="filter.dataREQSDa != null">
    AND A."DATA_REQS_RDA" &gt;= #{filter.dataREQSDa,jdbcType=DATE}
</if>
<if test="filter.dataREQSA != null">
    AND A."DATA_REQS_RDA" &lt;= #{filter.dataREQSA,jdbcType=DATE}
</if>
 <if test="filter.pm != null and filter.pm != ''">
    <bind name="pattern1" value="'%' + filter.pm + '%'" />
    AND lower(U."USER_NAME") LIKE lower(#{pattern1})
</if>
<if test="filter.CUSTOMER != null">     
    AND RC."ID_CUSTOMER" = #{filter.CUSTOMER,jdbcType=INTEGER}
</if>
<if test="filter.locationselected != null and filter.locationselected.size()>0">
    AND S."ID_LOCATION" IN 
    <foreach item="item" collection="filter.locationselected" index="index"
        open="(" separator="," close=")">
          #{item}
    </foreach>
</if>
<if test="filter.skills != null and filter.skills.size()>0">
    AND RS."ID_SKILL" IN 
    <foreach item="item" collection="filter.skills" index="index"
        open="(" separator="," close=")">
          #{item}
    </foreach>
</if>
</select>

在最新的 foreach (filter.skills) 上抛出异常。

问题是前面的 foreach (filter.locationSelected) 工作得很好。唯一的区别是 skills 是一个整数列表,而 locationSelected 是一个字符串列表。但这不应该是原因,因为我什至尝试使用字符串列表,但问题仍然存在...

RS.ID_SKILL 是一个 int4 所以,只要我的逻辑正常(如果我不发疯的话)我基本上是在检查 int 是否在整数列表中...... ......

但我仍然收到 BadSQLGrammarException 声明:运算符不存在:整数 = 字符变化 提示:没有运算符匹配给定的名称和参数类型。您可能需要添加显式类型转换。

我做错了什么?!

救救我!

编辑:S."ID_LOCATION" 是一个 varchar,所以我正在检查它的内容是否在字符串列表中...基于此唯一合乎逻辑的结论是 mybatis 的 foreach 不不能使用整数列表......我不知道......

您是否尝试过通过以下方式修改查询: 正在替换

AND RS."ID_SKILL" IN 

来自

AND cast(RS."ID_SKILL" as character varying) IN