Bernim
Bernim

Reputation: 68

MySQL: Update a SET field using named value and bit-operator

For MySQL, is it possible to update a field of type SET using one of the field's named values and bitwise operators? Example:

Assume foo to be SET('a', 'b',...), then the following does not work:

UPDATE mytable SET foo = foo | 'a' WHERE ...

Apparently, only foo = 'a' or foo = foo | 1 work. Is there any trick to get the above example working and make MySQL be aware of 'a' being not a "normal" string? I'd like to avoid magic numbers... Many thanks!

Upvotes: 1

Views: 399

Answers (1)

eggyal
eggyal

Reputation: 125925

UPDATE mytable SET foo = CONCAT_WS(',', foo, 'a') WHERE ...

Upvotes: 2

Related Questions