How To Query The Variable In An Active Query In Postgresql