Original query:

SELECT r.id, r.active_version FROM astra_umarketadm.agent_group_map agm, astra_umarketadm.rule_map rm, astra_umarketadm.rule r WHERE rm.ruleid = r.id AND agm.agid = rm.entityid AND rm.entity_type = 0 AND agm.agentid = $1 AND r.contextid = $2 AND r.active_version IS NOT NULL ORDER BY agm.id, rm.id;