PSQLException:错误:运算符不存在:uuid = uuid[]

Lef*_*eff 5 postgresql uuid kotlin

我试图通过检查是否与uuids传递给 select 语句的数组中的任何值匹配来从表中获取行。代码如下所示:

val existingCustomers = fetchRows(
      ctx, generateSQLForTuples(tuples), mapOf("uuids" to customers.map { it["uuid"] as UUID })
  )
Run Code Online (Sandbox Code Playgroud)

看起来generateSQLForTuples像这样:

private fun generateSQLForTuples(tuplesList: List<List<String>>):String =
    // language=PostgreSQL
    """
      select id, subcustomer
      from customer
      where uuid in (:uuids)
      union
      select id, subcustomer
      from customer
      where (customer_id, subcustomer) in (${toJdbcTuples(tuplesList)})
    """.trimIndent()
Run Code Online (Sandbox Code Playgroud)

但是,我收到错误:

PSQLException: ERROR: operator does not exist: uuid = uuid[]
Run Code Online (Sandbox Code Playgroud)

我在这里做错了什么,如何将具有 UUID 值的数组传递给 select 语句?

atb*_*ker 3

IN运算符不适用于ARRAY[],它适用于一列行。

您有两种选择来解决此问题:

  1. 使用扩展 ARRAYunnest()

例如。column IN (SELECT unnest((ARRAY[uuid1])::uuid[]))

  1. 用于ANY()与 ARRAY 一起使用

例如。WHERE column = ANY((ARRAY[uuid1])::uuid[])