例如,我有這個簡化的模型,其中時間戳和持續時間均表示秒。如何使用算術運算對不同類型的列進行算術運算過濾3 3
case class Item(id: Int, : Long, duration: Int)
val max_timestmap: Long = ??? val stmt = items.filter(x => (x.timestamp + x.duration) <= max_timestamp) db.run(stmt.result)
上面會不會與下面的錯誤,我有很難理解編譯。
ambiguous implicit values: [error] both value BooleanOptionColumnCanBeQueryCondition in object CanBeQueryCondition of type => slick.lifted.CanBeQueryCondition[slick.lifted.Rep[Option[Boolean]]] [error] and value BooleanCanBeQueryCondition in object CanBeQueryCondition of type => slick.lifted.CanBeQueryCondition[Boolean] [error] match expected type slick.lifted.CanBeQueryCondition[Nothing] [error] filter(x => (x.timestamp + x.duration) <= max_timestamp)
更新1: 好像問題源於一個事實,即timestamp
長,duration
是詮釋。當兩者都是相同的數據類型時,它似乎可以編譯。
更新2: 我發現此解決方案的工作。使用x.duration.asInstanceOf[Rep[Long]]
或可能更合適x.duration.asColumnOf[Long]
'(p => p.age <= 23)'是否有效?你不錯過進口? – nmat
持續時間是一個int?這是什麼意思,分鐘數,秒數,小時數?只需將所有內容轉換爲相同類型 – nmat
是的,持續時間以秒爲單位,並且在表格中以這種方式表示。是否可以在不改變表中的當前數據類型的情況下進行轉換? –