Bug #15931 Query don't work
Submitted: 22 Dec 2005 9:15 Modified: 22 Dec 2005 12:31
Reporter: Sergey Rudenko Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:4.1.14 OS:Linux (Linux)
Assigned to: CPU Architecture:Any

[22 Dec 2005 9:15] Sergey Rudenko
Description:
I'm run query:

SELECT CAST('1.5' AS DECIMAL(9,3));

MySQL said: 
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECIMAL( 9, 3  )  )' at line 1 

ps: MySQL 4.1.14 

How to repeat:
I'm run query:

SELECT CAST('1.5' AS DECIMAL(9,3));

MySQL said: 
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECIMAL( 9, 3  )  )' at line 1 

ps: MySQL 4.1.14
[22 Dec 2005 12:31] Valeriy Kravchuk
Thank you for a problem report. Sorry, but it is not a bug. CAST to decimal works in MySQL 5:

mysql> SELECT CAST('1.5' AS DECIMAL(9,3));
+-----------------------------+
| CAST('1.5' AS DECIMAL(9,3)) |
+-----------------------------+
|                       1.500 |
+-----------------------------+
1 row in set (0.01 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.0.15-nt |
+-----------+
1 row in set (0.00 sec)

But you can not CAST to DECIMAL in MySQL 4.1.x, according to the manual (http://dev.mysql.com/doc/refman/4.1/en/cast-functions.html):

"The CAST() and CONVERT()  functions can be used to take a value of one type and produce a value of another type.

The type can be one of the following values:

- BINARY (and BINARY[N] as of MySQL 4.1.1)
- CHAR (and CHAR[N] as of MySQL 4.1.1)
- DATE
- DATETIME
- SIGNED [INTEGER]
- TIME
- UNSIGNED [INTEGER]"