r/learnSQL • u/thisismugisha • 7d ago
Text column is storing accented text weirdly
/r/postgres/comments/1y3sx9v/text_column_is_storing_accented_text_weirdly/
1
Upvotes
r/learnSQL • u/thisismugisha • 7d ago
1
u/Discordbothost 6d ago
Try `encode(convert_to(your_column, 'UTF8'), 'hex')` on the row with Quarteirão. The ã should show up as `c3a3`. If the bytes are right but the text looks wrong, check how the client reads or displays the result. If you get `cf80` for π, work back through the insert and check what the driver sends.
1
u/syntheticcfo 5d ago
Those exact swaps are a good clue. In Windows 1252 the ã is byte E3, and E3 is π in code page 437, the old DOS one the Windows command prompt still uses by default. Same story for ó, which is F3 and shows up as ≤ in that code page. So the text is most likely fine in the database and it's the console showing it wrong. If you're running psql in cmd you probably get a warning at startup saying the console code page differs from the Windows code page. Running chcp 1252 in that window before starting psql usually fixes it, or use a client like pgAdmin or DBeaver to check. Your database settings are fine here, the C collation affects sort order, not what gets stored. If the hex check from the other comment gives c3a3 for the ã, the stored data is right and it's only the display.