0
我有一个在psql
中工作的查询,但是当我将它插入到我的REST服务中时,它不起作用。这里是我的代码:查询在psql中工作,但不能与pg.js一起工作
exports.getProjects = function(req, res) {
'use strict';
var query = client.query('select projects.project_id, array_to_string(array_agg(distinct project_subservices.subservice_id), ',') as subservices, array_to_string(array_agg(distinct project_certifications.certification_id), ',') as certifications from projects left outer join project_subservices on projects.project_id = project_subservices.project_id left outer join project_certifications on projects.project_id = project_certifications.project_id group by projects.project_id');
query.on('row', function(row, result) {
result.addRow(row);
});
query.on('end', function(result) {
var finalResult = {};
finalResult.meta = {};
finalResult.meta.count = result.rows.length;
finalResult.projects = result.rows;
res.json(finalResult);
});
};
这是我得到的错误:
/home/jason/Projects/Node/isx_server/node_modules/pg/lib/native/index.js:141
this._sendQueryWithParams(query.text, query.values, query.singleRowMode);
^
Error: Values must be an array
at Connection._pulseQueryQueue (/home/jason/Projects/Node/isx_server/node_modules/pg/lib/native/index.js:141:10)
at Connection.connection.on.clientBuilder.port (/home/jason/Projects/Node/isx_server/node_modules/pg/lib/native/index.js:241:18)
at Connection.EventEmitter.emit (events.js:93:17)
我可以剪切此代码粘贴到psql
和它的作品找到。 2个环境中会导致查询不起作用的区别是什么?我如何完成这项工作?谢谢您的帮助。
请向我们展示您的代码!但无论如何,你的问题似乎是你传递给'sendQueryWithParams'的一个参数('query.value'),它期望它是一个数组,但事实并非如此。 –
我添加了完整的代码。 – jhamm