I get “error: there is no parameter $4” when I try to run this code using node-postgres
I hope maybe someone can help
I have checked and the id exists in the database The param is logged in the console so it works
const updateUser = async (req, res) => {
const id = parseInt(req.params.id);
const {username, email, isadmin} = req.body;
console.log(id);
try{
pool.query(`UPDATE users SET username = $1, email = $2, isadmin = $3 WHERE id = $4`), [username, email, isadmin, id], (err, results) => {
if(err) {
throw err;
}
res.status(200).send(`User updated with ID: ${id}`)
}
} catch (err) {
throw err;
}
}
error message:
Server running on port 4001
7
C:\Users\Elisabeth\node_modules\pg-protocol\dist\parser.js:287
const message = name === 'notice' ? new messages_1.NoticeMessage(length, messageValue) : new messages_1.DatabaseError(messageValue, length, name);
^
error: there is no parameter $4
at Parser.parseErrorMessage (C:\Users\Elisabeth\node_modules\pg-protocol\dist\parser.js:287:98)
at Parser.handlePacket (C:\Users\Elisabeth\node_modules\pg-protocol\dist\parser.js:126:29)
at Parser.parse (C:\Users\Elisabeth\node_modules\pg-protocol\dist\parser.js:39:38)
at Socket.<anonymous> (C:\Users\Elisabeth\node_modules\pg-protocol\dist\index.js:11:42)
at Socket.emit (node:events:537:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
length: 94,
severity: 'ERROR',
code: '42P02',
detail: undefined,
hint: undefined,
position: '69',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_expr.c',
line: '845',
routine: 'transformParamRef'
}