SELECT posts.id, posts.text, posts.publish_date, posts.draft, posts.published,
          (SELECT json_agg(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(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(hashtags) FROM hashtags JOIN posts_hashtags ON hashtags.id = posts_hashtags.hashtag_id WHERE posts_hashtags.post_id = posts.id) AS hashtags
          FROM posts ORDER BY posts.id DESC

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