UPDATE with Subqueries

361 views
Skip to first unread message

Sebastian Messmer

unread,
Apr 12, 2014, 12:29:51 PM4/12/14
to scala...@googlegroups.com
I would like to create an SQL statement like

> UPDATE table1 SET field1 = (SELECT field1 FROM table2 WHERE table2.field2=table1.field1 LIMIT 1)

So fill a field of a table with a computed value.

Is this possible in slick? I know updating with static fields like

> Table1.map(_.field1).update(value1)

But I didn't find a way to enter a query there.

If it is not possible in slick, what do you think about implementing it? I think it would be a nice feature to have something like

> Table1.update(Column[T1] => Column[T1])

which would allow me to write

> Table1.update{ entry1 =>
>     Table2.filter(_.field2===entry1.field2)
>  }

Christopher Vogt

unread,
Apr 12, 2014, 2:18:56 PM4/12/14
to scala...@googlegroups.com
Slick currently does not support updating columns using database values
directly. You need to do the on the client side or write it in SQL. I
added your example to the ticket:
https://github.com/slick/slick/issues/497
Reply all
Reply to author
Forward
0 new messages