Bug #34564 CAST does not accept varchar type
Submitted: 14 Feb 2008 19:20 Modified: 24 Mar 2008 9:25
Reporter: Ken Johanson Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Parser Severity:S3 (Non-critical)
Version:5.1.22-rc-log OS:Any
Assigned to: CPU Architecture:Any
Tags: STANDARDS

[14 Feb 2008 19:20] Ken Johanson
Description:
Cast should accept varchar ar the target type:

SELECT CAST(123 AS varchar) -> "...syntax to use near 'varchar)'"
SELECT CAST(CURRENT_TIMESTAMP() AS varchar) -> "...syntax to use near 'varchar)'"
SELECT CAST(123 AS char) -> OK

How to repeat:
> SELECT CAST(123 AS varchar);
[14 Feb 2008 19:53] Valeriy Kravchuk
Thank you for a problem report. As current implementation is documented at http://dev.mysql.com/doc/refman/5.1/en/cast-functions.html#function_cast, I'd say this is just a reasonable and high priority feature request.
[14 Feb 2008 22:31] Ken Johanson
I must plea for changing this back to a bug. This is a sql non-conformace issue, and there is no portable and spec-compliant way to return an numeric type as varchar in Mysql right now. "CAST(n AS char)" works in Mysql but is technically not correct, and not consistent with other databases. Other DBs also do not support autocast (spec does not require it), so TRIM() etc are not portable.
[15 Feb 2008 5:50] Valeriy Kravchuk
OK. But in any case, please, do not expect any changes in CAST soon.
[18 May 2012 14:25] nicolas diogo
yep, there has being no change so far.