在子查询中重新滑动表格

时间:2016-10-31 15:28:30

标签: scala slick-3.0

我试图在光滑3中使用子查询来删除具有复合键的表中的行(key:String,ts:Timestamp),以便删除旧记录,但保留每个密钥至少一个。它几乎从这个scala代码中得到了正确的结果:

tq这里是TableQuery对照表格" a"和 minTimestamp是一个时间戳,在此之前应删除记录:

tq.filter(row => (row.ts < minTimestamp && row.ts =!= (
  tq.filter(filterRow => filterRow.key === row.key).map(_.ts).max
))).delete

但在执行子查询时,它不会重命名表并删除除整个表的max(ts)之外的所有行。它生成的查询是:

delete from "a" where ("a"."ts" < '2016-10-31 13:53:39.203') and (not (
  "a"."ts" = (select max("ts") from "a" where "a"."key" = "a"."key")
))

如何让它重命名子查询中的表,以便查询类似于:

delete from "a" where ("a"."ts" < '2016-10-31 13:53:39.203') and (not (
  "a"."ts" = (select max("ts") from "a" as "x" where "x"."key" = "a"."key")
))

0 个答案:

没有答案