代码之家  ›  专栏  ›  技术社区  ›  Leon

运算符不存在:integer=字符可变

  •  0
  • Leon  · 技术社区  · 6 年前

    我正在为一个例外而失去理智,我需要你的帮助。

    我在一个映射器中编写了一个查询,它基于两个条件从表中检索记录:列表中的“位置”和另一个中的“技能”。

    因此,基本上,如果用户选择要查找的多个技能,那么查询将使用这些技能恢复所有记录…

    这么简单,这么曲折,因为我用了两个前臂…一个有效,另一个不…

    这是一个查询:

    <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)的工作方式类似于魅力。唯一的区别是技能是整数列表,而locationselected是字符串列表。但这不应该是原因,因为我甚至尝试过使用字符串列表,但问题仍然存在…

    rs.id_skill是一个int4,所以只要我的逻辑去了(如果我不疯狂的话),我基本上是在检查一个int是否在一个整数列表中…………

    但我还是有一个错误的语法例外说明: 运算符不存在:integer=character varying提示:没有与给定名称和参数类型匹配的运算符。您可能需要添加显式类型转换。

    我做错什么了?!

    救救我!

    edit:s.“id_location”是一个varchar,所以我要检查它的内容是否在字符串列表中…基于此,唯一合乎逻辑的结论是mybatis的foreach不适用于整数列表…..我不知道……

    1 回复  |  直到 6 年前
        1
  •  3
  •   Koen    6 年前

    AND RS."ID_SKILL" IN 
    

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