We have something like the following PDO Statement which we use to communicate with a PostgreSQL 8.4 DB.
$st = $db -> prepare("INSERT INTO Saba.Betriebskosten (personalkosten)
VALUES(:kd_personalkosten)");
$st -> bindParam(':kd_personalkosten', $val['kd_personalkosten']);
$val['kd_personalkosten'] is either empty/null or contains a double value. In the case it is empty/null, we just want to insert an empty value, but we receive the following error:
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type double precision: '';
Which means that empty/null is converted to an empty STRING which is not compatible with the double precision field. How to circumvent this error?
PostgreSQL 8.4accept NULL values for double precision ?thevalid value for an empty string converting it to a numeric is OK. But if empty string means no value you should store it as NULL as Ivan suggested. Obviously this will mean re- defining the field.If this is not possible you might be able to use a numeric value that is meaningless to your application.eg 99999.999