Answer the question
In order to leave comments, you need to log in
How to put the result of an sql query into an object?
Hello.
The crux of the matter, I'm doing a sql query, here it is
SELECT sensor_alerts.*, sensor_instances.description,
sensor_instances.lastupdated, groups.address,
groups.city, groups.country
FROM sensor_alerts
LEFT JOIN sensor_instances ON sensor_instances.id = sensor_alerts.sensorid
LEFT JOIN groups ON sensor_alerts.groupid = groups.parentid
{
description: 1321231231
city: asdad
addres: asgs
country: sфывфы
}
{
description: 1321231231
groups: {
city: asdad
addres: asgs
country: sфывфы
}
}
Answer the question
In order to leave comments, you need to log in
SELECT
sensor_alerts.*,
sensor_instances.*,
json_agg(groups.*) 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
GROUP BY sensor_alerts.id; --- скорее всего группировка не обязательна
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question