2017-11-16 14 views
0

CSV 파일에서 후행 공백을 제거하고 싶습니다.CSV 파일의 데이터를 Postgres 테이블로로드하는 동안 꼬리 공백을 제거하려면 어떻게해야합니까?

샘플 CSV 파일 데이터 : (Delimitor = ";")

X ;Y;Z

X1 ; Y1;Z1

X2;Y2; Z2

나는 SED 또는 GREP 같은 뭔가를 갈 것입니다하지만 파일 크기가 큽니다. 사전 처리로 인해 성능에 영향을 미칠 수 있습니다.

로드 할 때 이러한 공백을 제거하는 방법을 찾고 있습니다.

답변

1

COPY 명령은 전처리를 지원하지 않습니다 - 당신이 가장 좋은 방법은 다음 공간과 데이터를 가져 오는 것입니다

https://www.postgresql.org/docs/current/static/sql-copy.html

In CSV format, all characters are significant. A quoted value surrounded by white space, or any characters other than DELIMITER, will include those characters. This can cause errors if you import data from a system that pads CSV lines with white space out to some fixed width. If such a situation arises you might need to preprocess the CSV file to remove the trailing white space, before importing the data into PostgreSQL.

내가 여기 생각 "로딩시"그것을 할 수 없습니다

update t set attr = rtim(attr); 
+0

전처리시이 작업을 수행하는 최적의 방법이 있습니까? –

+0

나는 매우 비슷한 질문에 답했다. https://stackoverflow.com/a/47324806/5315974 - 공간을 가져 와서 그것을 가져온다. –

+0

공백으로 가져 오는 경우에도이 오류가 발생한다. '오류 : 인코딩을위한 바이트 시퀀스가 ​​유효하지 않다. "UTF8": 0xa0' –