Warning
Error Code: 3858

MySQL Error 3858: Deprecated Float Precision

📦 MySQL
📋

Description

This warning indicates that you are attempting to define a floating-point data type (like `FLOAT` or `DOUBLE`) with an explicit total number of digits (M) and decimal places (D). MySQL considers this syntax deprecated and plans to remove support for it in future releases. While operations might succeed currently, this will lead to errors in newer versions.
💬

Error Message

Specifying number of digits for floating point data types is deprecated and will be removed in a future release.
🔍

Known Causes

4 known causes
⚠️
Creating Tables with Deprecated Syntax
A `CREATE TABLE` statement includes column definitions using the deprecated `FLOAT(M,D)` or `DOUBLE(M,D)` syntax.
⚠️
Altering Columns with Deprecated Syntax
An `ALTER TABLE` statement attempts to modify an existing column to use the deprecated `FLOAT(M,D)` or `DOUBLE(M,D)` precision specification.
⚠️
Legacy SQL Scripts or Migration
Executing older SQL scripts, importing a legacy database dump, or using migration tools that generate column definitions with the deprecated floating-point syntax.
⚠️
Application-Generated Schema
An Object-Relational Mapper (ORM) or other application framework is configured to generate `CREATE` or `ALTER` statements that include the deprecated `FLOAT(M,D)` or `DOUBLE(M,D)` syntax.
🛠️

Solutions

3 solutions available

1. Remove Precision from Existing FLOAT/DOUBLE Columns easy

Modify your table schema to remove the deprecated precision specifiers from FLOAT and DOUBLE columns.

1
Identify all tables and columns that use `FLOAT(M)` or `DOUBLE(M, D)` syntax. You can use a query like this to help find them:
SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, DATA_TYPE, COLUMN_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE DATA_TYPE IN ('float', 'double')
  AND COLUMN_TYPE LIKE 'float(%,%') OR COLUMN_TYPE LIKE 'double(%,%');
2
For each identified column, alter the table to remove the precision. For example, if you have a column `price FLOAT(10, 2)`, change it to `price FLOAT`.
ALTER TABLE your_table_name MODIFY COLUMN your_column_name FLOAT;
3
If the column was `DOUBLE(M, D)`, change it to `DOUBLE`.
ALTER TABLE your_table_name MODIFY COLUMN your_column_name DOUBLE;
4
Repeat for all affected columns across your database.

2. Update Data Definition Language (DDL) Scripts easy

Modify your database creation and alteration scripts to use the standard FLOAT and DOUBLE definitions.

1
Locate your SQL scripts used for creating tables or altering schemas.
2
Find any instances where `FLOAT(M, D)` or `DOUBLE(M, D)` are used and change them to `FLOAT` or `DOUBLE` respectively. For example, change `price FLOAT(10, 2)` to `price FLOAT`.
-- Before:
CREATE TABLE products (
    id INT PRIMARY KEY,
    name VARCHAR(255),
    price FLOAT(10, 2)
);

-- After:
CREATE TABLE products (
    id INT PRIMARY KEY,
    name VARCHAR(255),
    price FLOAT
);
3
Ensure that when applying these scripts (e.g., during deployments or database migrations), you are using the updated versions.

3. Consider DECIMAL for Precise Monetary Values medium

For scenarios requiring exact decimal representation, such as financial data, switch from FLOAT/DOUBLE to DECIMAL.

1
Identify columns that store monetary values or require exact decimal precision. These are prime candidates for `DECIMAL`.
2
Determine the appropriate precision (total number of digits) and scale (number of digits after the decimal point) for your `DECIMAL` columns. For example, `DECIMAL(10, 2)` can store values up to 99,999,999.99.
3
Alter your tables to replace `FLOAT` or `DOUBLE` columns with `DECIMAL` columns. For instance, change `price FLOAT` to `price DECIMAL(10, 2)`.
ALTER TABLE your_table_name MODIFY COLUMN your_column_name DECIMAL(10, 2);
4
Be aware that `DECIMAL` can be slower for calculations compared to `FLOAT`/`DOUBLE` but offers exactness.
🔗

Related Errors

5 related errors