No worries, thanks for the feedback!

Lukas

2015-12-05 18:42 GMT+01:00 <[email protected]>:

> Hi Lukas. Sorry, I didn't receive any email notification and just saw your
> reply. Thanks for the clarification! I tried out your suggestion and it
> works great.
>
> On Sunday, November 1, 2015 at 6:02:57 AM UTC-5, Lukas Eder wrote:
>>
>> Hello,
>>
>>
>> 2015-10-31 17:23 GMT+01:00 <[email protected]>:
>>
>>> Hi. I would like to update multiple rows in my DB, using a single query.
>>>
>>> I've found a SQL solution that I'd like to implement, as detailed here:
>>>
>>> http://stackoverflow.com/questions/20255138/sql-update-multiple-records-in-one-query
>>>
>>> UPDATE config
>>>    SET config_value = CASE config_name
>>>                       WHEN 'name1' THEN 'value'
>>>                       WHEN 'name2' THEN 'value2'
>>>                       ELSE config_value
>>>                       END
>>>  WHERE config_name IN('name1', 'name2');
>>>
>>>
>> This would be the equivalent jOOQ query:
>>
>>
>> DSL.using(configuration)
>>
>>    .update(CONFIG)
>>
>>    .set(CONFIG.CONFIG_VALUE, choose(CONFIG.CONFIG_NAME)
>>
>>                               .when("name1", "value")
>>
>>                               .when("name2", "value2")
>>
>>                               .otherwise(CONFIG.CONFIG_VALUE))
>>
>>    .where(CONFIG.CONFIG_NAME.in("name1", "name2"))
>>
>>    .execute();
>>
>>
>> "choose" is static-imported from org.jooq.impl.DSL.choose
>>
>> Some nuances: for my use case, the update-values aren't static constants.
>>> They are increments to existing DB values. Eg:
>>> WHEN 'name1' THEN (config_value + ' new_value')
>>>
>>
>> No problem. I'm assuming that your + is the concatenation operator, e.g.
>> in SQL Server. Just change the previous query into:
>>
>>                               .when("name1", CONFIG.CONFIG_VALUE.concat("
>> new_value"))
>>
>> Hope this help,
>> Lukas
>>
> --
> You received this message because you are subscribed to the Google Groups
> "jOOQ User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

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

Reply via email to