Casting a Calculated Column in a MySQL view.
- by Chris Brent
I have a view that contains a calculated column. Is there are a way to cast it as a CHAR or VARCHAR rather than a VARBINARY ? Obviously, I have tried using CAST(... as CHAR) but it gives an error.
Here is a simple replicable example.
CREATE VIEW view_example AS
SELECT concat_ws('_', lpad(9, 3,'0'), lpad(1,3,'0'), date_format(now(),'%Y%m%d%H%i%S'))
AS calculated_field_id;
This is how my view is created:
describe view_example;
+---------------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+---------------+------+-----+---------+-------+
| calculated_field_id | varbinary(27) | YES | | NULL | |
+---------------------+---------------+------+-----+---------+-------+
select version();
+-----------------------+
| version() |
+-----------------------+
| 5.0.51a-community-log |
+-----------------------+