我正在尝试生成这样的 sql 语句:
select count(*)>0 from "SomeTable"
使用 Scala 的 slick 1.0.1 和 postgres。
这是我的代码:
val rows = for(row <- Query(Order)) yield row
println(rows.selectStatement)
val rowCount = (for(l<- Query(rows.length)) yield l).take(0)
println(rowCount.selectStatement)
val e = for(l<-rowCount.take(0)) yield l> 0
println(e.selectStatement)
但它会生成如下查询:
“行”似乎按预期生成:
select x2."ID", x2."truck_id", x2."pickup", x2."user_uid", x2."user_provider", x2."status" from "Orders" x2`
rowCount 肯定是奇数。
select x2.x3 from (select count(1) as x3 from (select x4."ID", x4."truck_id", x4."pickup", x4."user_uid", x4."user_provider", x4."status" from "Orders" x4) x5) x2 where false -->for "rowcount".
e也是一个邪恶的野兽。
select x2.x3 > 0 from (select count(1) as x3 from (select x4."ID", x4."truck_id", x4."pickup", x4."user_uid", x4."user_provider", x4."status" from "Orders" x4) x5) x2 where false -> huh....weird.
我不太确定,但在我看来,我不太了解聚合/分组函数(例如 count(*))和 Scala 光滑。有人有建议吗?