I have a function that records working data. Then I insert this array into the request.
async function setJobs(jobs) {
const insertFieldsOfJob = [];
for (const key of jobs) {
const jobFields = [
`'${key.job_id}'`,
`'${key.description}'`,
`'${key.verified}'`,
`'${key.amount}'`,`,
`'${key.title}'`,
`'${key.ctime}'`,
];
insertFieldsOfJob.push(`(${jobFields})`);
};
const jobsIds = (await db.query(Jobs.writeJobs(insertFieldsOfJob))).rows;
return jobsIds;
};
Here I am writing to the job details database
class Job {
static writeJobs(jobsDetails) {
const sql = `INSERT INTO JOBS (JOB_ID, DESCRIPTION, VERIFIED, AMOUNT, TITLE, CTIME)
VALUES
${jobsDetails}
RETURNING ID`
return sql;
}
}
module.exports = Job;
I get data
jobs {
job_id: 1,
description: test,
verified: false,
amount: 500.00,
title: test,
ctime: 1564461408000,
}
And I get errors
error: invalid integer value: "500.00"
error: the value "1564461408000" is out of range for type integer
Why it happens? I refer to the properties of the object as a string.
Inttype to your columns when you should be givingFloat / Doubleforamountandtimestamp / date-timeforctimedepending upon your DB.varchar 220