I'm wondering if it's possible to return a list of results as a JSON object. My query is more complex than the below lets on but for the sake of simplicity express what I'm aiming for.
SELECT
r.name, r.address
FROM "Locations" AS r
LEFT JOIN "Units" AS f
ON r.city = f.city
There are many potential Units per location but it would be great of those came back as JSON as opposed to modifying my full table structure.
So the response I'm looking for is one row for each location with the columns: name (string), address (string) and units (JSON representing all the rows).
This would never be possible in MySQL, wondering if I can do it in Postgres. The data that will be JSONd isn't large so I'm not too concerned about performance.