--
-- lob_get_data/1
--
create or replace function lob_get_data(
  integer
) returns text as $$

declare
        p_lob_id alias for $1;
        v_rec   record;
        v_data  text default '';
begin
        for v_rec in select data, segment from lob_data where lob_id = p_lob_id order by segment 
        loop
            v_data := v_data || v_rec.data;
        end loop;

        return v_data;

end;$$ language plpgsql;