SELECT messages.*,
        row_to_json(users.*) as user,
        row_to_json(channels.*) As channel
    FROM messages
LEFT JOIN users ON messages.user_id = users.id
LEFT JOIN channels ON messages.channel_id = channels.id 
WHERE messages.id=%s;