当我尝试使用node-postgres客户端运行此代码时,我得到“错误:没有参数 $1” :
app.post('/newcause', function (req,res){
console.log(req.body);
var g;
var r = [];
for (g in req.body)
{
r[g]=req.body[g];
console.log('r[g] is ' + r[g]);
}
client = pg.connect(connectionString, function(err, client, done){
if(err) console.log(err);
client.query('INSERT INTO causes (cause_name, goal, organization, sponsor, submitter) VALUES ($1,$2,$3,$4,$5)', r, function(err){
console.log('This is r' + r)
if (err) console.log(err);
});
});
});
有什么建议吗?
PS,这是完整的错误声明:
{ [error: there is no parameter $1]
name: 'error',
length: 87,
severity: 'ERROR',
code: '42P02',
detail: undefined,
hint: undefined,
position: '81',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
file: 'parse_expr.c',
line: '812',
routine: 'transformParamRef' }