I'm working on a web app using React, Node, Express, Massive, and PostgreSQL, and having trouble performing one specific query:
SELECT
COUNT(DISTINCT cu.user_id) AS ucount,
COUNT(DISTINCT p.project_id) AS pcount,
COUNT(DISTINCT t.task_id) AS tcount,
c.clique_id, c.clique_name, c.admin_id, c.created_on
FROM cliques c
FULL OUTER JOIN cliques_users cu ON cu.clique_id = c.clique_id
FULL OUTER JOIN users u ON u.user_id = cu.user_id
FULL OUTER JOIN projects p ON p.clique_id = cu.clique_id
FULL OUTER JOIN tasks t ON t.clique_id = cu.clique_id
WHERE c.clique_id IN (
SELECT cu.clique_id FROM cliques_users cu WHERE cu.user_id = 3
)
GROUP BY c.clique_id;
**Note: I'm using 3 on the subquery just to test.
I'm using Postico to test my SQL statements, and this query returns the results I expect. But when this is done on the app itself, requesting the data by hitting an endpoint, the server throws an error:
{ error: function count(integer) does not exist at ...
name: 'error',
length: 225,
severity: 'ERROR',
code: '42883',
detail: undefined,
hint: 'No function matches the given name and argument types. You might need to add explicit type casts.',
position: '55',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_func.c',
line: '528',
routine: 'ParseFuncOrColumn' }
The callback function that runs when the endpoint is hit looks like this:
(req, res, next) => {
req.app.get( 'db' )
.clique.getCliqueSummaryQuery( req.params.user_id )
.then( response => {
res.status(200).json(response);
})
.catch( err => {
console.log( 'getMyCliquesInfo failed: ', err );
res.status(500).json( err );
});
}
getCliqueSummaryQuery() runs the query, passing a url parameter as a variable that will replace the 3 I've hardcoded for testing. The error occurs with both variable and hardcoded values. I've copied the query straight from Postico to my sql file.
Anyone know why it works one way and not the other?