id: 1
name: Товар 1
id: 1
product_id: 1
url: 'example.png'
id: 2
product_id: 1
url: 'example2.png'
[
{
id: 1,
name: 'Товар 1',
photos: [
{
id: 1,
url: example.png'
},
{
id: 2,
url: example2.png'
}
]
}
]
select products.id, products.name, jsonb_agg(url)
from products
left join products_photos on products.id = product_id
group by products.id, products.name
|----|---------|----------------------------------|
| id | name | jsonb_agg |
|----|---------|----------------------------------|
| 1 | Товар 1 | ["example1.png", "example2.png"] |
(product_)id, (product_)name, (photo_)id, (photo_)url
1, 'Товар 1', 1, 'example.png'
1, 'Товар 1', 2, 'example2.png'