removing zwnj character from string in postgres during select statement
-
13-10-2019 - |
Question
The utf encoded string contains Zwnj(zero width non joiner) at the end and is stored in database. Is it possible to remove that character during select statement. I tried trim() but doesn't work.
Solution
CREATE TABLE test (x text);
INSERT INTO test VALUES (E'abc');
INSERT INTO test VALUES (E'foo\u200C'); -- U+200C = ZERO WIDTH NON-JOINER
SELECT x, octet_length(x) FROM test;
x │ octet_length
─────┼──────────────
abc │ 3
foo │ 6
(2 rows)
CREATE TABLE test2 AS SELECT replace(x, E'\u200C', '') AS x FROM test;
SELECT x, octet_length(x) FROM test2;
x │ octet_length
─────┼──────────────
abc │ 3
foo │ 3
(2 rows)
OTHER TIPS
You need to use replace(your_column, 'Zwnj','')
instead of trim()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow