Mega Code Archive

 
Categories / MySQL / Function
 

UPDATE statement moves each bit to the left one position

mysql> mysql> CREATE TABLE Attributes     -> (     ->     UserID SMALLINT NOT NULL PRIMARY KEY,     ->     Settings TINYINT UNSIGNED NOT NULL     -> ); Query OK, 0 rows affected (0.01 sec) mysql> INSERT INTO Attributes VALUES     -> (101, 58),     -> (102, 73),     -> (103, 45); Query OK, 3 rows affected (0.00 sec) Records: 3  Duplicates: 0  Warnings: 0 mysql> mysql> select * from Attributes; +--------+----------+ | UserID | Settings | +--------+----------+ |    101 |       58 | |    102 |       73 | |    103 |       45 | +--------+----------+ 3 rows in set (0.00 sec) mysql> mysql> UPDATE Attributes     -> SET Settings=Settings << 1; Query OK, 3 rows affected (0.00 sec) Rows matched: 3  Changed: 3  Warnings: 0 mysql> mysql> mysql> select * from Attributes; +--------+----------+ | UserID | Settings | +--------+----------+ |    101 |      116 | |    102 |      146 | |    103 |       90 | +--------+----------+ 3 rows in set (0.00 sec) mysql> mysql> drop table Attributes; Query OK, 0 rows affected (0.00 sec) mysql>