smarter (and uglier) query for prymitive/upaas#35 [ci skip]