Compose “Insert…Select…Where” query

ε祈祈猫儿з 提交于 2019-12-19 19:46:23

问题


I'm trying to compose a query using Slick 3.0, but can't seem to figure it out.

The equivalent SQL is "insert into SavedMail select * from Inbox where Inbox.id = 1"

val mailTable = TableQuery[Tables.Inbox]
val savedMailTable = TableQuery[Tables.Savedmail]
val select = mailTable.filter(_.id === msgId)

I'm stuck on how to do the insert now. Help appreciated.


回答1:


Here's a solution I've come up with. Perhaps there's a way to not use forceInsertQuery, but hey, this works.

val mailTable = TableQuery[Tables.Inbox]
val savedMailTable = TableQuery[Tables.Savedmail]

val select = mailTable.filter(_.id === msgId).map(c => (c.id, c.touserid, c.fromuserid, c.mailtype, c.subject, c.msg, c.postdate))
val q = savedMailTable.map(c => (c.id, c.touserid, c.fromuserid, c.mailtype, c.subject, c.msg, c.postdate)) forceInsertQuery select


来源:https://stackoverflow.com/questions/31347462/compose-insert-select-where-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!