簡體   English   中英

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 ($1)").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);

處理一組 id 以返回多行的正確方法是什么?

編輯

我最終這樣做了:

        Tuple parameter = Tuple.of(ids.toArray(new Long[]{}));

        String query = "with values as (\n" +
                "select unnest(($1)::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($1)

然后您應該能夠使用 List/Set/Array 參數值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM