Oracle 5.0 Reference Manual page 1029

Table of Contents

Advertisement

+------------+
| VERSION()
|
+------------+
| 4.1.18-log |
+------------+
1 row in set (0.01 sec)
mysql>
CREATE TABLE t SELECT 2.5 AS a, 25E-1 AS b;
Query OK, 1 row affected (0.07 sec)
Records: 1
Duplicates: 0
mysql>
DESCRIBE t;
+-------+-------------+------+-----+---------+-------+
| Field | Type
+-------+-------------+------+-----+---------+-------+
| a
| double(3,1) |
| b
| double
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.04 sec)
As of MySQL 5.0.3, the approximate-value literal is evaluated using floating point, but the exact-value
literal is handled as DECIMAL:
mysql>
SELECT VERSION();
+------------+
| VERSION()
|
+------------+
| 5.0.19-log |
+------------+
1 row in set (0.17 sec)
mysql>
CREATE TABLE t SELECT 2.5 AS a, 25E-1 AS b;
Query OK, 1 row affected (0.19 sec)
Records: 1
Duplicates: 0
mysql>
DESCRIBE t;
+-------+-----------------------+------+-----+---------+-------+
| Field | Type
+-------+-----------------------+------+-----+---------+-------+
| a
| decimal(2,1) unsigned | NO
| b
| double
+-------+-----------------------+------+-----+---------+-------+
2 rows in set (0.02 sec)
Example 7. If the argument to an aggregate function is an exact numeric type, the result is also an
exact numeric type, with a scale at least that of the argument.
Consider these statements:
mysql>
CREATE TABLE t (i INT, d DECIMAL, f FLOAT);
mysql>
INSERT INTO t VALUES(1,1,1);
mysql>
CREATE TABLE y SELECT AVG(i), AVG(d), AVG(f) FROM t;
Before MySQL 5.0.3, the result is a double no matter the argument type:
mysql>
DESCRIBE y;
+--------+--------------+------+-----+---------+-------+
| Field
| Type
+--------+--------------+------+-----+---------+-------+
| AVG(i) | double(17,4) | YES
| AVG(d) | double(17,4) | YES
| AVG(f) | double
+--------+--------------+------+-----+---------+-------+
As of MySQL 5.0.3, the result is a double only for the floating-point argument. For exact type
arguments, the result is also an exact type:
mysql>
DESCRIBE y;
+--------+---------------+------+-----+---------+-------+
| Field
| Type
Precision Math Examples
Warnings: 0
| Null | Key | Default | Extra |
|
| 0.0
|
|
| 0
Warnings: 0
| Null | Key | Default | Extra |
|
| NO
|
| Null | Key | Default | Extra |
|
| NULL
|
| NULL
| YES
|
| NULL
| Null | Key | Default | Extra |
1009
|
|
|
|
| 0.0
|
|
| 0
|
|
|
|
|
|
|
|

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents