0

I'm having the following error:

I have a post form to insert some values to a postgres database using pg-promise. Those values are being converted to integers on the server. But when I try to insert the values to postgres, it says:

 invalid input syntax for integer: ""

What I'm trying to do:

Every field that its left blank, convert it to NULL and insert it to the database, here's the code:

var tier_1 = parseInt(req.body.tier_1);

if (isNaN(tier_1)) {
  console.log("Not a Number");
  tier_1= null;
}

and the query:

  "insert into products(tier_1) values (${tier_1})"

but postgres still reads tier_1 as a string.

Any ideas?

Thank you!

Blinhawk
  • 379
  • 2
  • 7
  • 19
  • Log the actual query you are executing, and then see what your app is doing wrong. For logging query you can use [pg-monitor](https://github.com/vitaly-t/pg-monitor), or event [query](http://vitaly-t.github.io/pg-promise/global.html#event:query), or [as.format](http://vitaly-t.github.io/pg-promise/formatting.html#.format) method. – vitaly-t Jun 26 '18 at 16:11
  • Hi @vitaly-t, figured it out. It has to do with how javascript/express does the post. Thank you! – Blinhawk Jun 26 '18 at 17:14

0 Answers0