7.2.x 버전에는 문자열 바꾸기 함수인 replace 함수가 없어져버렸습니다. 쓸일이 생겨서 간단하게 만들어보았습니다.
CREATE OR REPLACE FUNCTION replace(text, text, text) RETURNS text AS '
DECLARE
source ALIAS FOR $1;
findstr ALIAS FOR $2;
replstr ALIAS FOR $3;
deststr text;
workstr text;
curpos int;
BEGIN
IF source is null THEN
return source;
END IF;
deststr := '''';
curpos := 0;
workstr := source;
curpos := strpos(workstr, findstr);
LOOP
EXIT WHEN curpos = 0;
deststr := deststr || substr(workstr, 1, curpos - 1);
workstr := substr(workstr, curpos + length(findstr));
deststr := deststr || replstr;
curpos := strpos(workstr, findstr);
END LOOP;
RETURN deststr || workstr;
END;
' LANGUAGE 'plpgsql';
|