I have a MySQL table, let’s call it Permissions, with numeric columns UserId and Privilege. The UserId column is considered to be a decimal value, but Privilege is supposed to be a hexadecimal value. The hexadecimal values are better for privilege codes (because every privilege bit is responsible for the flags like R, W, X and so on), and this is widely used by us for the INSERT statements using the hexadecimal literals, e.g.:
INSERT INTO `Permissions` (`UserId`, `Privilege`) VALUES (12, 0x53);
Let’s assume that 3 in 0x53 is a flag mask standing for encoded privilege actions, so a person who read such an INSERT statement can easily understand that this permission grants R(1) and W(2) permissions. But when the query to the Permissions table is executed, e.g. in native MySQL client, the privilege value is shown as decimal (please assume SELECT * FROM):
+--------+-----------+
| UserID | Privilege |
+--------+-----------+
| 12 | 83 |
+--------+-----------+
Is there a way to recommend MySQL clients to display (not return as strings) some numeric columns in hexadecimal view by default? It probably might be somewhere in table metadata, hmmm, “recommendations” or somewhere in clients configs – honestly, I have no any idea on that. Another reason of why this is useful is that it could be possible to use simple SELECT * FROM query not applying the HEX() function for a certain column every time you invoke the query, where HEX() even changes the result set column type from number to string.
Any ideas? Your help would be really appreciated. Thanks in advance.
P.S. I’m not sure if this question should be asked here. If a better place is at SuperUser or Database Administrators, please migrate. Thanks!
It seems that a VIEW would be what you want. Just select all of the columns, specifying HEX(Permissions) as Permissions, and tell clients to use the view instead of the table.
http://dev.mysql.com/doc/refman/5.5/en/create-view.html