Update from select?

38 views
Skip to first unread message

ÆtherSurfer

unread,
Jun 2, 2015, 6:21:05 PM6/2/15
to squ...@googlegroups.com
Given a table:
╔════╦═════════╦═════╗
║ id ║ prev_id ║ foo ║
╠════╬═════════╬═════╣
║  1 ║         ║ bar ║
║  2 ║       1 ║     ║
╚════╩═════════╩═════╝

How do I do the following query in squeryl?

UPDATE widgets 
SET 
  widgets.foo = 
    (
     SELECT widgets.foo
     FROM widgets 
     WHERE widgets.id = 1
    )
WHERE
    widgets.id = 2

Reference:
http://stackoverflow.com/questions/29808430/squeryl-update-from-select

ÆtherSurfer

unread,
Jun 11, 2015, 10:44:37 AM6/11/15
to squ...@googlegroups.com
I eventually settled on this workaround

update(widgets) (
  w=>
    where(w.id === 2)
    set(w.foo := from(widgets)(prevW => where(prevW.id === 1) compute(min(foo))))
)

David Whittaker

unread,
Jun 11, 2015, 11:07:42 AM6/11/15
to squ...@googlegroups.com
Thanks for updating the thread.

-Dave

--
You received this message because you are subscribed to the Google Groups "Squeryl" group.
To unsubscribe from this group and stop receiving emails from it, send an email to squeryl+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages