Search code examples
postgresqltrimnon-breaking-characters

How to remove non-breaking spaces from a column in Postgres


Trying to remove a non-breaking space from a field without any success. I've tried

execute <<-SQL
  UPDATE customers
  SET name = TRIM (name)
SQL

but this removes only spaces. It's similar question as this but I need it for Postgres (Postgres complains syntax error at or near "x00A0") and also I need only trimming i.e it has to remove only at the beginning and at the end of the text.

Thanks


Solution

  • You can pass the character as the second argument of trim():

    update customers
    set name = trim(name, chr(160))
    

    See String Functions and Operators in the docs for the functions definition.