Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
How to convert a list of tuples into an OID?

I have an SQL statement where I would like to pass a list of tuples customerIdSubCustomerPairs so that I can fetch all the rows matching the where clause from the table customers.

This is the SQL for it:

@Language("PostgreSQL")
private const val getExistingRowsSql = """
  select customerId, subcustomer
  from customer
  where (uuid IN (:uuids) AND is_deleted = false)
  union
  select customerId, subcustomer
  from customer
  where (customerId, subcustomer) IN (:customerIdSubCustomerPairs) AND is_deleted = false
"""

I have a list of customers from which I am building a list of lists for customerIdSubCustomerPairs. It looks like this:

val existingCustomers = fetchRows(
      ctx, getExistingRowsSql, mapOf(
      "uuids" to customers.map { it["uuid"] },
      "customerIdSubCustomerPairs" to customers.map { listOf(it["customerId"] as String, it["subCustomer"] as String) }
  ))

And I have a function where I convert values to Oid types:

fun jdbcConvertValue(session: Session, v: Any?): Any? =
    when (v) {
      is Collection<*> -> {
        when (val type = v.firstOrNull()) {
          null -> null
          is String -> session.connection.underlying.createArrayOf("text", v.toTypedArray())
          is Long -> session.connection.underlying.createArrayOf("bigint", v.toTypedArray())
          is Int -> session.connection.underlying.createArrayOf("bigint", v.toTypedArray())
          is UUID -> session.connection.underlying.createArrayOf("uuid", v.toTypedArray())
          is List<*> -> v.map { jdbcConvertValue(session, it) }.toTypedArray()
          else -> throw Exception("You need to map your array type $type ${type.javaClass}")
        }
      }
      else -> v
    }

However, when I try to fetch rows like that, I get an error:

org.postgresql.util.PSQLException: Cannot cast an instance of [Ljava.lang.Object; to type Types.ARRAY

I am not sure how to pass values as tuples into a SQL statement? The fields customerId and subcustomer are both text columns in the DB table.

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda