I am inserting a floating point number in a table using libpq
. I am getting this error INSERT failed: ERROR: insufficient data left in message
.
Here is the corresponding snippet from my code base:
printf ("Enter write parameter_value");
scanf("%f", ¶meter_value);
char *stm = "INSERT INTO write_reg_set (parameter_value) VALUES ($1::double precision)";
int nparam = 1;
//set the values to use
const char *values[1] = {(char *)¶meter_value};
//calculate the lengths of each of the values
int lengths[1] = {sizeof(parameter_value)};
//state which parameters are binary
int binary[1] = {1};
PGresult *res = PQexecParams(conn,
stm,
nparam, //number of parameters
NULL, //ignore the Oid field
values, //values to substitute $1 and $2 and so on
lengths, //the lengths, in bytes, of each of the parameter values
binary, //whether the values are binary or not
0); //we want the result in text format
if (PQresultStatus(res) != PGRES_COMMAND_OK) {
fprintf(stderr, "INSERT failed: %s", PQerrorMessage(conn));
exit_nicely(conn,res);
}
PQclear(res);