SELECT posts.id, posts.text, posts.publish_date, posts.draft, posts.published,
    (SELECT json_agg(row_to_json(pictures)) FROM pictures JOIN posts_pictures ON pictures.id = posts_pictures.picture_id WHERE posts_pictures.post_id = posts.id) AS pictures,
    (SELECT json_agg(row_to_json(destinations)) FROM destinations JOIN posts_destinations ON destinations.id = posts_destinations.destination_id WHERE posts_destinations.post_id = posts.id) AS destinations,
    (SELECT json_agg(row_to_json(hashtags)) FROM hashtags JOIN posts_hashtags ON hashtags.id = posts_hashtags.hashtag_id WHERE posts_hashtags.post_id = posts.id) AS hashtags
 FROM posts;

Изменить пасту