-- -- number_src/1 -- create or replace function number_src( text ) returns text as $$ declare v_src alias for $1; v_pos integer; v_ret text default ''; v_tmp text; v_cnt integer default -1; begin if v_src is null then return null; end if; v_tmp := v_src; LOOP v_pos := position(' ' in v_tmp); v_cnt := v_cnt + 1; exit when v_pos = 0; if v_cnt != 0 then v_ret := v_ret || to_char(v_cnt,'9999') || ':' || substr(v_tmp,1,v_pos); end if; v_tmp := substr(v_tmp,v_pos + 1); end LOOP; return v_ret || to_char(v_cnt,'9999') || ':' || v_tmp; end;$$ language plpgsql;