Bug #34564 CAST does not accept varchar type
Submitted: 14 Feb 2008 20:20 Modified: 24 Mar 2008 10:25
Reporter: Ken Johanson
Status: Verified
Category:Server: Types Severity:S3 (Non-critical)
Version:5.1.22-rc-log OS:Any
Assigned to: Alexey Kopytov Target Version:
Tags: STANDARDS
Triage: Triaged: D3 (Medium)

[14 Feb 2008 20: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 20: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 23: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 6:50] Valeriy Kravchuk
OK. But in any case, please, do not expect any changes in CAST soon.