I have optional double field in my vapor model and if I omit that field when saving model, then database driver spits out:
Uncaught Error: DatabaseError.invalidSQL("ERROR: invalid input syntax for type double precision: \"\"\n"). Use middleware to catch this error and provide a better response. Otherwise, a 500 error page will be returned in the production environment.%
I think the problem is in Database.swift which applies bindings:
for i in 0..<values.count {
var ch = values[i].string?.bytes ?? []
ch.append(0)
The value that is translated from model is Node.Node.null but then the loop itself simply pushes null terminated string back to database, but instead probably should produce NULL to indicate the intention.
I have optional double field in my vapor model and if I omit that field when saving model, then database driver spits out:
I think the problem is in
Database.swift
which applies bindings:The value that is translated from model is
Node.Node.null
but then the loop itself simply pushes null terminated string back to database, but instead probably should produceNULL
to indicate the intention.The query itself is:
Running the following SQL manually works fine:
Spending some time reading through docs revealed that
PQexecParams
converts nil pointer to NULL.Reference: https://www.postgresql.org/docs/9.1/static/libpq-exec.html