SELECT Sum(diff) FROM (SELECT Date_part('epoch', age(Max(s.timepoint), Min(s.timepoint))) * 1000 AS diff FROM v2_game g, v2_player_game_rel r, v2_timepoint_stats s WHERE g.id = r.g AND NOT r.locked AND s.player_game = r.id AND r.p = ? GROUP BY g.id) AS foo
I have tried a few things, but I always either get a wrong query or a query that is straight out invalid.
My best guess looks like this:
Datapoints > "v2_timepoint_stats"
r.game > "r.g"
r.playerId > "r.p"
datePartLone and age or lifted functions from postgres
val q = (for { s <- Datapoints r <- s.playerGame if (!r.locked && r.playerId === 410) g <- r.game } yield (g.id, datePartLong("epoch", age(s.time.max.get, s.time.min.get)) * 1000L)).groupBy(x => x._1).map { case (id, len) => len.map(_._2).sum }
This generates this SQL:
SELECT Sum(x2.x3) FROM (SELECT x4."id" AS x5, Date_part('epoch', Age(Max(x6."timepoint"), Min(x6."timepoint"))) * 1000 AS x3 FROM "v2_timepoint_stats" x6, "v2_player_game_rel" x7, "v2_game" x4 WHERE ( ( x7."id" = x6."player_game" ) AND ( ( NOT x7."locked" ) AND ( x7."p" = 410 ) ) ) AND ( x4."id" = x7."g" )) x2 GROUP BY x2.x5So this fails like with this message:"column "x4.id" must appear in the GROUP BY clause or be used in an aggregate function"because the inner query selects uses min and max on the date part, but no aggregate on the id (ofc since I want to group by on it). Moving the group by inside the subquery gives me the expected result.I think my basic problem is that I cant find a way to do a group by that groups by a column that is not selected.How does one do that? I cant find a way to do it without getting compiler errors.On a sidenote, this part age(s.time.max.get, s.time.min.get)) yields me a deprecated warning I should use Query().min, but code like age(Query(s.time).max.get, Query(s.time).min.get) give this sql, which has an invalid syntay: age(select max(x6."timepoint"),select min(x6."timepoint")
Perhaps you'd find sqltyped interesting?
--
---
You received this message because you are subscribed to the Google Groups "Slick / ScalaQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaquery+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
That paired with the problems you got
because of "thinking SQL" when using Slick made it understandably a bit
hard.
[...] check back if you are ever annoyed by SQL
semantics and want Scala back :).
To be clear: Slick is a joint project of EPFL and Typesafe and I am
working on the EPFL side. The point of view described in my posts are my
personal ones, which may or may not match those of Typesafe.
The adoption of SQL-esque languages may be just due to the elegance of
> That paired with the problems you got
> because of "thinking SQL" when using Slick made it understandably a bit
> hard.
>
> I find this point of view quite remarkable. SQL has come a long way and
> it does carry its 30-year-old legacy. But with legacy comes traction and
> robustness, and up to date, SQL has been the unchallenged means of
> querying and interoperating with RDBMS. Some non-RDBMS have even started
> to adopt SQL-esque languages as their querying interfaces because of the
> simplicity and expressivity of SQL. Not even LINQ-to-SQL can make such a
> claim, even if LINQ is a very well-adopted API for "querying"
> collections through LINQ-to-Objects, or entities through LINQ-to-EF.
comprehensions in general and the fact that SQL is the most
popular/familiar comprehension-language. Having a familiar API is a
strong feature. API-wise Jooq is familiar to SQL users and Slick is
familiar to Scala collections users. SQL and Scala comprehensions /
collection methods have a lot of closely corresponding concepts. But
there are syntactic and semantic differences in the APIs. Using one API
with having a different one in mind can lead to unexpected errors or
behavior. That was my point. If you are "thinking SQL" the Scala
collections API may behave unexpectedly and vise-versa.
> Back to SQL: If Slick users care about their RDBMS' performance (whichThere are cases were hand tuning SQL is absolutely necessary. There are
> they should, when they pay millions for Oracle licenses and [xx] for
> Slick driver licenses), then they might really want to stay in control
> of aforementioned SQL.
other cases where Slick produces optimal or good enough SQL and
composability becomes more important because of the improved
productivity, understandability and more likely correctness that comes
with it. I am not familiar enough with jooq to know if it offers the
same level of composability. Monolithic SQL strings clearly do not.
It is an API mismatch that makes it hard, NOT an impedance mismatch. SQL
> Now, if "thinking SQL" makes using Slick hard -
> or vice versa, using Slick makes "thinking SQL" hard, then maybe we
> have a new impedance mismatch here? Wouldn't it be better to
> implement your own "NoSQL" storage engine, then?
and Slick have different APIs, but very similar concepts. Both are
relational... no mismatch.
> [...] check back if you are ever annoyed by SQLYou are overrating this "statement". This is just me being enthusiastic
> semantics and want Scala back :).
>
> What is Typesafe's official stand on the "SQL subject"? Is that
> documented somewhere? Is "annoyance" with SQL an authoritative claim by
> Typesafe (as can be seen below)?
about Slick offering a Scala-collections-like API. It did not mean that
an SQL-inspired API is bad or necessarily annoying.
I respect jooq a
lot. If you want a type-safe SQL-like API, something like jooq is the
way to go. I said that in my recommendation to the initial poster of
this thread. But I do believe that there is a certain appeal in using
largely identical APIs for querying databases and collections and NOT
having two APIs (collections and SQL) to logically do the same thing
just on different storage. This is one of the things Slick is about. And
if familiarity with SQL is more important to someone than API
unification then that is perfectly fine and jooq is probably a good
library for that choice.
Slick embraces language integration, jooq embraces SQL familiarity. Both
embrace type-safe, relational queries. I see us largely fighting for the
same cause, offering something that can be superior to SQL strings and
ORMs. Let's focus on that :)!
Hi Lukas,
likewise :).
> Thank you very much for your response!
I interpret impedance mismatch as the difference in concepts between OO
> It is an API mismatch that makes it hard, NOT an impedance mismatch. SQL
> and Slick have different APIs, but very similar concepts. Both are
> relational... no mismatch.
>
> Would be interesting to see where this term came from. Clearly it is
> related to impedance matching:
> http://en.wikipedia.org/wiki/Impedance_matching
>
> I guess it can be said that Slick is indeed "maximising power transfer"
> by being a "relational-based" API, if we want to call it that way. So,
> OK, I can see your point. I won't reuse the impedance term again in this
> context.
and SQL, especially imperative vs. declarative, but also object-identity
vs. primary keys, object-references vs. joins, an so forth.
> Slick embraces language integration, jooq embraces SQL familiarity. BothGreat :). We could even consider some kind of integration at some point.
> embrace type-safe, relational queries. I see us largely fighting for the
> same cause, offering something that can be superior to SQL strings and
> ORMs. Let's focus on that :)!
>
>
> Well, we can clearly agree on the latter :-)
I could imagine falling back to jooq instead of plain SQL when you hit a
Slick limitation.
Or using Slick as a jooq backend to run jooq on nosql
stores once we get there with Slick (which is on hold at the moment due
to higher priorities).
Slick can emulate relational features (e.g.
joins) when not supported by a backend natively, which could help.
Maybe we run into each other at Scala Days Berlin?
Maybe I missed something, but us there a reason no one mentioned the other SQL-style Scala libraries, like Squeryl and sqltyped? I believe there are others besides jooq as well.
--
---
You received this message because you are subscribed to the Google Groups "Slick / ScalaQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaquery+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/52EA18BB.7010502%40gmail.com.