문제

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.

도움이 되었습니까?

해결책

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)

다른 팁

You need to use replace(your_column, 'Zwnj','') instead of trim()

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top