PostgreSQLで文字列を置換するコマンドについて説明します。

コマンド

以下のコマンドでは、postsテーブルのcontentカラムの文字列 "example.com" を "example.net" に置換します。

update posts
set content = replace(content, 'example.com', 'example.net')
where content like '%example.com%';

whereの行はなくても結果は同じになりますが、パフォーマンスを考えて書いています。

実行する前にバックアップを取りましょう。