postgresql7.1 FIX ME ROWNUM select rel_id from (select rel_id from addresses_located where sort_key $operator (select sort_key from location_rels where rel_id = :rel_id) and locatee_id = :contact_id order by sort_key $direction) sq where rownum = 1 FIX ME PLSQL FIX ME PLSQL begin location_rel__swap_sort(rel_id_one => :rel_id, rel_id_two => :other_rel_id); end;