postgresql - replace all instances of a string within text field

后端 未结 4 2205
时光取名叫无心
时光取名叫无心 2020-11-28 18:57

In postgresql, how do I replace all instances of a string within a database column?

Say I want to replace all instances of cat with dog, fo

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 19:26

    You can use the replace function

    UPDATE your_table SET field = REPLACE(your_field, 'cat','dog')
    

    The function definition is as follows (got from here):

    replace(string text, from text, to text)
    

    and returns the modified text. You can also check out this sql fiddle.

提交回复
热议问题