Warning: Data truncated for column 'AirPress' at row 1

简介: /************************************************************************ * Warning: Data truncated for column 'AirPress' at row 1 * 说明: * 最近往MySQL中存入数据时,总是看到这个Warning,花点时间来找一下原因。
/************************************************************************
 *       Warning: Data truncated for column 'AirPress' at row 1
 * 说明:
 *     最近往MySQL中存入数据时,总是看到这个Warning,花点时间来找一下原因。
 *
 *                                      2016-10-20 深圳 南山平山村 曾剑锋
 ***********************************************************************/

一、参考文档:
    python float类型转string类型,要求精度不能丢失!!!
        http://bbs.csdn.net/topics/390236828

二、原因解析:
    1. MySQL中对应的字段中采用类型是:decimal(18,4);
    2. Python中对应的字段采用float类型;
    3. 将float类型变量直接通过str()函数存入MySQL字段中会出现类似如下警告:
        Warning: Data truncated for column 'AirPress' at row 1
    4. 将[str()]函数换成["%.4f" % 变量名]就可避免;
    5. 原因是str()转换出来float类型数据精度大于4,造成数据被truncated。

 

目录
相关文章
|
7月前
|
存储 SQL 关系型数据库
【MySQL异常】Row size too large (> 1982). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNA
【MySQL异常】Row size too large (> 1982). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNA
63 0
|
关系型数据库 MySQL 数据库
MySQL新增字段报错:ERROR 1118 -- Row size too large. The maximum row size for the used table type
MySQL新增字段报错:ERROR 1118 -- Row size too large. The maximum row size for the used table type
1485 0
|
1月前
|
索引 Python
row[i] = col[j] = TrueIndexError: list assignment index out of range
row[i] = col[j] = TrueIndexError: list assignment index out of range
|
11月前
|
数据库
Data truncation: Incorrect date value: ‘2022-11-28T16:00:00.000Z‘ for column ‘start_date‘ at row 1
Data truncation: Incorrect date value: ‘2022-11-28T16:00:00.000Z‘ for column ‘start_date‘ at row 1
187 0
|
存储 关系型数据库 MySQL
MySQL出现Data too long for column...(错误号1406)和 Data truncated for column...(错误号1265)
MySQL出现Data too long for column...(错误号1406)和 Data truncated for column...(错误号1265)
602 0
MySQL出现Data too long for column...(错误号1406)和 Data truncated for column...(错误号1265)
|
SQL Java 数据库连接
JPA异常:Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
JPA异常:Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
1763 0
|
SQL 关系型数据库 MySQL
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
882 0
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
|
数据库
Data truncation: Out of range value for column ‘estimate_score‘
Data truncation: Out of range value for column ‘estimate_score‘