天天看点

THINKPHP5.3插入数据库报错。Invalid text representation: 7 ERROR

环境:Centos+thinkphp5.3+pg10

场景:通过thinkphp5.3框架在pg10中添加数据报错:Invalid text representation: 7 ERROR:  invalid input syntax for type integer: "0.5""。通过fetchSql()生成的sql在客户端中执行正常插入。

原因:代码中有添加到pg数据库中的数据是小数,但是数据库该字段设置的类型为int。因此通过框架添加数据小数类型为text添加失败。

修改方式:将字段类型由int改为float4或float8

执行sql:alter table "table_name" alter COLUMN column_name type float4 ;