MariaDB Knowledge Base Comments for: FIND_IN_SEThttps://mariadb.com/kb/en/find_in_set/+comments/feed/en-usFri, 11 Oct 2024 02:12:20 +0000Re: FIND_IN_SEThttps://mariadb.com/kb/en/find_in_set/+comments/6381<p>if you wish to update a record and remove an element from a SET, you can't use UPDATE my_table SET my_col = my_col - 'element_to_remove' and you can't use UPDATE my_table SET my_col = my_col - FIND_IN_SET('element_to_remove',my_col)</p>
<p>Rather, you must use bit arithmetic this way:
UPDATE my_table SET my_col = my_col - floor(pow(2,find_in_set('element_to_remove',my_col)-1))</p>
<p>Here is a breakdown:
1. find_in_set() will return the position of 'element_to_remove' in my_col, starting at 1
2. since bit arithmetic is starting at 0, you must remove 1
3. converting that number to a power of 2 with pow()
4. taking the floor in case 'element_to_remove' isn't present in my_col to start with, which gives pow(2,-1) = 0.5 so the floor of that is zero</p>
Android Marchandhttps://mariadb.com/kb/en/find_in_set/+comments/6381Re: FIND_IN_SEThttps://mariadb.com/kb/en/find_in_set/+comments/1680<p>how can i do it for script:
select Patindex('%[^-.0-9]%', atexthours + 'x');</p>
Adrian Hastrohttps://mariadb.com/kb/en/find_in_set/+comments/1680