const list = await app.ds.pg.query(`
SELECT sensor_alerts.*, sensor_instances.description, sensor_instances.lastupdated,
json_build_object(
"city": groups.city
"address": groups.address
"country": groups.country
) as groups
FROM sensor_alerts
LEFT JOIN sensor_instances ON sensor_instances.id = sensor_alerts.sensorid
LEFT JOIN groups ON sensor_alerts.groupid = groups.parentid
WHERE sensor_alerts.groupid IN (${where.groupid.join(",")})
ORDER BY sensor_alerts.${sortField} ${sortDirection}
LIMIT $1
OFFSET $2
`, [limit, offset]);
Во-первых, для джуна даже для МСК это что-то много, привирают. Либо не джуны, либо завышают.