How to fix unicode REPLACEMENT CHARACTER � in postgres database



  • Is there a way fix the � problem in postgres database:

    enter image description here

    As you can see there are names with accents and are not displayed corretly in the database. I would like to know if there is a way to fix this without dropping the database and restoring it... ?

    When I execute

    SELECT CAST (userfirstname AS bytea) FROM tab WHERE id = 42;`
    

    this is the result i get:

                   bytea
    --------------------------------------
     \x5374efbfbd7068616e696520284d6d6529
    (1 ligne)
    


  • That character (0xEFBFBD in UTF-8) really is Unicode 0xFFFD, the “replacement character” �.

    So if that's not what you want, the problem must have occurred when you inserted the data into the database. PostgreSQL does not surreptitiously modify strings, so some software most have done that before the data were put into the database.

    Since the characters you would like to see are not all equal (I spot é and ç, for example), there is no automatic way to repair the damage.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2