简体   繁体   中英

Postgres error: syntax error at or near “,”

i'm try to find error from my code but i dont know what i wrong. Can Anyone see some error on it?

const {Client} = require('pg');
const client = new Client({
user: 'me',
host: 'localhost',
database: 'printer',
password: '1234',
port: 5432,
});

client.connect(function(err){
if (err) throw err
console.log("Connected Successfuly");
console.log("****if you want to stop this service, press Ctrl + C****");

var datain ='{"filename" : "filetest01.pdf","printer" : "Microsoft Print to PDF","address" : "C:\\Users\\parun\\Desktop\\printer\\printerserver\\photo","date" : "2020-11-23T17:00:00.000Z","status" : 1}';
var sql = 'INSERT INTO print(filename, printer, address, date, status) VALUES(?, ?, ?, ?, ?)';

client.query(sql, [datain.filename, datain.printer, datain.address, datain.date, datain.status],(err, result) => {
        if (err)
            throw err;
        console.table(result.rows);
    });
});

change your sql

var sql = 'INSERT INTO print(filename, printer, address, date, status) VALUES($1, $2, $3, $4, $5)';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM