You can not!
CAST and CONVERT only work:
- BINARY [(N)],
- CHAR [(N)],
- DATE
- Datetime
- DECIMAL [(M [, D])]
- SIGNED [INTEGER]
- TIME
- UNSIGNED [INTEGER]
No place for: BIT, BITINT, TINYINT, MEDIUMINT, BIGINT, SMALLINT, ...
However, you can create your own cast_to_bit (n) function:
DELIMITER $$ CREATE FUNCTION cast_to_bit (N INT) RETURNS bit(1) BEGIN RETURN N; END
To try it yourself, you can create a view with several transformations, for example:
CREATE VIEW view_bit AS SELECT cast_to_bit(0), cast_to_bit(1), cast_to_bit(FALSE), cast_to_bit(TRUE), cast_to_bit(b'0'), cast_to_bit(b'1'), cast_to_bit(2=3), cast_to_bit(2=2)
... and then describe it!
DESCRIBE view_bit;
Ted!! Now all the bit (1) !!!
Nuno Rafael Figueiredo
source share