I have a query that works in psql, but when I insert it into my REST service it doesnt work. Here is my code:
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);
});
};
Here is the error I get:
/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)
I can cut and paste this code into psql and it works find. What is the difference in the 2 environments that will cause the query not to work? How do I make this work? Thanks for the help.
sendQueryWithParamsan argument (query.value), that it expects it to be an array, but it's not.