半角カナを全角カナ
CREATE FUNCTION han2zen(varchar) RETURNS varchar AS ' DECLARE p1 alias for $1; str varchar; len int; i int; zenkakus varchar; hankakus varchar; BEGIN str := p1; str := replace(str, ''ガ'', ''ガ''); str := replace(str, ''ギ'', ''ギ''); str := replace(str, ''グ'', ''グ''); str := replace(str, ''ゲ'', ''ゲ''); str := replace(str, ''ゴ'', ''ゴ''); str := replace(str, ''ザ'', ''ザ''); str := replace(str, ''ジ'', ''ジ''); str := replace(str, ''ズ'', ''ズ''); str := replace(str, ''ゼ'', ''ゼ''); str := replace(str, ''ゾ'', ''ゾ''); str := replace(str, ''ダ'', ''ダ''); str := replace(str, ''ヂ'', ''ヂ''); str := replace(str, ''ヅ'', ''ヅ''); str := replace(str, ''デ'', ''デ''); str := replace(str, ''ド'', ''ド''); str := replace(str, ''バ'', ''バ''); str := replace(str, ''ビ'', ''ビ''); str := replace(str, ''ブ'', ''ブ''); str := replace(str, ''ベ'', ''ベ''); str := replace(str, ''ボ'', ''ボ''); str := replace(str, ''パ'', ''パ''); str := replace(str, ''ピ'', ''ピ''); str := replace(str, ''プ'', ''プ''); str := replace(str, ''ペ'', ''ペ''); str := replace(str, ''ポ'', ''ポ''); str := replace(str, ''ヴ'', ''ヴ''); zenkakus := ''アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンァィゥェォッャュョー・''; hankakus := ''アイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワヲンァィゥェォッャュョー・''; len := length(zenkakus); for i in 0 .. len loop str := replace(str, substr(hankakus, i, 1), substr(zenkakus, i, 1)); end loop; return str; END; ' LANGUAGE 'plpgsql' ; UPDATE table_name SET col_name=kana2full(col_name);
または、CREATE FUNCTION を han2zen.sql に保存して
\i /path/to/han2zen.sql UPDATE table_name SET col_name=kana2full(col_name);
登録した関数の削除
DROP FUNCTION han2zen(varchar);