I have a two tables like the following:
workshops table
+----+--------------+------------+
| id | name | option_ids |
+----+--------------+------------+
| 1 | Conversation | {2,3} |
+----+--------------+------------+
options table
+----+-----------+---------------+
| id | day | time |
+----+-----------+---------------+
| 1 | Monday | 13:00 - 14:00 |
| 2 | Tuesday | 12:00 - 13:00 |
| 3 | Wednesday | 11:00 - 12:00 |
+----+-----------+---------------+
I want to construct a Query where I retrieve the workshop name and also all the information for option_ids 2 and 3.
I would like to eventually construct a JSON like so:
{
name: "Conversation",
options: [
{ day: "Tuesday", time: "12:00 - 13:00" },
{ day: "Wednesday", time: "11:00 - 12:00" }
]
}
Looking at the postgresql.org documentation maybe it has something to do with the json_object
function?