MegaTux MegaTux - 4 months ago 12
Ruby Question

Ruby Sequel gem: update a row column with a value from another row column that I know the Id

How to write this using the Sequel gem? :

update table set col = (select col from table where id = :x) where id = :y


I have the record with
id=:y
but I want to avoid retrieving the record with
id(:x)
and then doing the update. Just one step!
Do I have to use raw sql (
DB.run()
)?

Answer
DB[:table].where(:id=>y).update(:col=>DB[:table].where(:id=>x).select(:col))
Comments