Cast oids inside logical queries