-
Notifications
You must be signed in to change notification settings - Fork 180
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
Needed: unnest WITH ORDINALITY
#335
Comments
@virusdave slick-pg can't resolve this. Maybe you should try |
the problem there is that For instance, consider a db table that has an index on 2 columns, A,B. If we could accomplish this unnesting, then the entire query can be precompiled just fine. The final query would look something like:
Such a query would be precompilable and still be parameterizable with parameter sets of cardinality unknown at compile time, which is a HUGE problem in slick now. If this unnesting functionality isn't possible in slick-pg currently, can you add it? It would solve a critical use case with high performance. |
I'll try. But |
Well, the generated |
Yup, for sure! I think i could possibly add the Does it look like it'll be doable? |
No, I can't let it generate |
Hello, @virusdave! Did you manage to come up with a workaround for this? |
Have you try using |
Let's say I have 2 sql array literals (in scala as lists):
val a = List("a", "b", "c")
andval b = List(1, 2, 3)
I want to do a
zipJoin
on theunnest
of these two, to produce:Trying something naive like:
val c = Query(a.unnest).zipJoin(Query(b.unnest))
doesn't do the right thing, due to howzipJoin
andunnest
are implemented! Instead, it gives the cross product of these two sets.Specifically, the construct
SELECT UNNEST(...)
instead ofSELECT * FROM (UNNEST(...))
, when combined withROW_NUMBER
gives all rows the value1
.Investigating a bit, it seems like the "correct" method to do this in postgres is by using the syntax
SELECT * FROM (UNNEST(...) WITH ORDINALITY)
, which will then be guaranteed to give me back the items from the input array with correctly applied indices, which could then be joined on.How is this possible using slick-pg, or do I need to use a
sql""
style query?The text was updated successfully, but these errors were encountered: