postgresql中如何替换掉某个字段里的字母?


比如,字段名称为slug,我想把所有数据中,该字段里面的字母a替换为字母c。请问该如何书写sql?

sql PostgreSQL

kouiyuu 9 years, 11 months ago

你可以使用replace函数, 参考 http://www.postgresql.org/docs/8.1/st...

replace(string text, from text, to text)

那你上面的例子,就是

update table_name set slug = replace(slug, 'a', 'b')

你也可以使用 regexp_replace

风雨中的FXR answered 9 years, 11 months ago

Your Answer