Hi Jeremy,

I tried your given example but failed with the following message.
"NoMethodError: undefined method `values' for 
#<Sequel::TinyTDS::Database:....."
is this an adapter-specific error?
>From what I understand, DB is derived from Sequel::Database, but I can't 
find the method "values" documented 
(https://sequel.jeremyevans.net/rdoc/classes/Sequel/Database.html)

Kindly advise.

thank you.

On Sunday, November 7, 2021 at 9:43:56 AM UTC-8 Jeremy Evans wrote:

> 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/3d8167cc-bbef-407a-ad5c-7bdea23ec111n%40googlegroups.com.

Reply via email to