问题
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!
回答1:
UPDATE mytable SET foo = CONCAT_WS(',', foo, 'a') WHERE ...
来源:https://stackoverflow.com/questions/17089609/mysql-update-a-set-field-using-named-value-and-bit-operator