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