【发布时间】:2019-10-03 10:19:59
【问题描述】:
我的查询看起来像这样,并且执行良好:
select *
from table t
where (t.one,t.two,t.three) in ( (11,12,13), (21,22,23) );
现在in 语句中这些三元组的数量会有所不同,因此我尝试使用 JDBC 执行以下操作:
String sql = "select * from table where (one, two, three) in (select * from unnest(?::smallint[], ?::integer[], ?::integer[]))"
// conn is the java.sql.Connection
PreparedStatement ps = conn.prepareStatement(sql);
ps.setArray(1, conn.createArrayOf("smallint", new Short[]{11, 21}));
ps.setArray(2, conn.createArrayOf("integer", new Integer[]{12,22}));
ps.setArray(3, conn.createArrayOf("integer", new Integer[]{13,23}));
return ps;
这表现非常糟糕。那么有没有办法使用 jdbc 发送三元组,使得最终结果等同于 sql 查询?
我有两个 btree 索引,一个在 one, two,另一个在 one, three 我需要使用其中任何一个来提高性能
【问题讨论】:
标签: postgresql jdbc spring-jdbc postgresql-11 pg-jdbc