环境
org.postgresql:postgresql:9.3-1102-jdbc41
org.mybatis:mybatis:3.2.7
查询如下所示。我的应用程序正在连接到AWS RedShift
SELECT * FROM sample_table WHERE
<foreach item="item" collection="lists" open="(" close=")" separator=" OR ">
(xxx BETWEEN #{item.From} AND #{item.To})
</foreach>
如果参数的长度,列表太大(超过3000),mybatis会出现一些错误。
2015-11-07 12:46:26,672 [main] ERROR Main - org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
### The error may exist in com/xxx/sql/sql_redshift.xml
### The error may involve com.xxx.sql.findXXXs-Inline
### The error occurred while setting parameters
我认为发送到RedShift的生成查询太大而无法发送。 有没有一种避免这个问题的好方法?
FYI 输出查询就像这样
SELECT * FROM sample_table WHERE
(
(xxx BETWEEN 2 AND 5) OR
(xxx BETWEEN 9 AND 12) OR
(xxx BETWEEN 15 AND 20) OR
(xxx BETWEEN 30 AND 59) OR
)