I have a table of values, with one of the columns being of type SET.
If it currently has the members ('a', 'b', 'c', 'd'), how do I add 'e' to the possible values?
I realize that using a SET type is a little strange, and I'm unclear why one would use it instead of a foreign key to another table with the values of the set, but I didn't design the database in question, and can't change it that much.
Thanks for your help!
UPDATE: I want to update the SET type for all rows, not just one, if that helps.
6 The SET Type. A SET is a string object that can have zero or more values, each of which must be chosen from a list of permitted values specified when the table is created. SET column values that consist of multiple set members are specified with members separated by commas ( , ).
The MySQL SET datatype allows us to compare multiple values without using complex JOIN operations. We can manipulate the set with binary functions to do complex comparisons by comparing bit values on a single column instead of comparing multiple rows of multiple tables.
To add an element to an existing SET use the CONCAT() function to add the new element to your comma separated list. To work with decimal values, we can use the bitwise OR operator |.
UPDATE set_test SET myset = CONCAT(myset,",Travel")
WHERE rowid = 3;
or
UPDATE set_test SET myset = myset | 1 WHERE rowid = 3;
You can also use the CONCAT_WS() function, which handles list separators for us:
UPDATE set_test SET myset = CONCAT_WS(',',myset,'Dancing')
WHERE rowid = 6;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With