On Sat, Nov 6, 2021 at 10:40 PM Jiangchuan He <[email protected]> wrote:

> Hi, I'm also looking for this method. I checked around and eventually
> landed here.
>
> I can clarify a little bit. The use case I would like Sequel to support is
> (PostgreSQL, more context
> <https://stackoverflow.com/questions/18797608/update-multiple-rows-in-same-query-using-postgresql>
> )
>
> *update test as t *
> *set column_b = c.column_b*
> *from (values  **(1, '123'), (2, '345') )  **as c(column_a, column_b) *
> *where c.column_a = t.column_a;*
>
> *-- Assume column_a is the primary key.*
>
> Do we have existing Sequel method that can make the query like the above
> ?  As I'm not seeing there's such method in Sequel can do this kind of bulk
> update so far. Would really appreciate if we plan to introduce such feature
> !
>

 You can do this with the dataset methods that ship with Sequel, there is
no need to add anything to support it:

DB.from(Sequel[:test].as(:t), DB.values([[1, '123'], [2, '345']]).as(:c,
[:column_a, :column_b])).
  where{{c[:column_a]=>t[:column_a]}}.
  update(:column_b=>Sequel[:c][:column_b])

UPDATE "test" AS "t"
SET "column_b" = "c"."column_b"
FROM (VALUES (1, '123'), (2, '345')) AS "c"("column_a", "column_b")
WHERE ("c"."column_a" = "t"."column_a")

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 view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/CADGZSSdD8HZ%2BWN28QzQw2FQ%3Dj%3DTzodsTxHVrWwkX-TiFJpah3A%40mail.gmail.com.

Reply via email to