LoginSignup
0
0

More than 5 years have passed since last update.

【PostgreSQL】特定のカラムに一括で同じ文字列操作をする小技

Last updated at Posted at 2016-02-28

使う機会はあまりなさそうだけど、せっかくなのでメモ。
なんらかの理由で一時的にキーワードを追加したい時とかに使えそう。

  • 同じ文字列を追加する
UPDATE
  table1 AS t1
SET
  column1 = '追加する文字列 ' || t2.column1 FROM (SELECT id, column1 FROM table1) AS t2
WHERE
  t1.id = t2.id 
  • 追加した文字列を削除する
UPDATE
  table1 AS t1
SET
  column1 = t2.column1 FROM (SELECT id, REPLACE(column1, '追加する文字列 ', '') FROM table1) AS t2
WHERE
  t1.id = t2.id 

t2の抽出に条件を追加すれば、もっと細かい指定も可能。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0