Casting a Calculated Column in a MySQL view.

Posted by Chris Brent on Stack Overflow See other posts from Stack Overflow or by Chris Brent
Published on 2010-06-02T05:49:33Z Indexed on 2010/06/02 5:53 UTC
Read the original article Hit count: 186

Filed under:

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 |
+-----------------------+

© Stack Overflow or respective owner

Related posts about mysql