On Friday, December 15, 2017 at 2:13:06 AM UTC-8, Emil Ahlbäck wrote:
>
> Hello everyone
>
> I'm struggling to find the right documentation to accomplish an update 
> query which performs updates on many rows in one go. The equal SQL 
> statement looks like this:
>
> UPDATE order_lines AS ol
>   SET ol.material_cost = val.material_cost 
> FROM ( 
>  VALUES (1, 150), (2, 320) 
> ) AS val(id, material_cost) 
> WHERE ol.id = val.id;
>
>
> I'm right now resorting to string interpolation and raw SQL to perform 
> this query but I'd like to write things a little bit more elegant. I'd be 
> very thankful for pointers to the right piece of documentation!
>

Here you go: 

DB.from(Sequel[:order_lines].as(:ol), DB.values([[1, 150], [2, 
320]]).as(:val, [:id, :material_cost])).
  where{ol[:id] =~ val[:id]}.
  update(Sequel[:ol][:material_cost] => Sequel[:val][:material_cost]) 

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to