Question

I have some complex SQL which upon execution returns two Long columns. Now, how can I write queries like the following?

val sqlStr: String = ??? // My complex SELECT statment
val sqlQuery = queryNA[(Long, Long)](sqlStr)
for {
  data <- tableQuery if data.id in sqlQuery._1
} yield data

I expect it to produce something like SELECT ... FROM table WHERE table.id IN (SELECT ...) Is this even possible? And if not, can you please point out some other way or workaround of doing something similar? The problems here:

  • Most other parts are using Query API and I want it to be interoperable
  • Executing sqlStr directly will fetch lots of results and I'd like to avoid that
Was it helpful?

Solution

The lifted embedding (Query API) and plain SQL do not interoperate at the moment. The lifted embedding needs to know the exact structure it got from the scala code to do its optimizations. It can't do that on plain SQL code. I guess you could imagine something in the future, but there are no concrete plans at the moment.

I created a ticket, so we'll look into it at some point: https://github.com/slick/slick/issues/756

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top