user238271
user238271

Reputation: 643

Postgres replace characters in string

I have column with text where I need to change characters! For example

So I need to replace � with character D. I try next but I get error:invalid regular expression: quantifier operand invalid

update  tableT pp set descript=(select regexp_replace(descript,'�', 'D') 
FROM 
  tableT kk where pp.id=kk.id) ;

Upvotes: 18

Views: 24121

Answers (2)

jarlh
jarlh

Reputation: 44696

It's just a plain UPDATE:

update  tableT set descript= regexp_replace(descript,'�', 'D')

add where descript like '%�%' to minimize transaction.

Or, as President Camacho says, why not use replace instead of regexp_replace?

Upvotes: 14

President Camacho
President Camacho

Reputation: 1900

update tableT pp
set descript = (select replace(descript, '�', 'D') from tableT where id = pp.id)

Why don't use replace?

Upvotes: 20

Related Questions