anay: Fixing the query for postgreSQL