Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named parameters with array type #27

Closed
rubendm92 opened this issue Nov 30, 2018 · 4 comments
Closed

Named parameters with array type #27

rubendm92 opened this issue Nov 30, 2018 · 4 comments

Comments

@rubendm92
Copy link
Contributor

rubendm92 commented Nov 30, 2018

Hi

We are trying to do an insert to a table that contains a field of type text[] (postgres). We are doing something like this

sessionProvider.createSession().use { session ->
    session.run(queryOf(
            "INSERT INTO t(x, xs) VALUES(:x, :xs)",
            mapOf("x" to "hello", "xs" to listOf("1", "2"))
    ).asUpdate)
}

We are getting an error because of the type os xs.

org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of java.util.Collections$SingletonList. Use setObject() with an explicit Types value to specify the type to use.

I don't see any example or documentation related to this. Is this supported?

Thanks!

@seratch
Copy link
Owner

seratch commented Nov 30, 2018

Use java.sql.Array type for array type. It's not due to a specification of this library but JDBC's one. https://jdbc.postgresql.org/documentation/head/arrays.html

@rubendm92
Copy link
Contributor Author

But for creating a java.sql.Array I need a JDBC's connection, right? All the examples I see are using a connection from JDBC but I don't see how to do it with the session object from Kotliquery or something similar

@rubendm92
Copy link
Contributor Author

Oh, I see I can use session.connection.underlying.createArray. Kinda ugly, don't you think? 🤔

@seratch
Copy link
Owner

seratch commented Nov 30, 2018

I agree. It's also not ideal but I'm okay to have session.createArray in short.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants