Build posts_feed query using sql