Bug #63469 BIT can be cast() but docs does not list it!
Submitted: 29 Nov 2011 9:11 Modified: 7 May 2012 14:07
Reporter: Peter Laursen (Basic Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:5.5.18 - likely any OS:Any
Assigned to: Paul DuBois CPU Architecture:Any
Tags: qc

[29 Nov 2011 9:11] Peter Laursen
Description:
http://dev.mysql.com/doc/refman/5.5/en/cast-functions.html

The CONVERT() and CAST() functions take a value of one type and produce a value of another type.  The type can be one of the following values: 
BINARY[(N)] 
CHAR[(N)] 
DATE 
DATETIME 
DECIMAL[(M[,D])] 
SIGNED [INTEGER] 
TIME 
UNSIGNED [INTEGER]

It seems to work fine with BIT too when cast FROM but not cast TO.

How to repeat:
CREATE TABLE `test`.`TableName1`( 
   `id` INT NOT NULL AUTO_INCREMENT , 
   `b` BIT , 
   PRIMARY KEY (`id`)
 );
 
 INSERT INTO bittest (b) VALUES (b'1'), (b'0');
 
 -- works
 SELECT CAST(b AS UNSIGNED) FROM bittest;
 /*
 cast(b as unsigned)
-------------------
                  1
                  0
 */

-- does not work
SELECT CAST(id AS BIT) FROM bittest;
-- 1064 syntax error

Suggested fix:
This may be a small docs issue only but I am not sure. 

If this cast is safe also this page 
http://dev.mysql.com/doc/refman/5.5/en/bit-field-values.html should ahve added this option to the description as well (ie "To display them in printable form, add 0 or use a conversion function such as BIN()." >> "To display them in printable form, add 0, use a conversion function such as BIN() or CAST() to another datatype.
[29 Nov 2011 9:20] Peter Laursen
The statement "The type can be one of the following values" applies to *target* type. And that is not clear from the text I think.

"The CONVERT() and CAST() functions take a value of *any* type and produce
 a value of another type.  The *result* type can be one of the following values: .." ?
[29 Nov 2011 19:18] Valeriy Kravchuk
Well, based on font style used for "type" word used in that sentence, it refers to second parameter of CONVERT() call specified above and one ca easily guess that it is a target type... But few more words explaining this without relying on font style will not hurt.
[7 May 2012 14:07] Paul DuBois
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant products.