postgresql7.1
select rel_id
from (select rel_id, sort_key
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
limit 1
select location_rel__swap_sort(rel_id_one => :rel_id, rel_id_two => :other_rel_id);