0

I am having werid problem. Trying to remove whitespace characters from varchar variable in PostgresSQL. However one space is not removed. I dont know how is this possible.

Variable value: Snímek obrazovky 2019-12-05 v 13.33.37.png

regexp_replace(variable, '\s', '_', 'g')

Returns: Snímek_obrazovky_2019-12-05_v 13.33.37.png (notice a space after _v)

replace(variable, ' ', '_')

Returns: Snímek_obrazovky_2019-12-05_v 13.33.37.png = the same.

I dont know what else to try. Any ides? Might be some special character in there? Can identify which kind.

Macejkou
  • 636
  • 3
  • 14
  • 24

2 Answers2

0

In UTF8 encoding you can check the codes of all characters in the string:

select ch, ascii(ch) as code
from unnest(regexp_split_to_array('Snímek obrazovky 2019-12-05 v 13.33.37.png', '')) as ch
klin
  • 112,967
  • 15
  • 204
  • 232
  • AHA!! Thank you! It was "no brake space" character 160 instead of 32 regular space. Looks like \s doesnt cover that. – Macejkou Feb 23 '23 at 16:50
0
replace(variable,chr(160),'_')

Is the way to go.

Macejkou
  • 636
  • 3
  • 14
  • 24