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

Support for Array fields like uuid[] on Postgres #40

Open
jlvertol opened this issue Oct 14, 2024 · 4 comments
Open

Support for Array fields like uuid[] on Postgres #40

jlvertol opened this issue Oct 14, 2024 · 4 comments

Comments

@jlvertol
Copy link
Contributor

jlvertol commented Oct 14, 2024

Hi! As far as I could tell while using Scalasql with Postgres, SQL array columns are not supported.

I tried to add a property of type T[Seq[String]] to my table, but got this error:

[error] 109 |object Invoice extends Table[Invoice]:
[error]     |                                     ^
[error]     |No given instance of type scalasql.core.Queryable.Row[scalasql.core.Expr[Seq[String]], Seq[String]] was found.
[error]     |I found:
[error]     |
[error]     |    scalasql.core.Expr.ExprQueryable[scalasql.core.Expr, Seq[String]](
[error]     |      scalasql.core.TypeMapper.enumTypeFromDialectTypeMappers[T])
[error]     |
[error]     |But method enumTypeFromDialectTypeMappers in object TypeMapper does not match type scalasql.core.TypeMapper[Seq[String]].

Additionally, if I just try to use T[String] as a workaround, I get a different error when querying the table instead:

org.postgresql.util.PSQLException: ERROR: operator does not exist: uuid[] ~~ text
  Hint: No operator matches the given name and argument types. You might need to add explicit type casts.

Am I correct that we don't support these types?

If so, I'd like to try my hand at solving it, but first I want to make sure this is actually not supported and there's no workarounds (ḧence my question above)

@lihaoyi
Copy link
Member

lihaoyi commented Oct 20, 2024

Yes they're not supported right now, would love to have your help in adding support!

@NovaMage
Copy link

@jlvertol Did you end up taking a stab at this or did you find a workaround? This is the only thing stopping me from adopting this library at my company.

@jlvertol
Copy link
Contributor Author

@jlvertol Did you end up taking a stab at this or did you find a workaround? This is the only thing stopping me from adopting this library at my company.

Hey @NovaMage, I did take a stab at it, but given time constraints it was only good enough to fix it for me and my company (by making a workaround class in our own repository). The upside is that Li's library is indeed flexible enough to allow such workarounds; you don't even need to fork ScalaSQL, it's enough to make an implicit class for the kind of Arrays you need to support.

As for the patch, I don't know when I'll be able to come back and make a patch for this.

@NovaMage
Copy link

NovaMage commented Jan 22, 2025

For any future readers, I set up a repository showcasing how to set up the TypeMapper for Vector[Long] (mapped to BIGINT[] in postgres)

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

3 participants