Quarkus Reactive PostgreSQL Vert.x - Long & in () 查询的集合
Quarkus Reactive PostgreSQL Vert.x - Collection of Long & in () queries
我正在尝试将准备好的查询与使用一组 Long 作为参数的 'where xxx in ()' 查询结合使用:
public static Multi<Item> findAll(PgPool client, Set<Long> ids) {
Tuple parameter = Tuple.of(ids.toArray(new Long[]{}));
// Tuple parameter = Tuple.wrap(new ArrayList(ids));
return client.preparedQuery("SELECT id, name, properties FROM items where id in ()").execute(parameter)
.onItem().transformToMulti(set -> Multi.createFrom().iterable(set))
.onItem().transform(Item::from);
}
但是虽然 'in' SQL 查询应该处理多个值,但它在传递数组时确实有效,抛出以下内容:
io.vertx.core.impl.NoStackTraceThrowable: Parameter at position[0] with class = [[Ljava.lang.Long;] and value = [[Ljava.lang.Long;@1a074753] can not be coerced to the expected class = [java.lang.Number] for encoding.
传递单个值有效,但这不是该方法的目的:
Tuple parameter = Tuple.of(1206756351360216067L);
为了 return 多行,处理 ID 集的正确方法是什么?
编辑
我最终这样做了:
Tuple parameter = Tuple.of(ids.toArray(new Long[]{}));
String query = "with values as (\n" +
"select unnest(()::bigint[]) as id\n" +
")\n" +
"select v.* from values vl " +
"join items v on v.id = vl.id";
将查询更改为:
SELECT id, name, properties FROM items where id = ANY()
然后您应该可以使用 List/Set/Array 参数值。
我正在尝试将准备好的查询与使用一组 Long 作为参数的 'where xxx in ()' 查询结合使用:
public static Multi<Item> findAll(PgPool client, Set<Long> ids) {
Tuple parameter = Tuple.of(ids.toArray(new Long[]{}));
// Tuple parameter = Tuple.wrap(new ArrayList(ids));
return client.preparedQuery("SELECT id, name, properties FROM items where id in ()").execute(parameter)
.onItem().transformToMulti(set -> Multi.createFrom().iterable(set))
.onItem().transform(Item::from);
}
但是虽然 'in' SQL 查询应该处理多个值,但它在传递数组时确实有效,抛出以下内容:
io.vertx.core.impl.NoStackTraceThrowable: Parameter at position[0] with class = [[Ljava.lang.Long;] and value = [[Ljava.lang.Long;@1a074753] can not be coerced to the expected class = [java.lang.Number] for encoding.
传递单个值有效,但这不是该方法的目的:
Tuple parameter = Tuple.of(1206756351360216067L);
为了 return 多行,处理 ID 集的正确方法是什么?
编辑
我最终这样做了:
Tuple parameter = Tuple.of(ids.toArray(new Long[]{}));
String query = "with values as (\n" +
"select unnest(()::bigint[]) as id\n" +
")\n" +
"select v.* from values vl " +
"join items v on v.id = vl.id";
将查询更改为:
SELECT id, name, properties FROM items where id = ANY()
然后您应该可以使用 List/Set/Array 参数值。