I am trying to insert the date it was created on into a table and I'm getting an error, here is the code:
const cs = 'site';
const client = new Pool({
cs,
user: 'user',
host: 'host',
database: 'database',
password: 'password',
port: 5432,
ssl: {
rejectUnauthorized: false
}
});
//to get rid of the T
var d = new Date().toISOString().replace(/T/, " ");
//to get rid of the .Z something
var e= d.substr(0, 19);
console.log(e);
const value= `INSERT INTO price(created_on,something1, something2)VALUES(${e},1,1)`;
client.query(
value,
(err, res) => {
console.log(err, res);
client.end();
}
);
when I look at the result in the console it says 2021-03-14 16:25:05, yet it gives me a
error: syntax error at or near "16"
What am I doing wrong?
you need to quote the date value:
const value= `INSERT INTO price(created_on,something1, something2)VALUES('${e}',1,1)`;
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.