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

久未见 提交于 2020-06-28 10:20:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!