1

I want to remove the trailing whitespaces from CSV file.

Sample CSV file Data:(Delimitor=";")

X ;Y;Z

X1 ; Y1;Z1

X2;Y2; Z2

I would have gone for something like SED or GREP but the file size is huge so it may impact the performance because of preprocessing.

I am looking for a way to remove these whites spaces at the time of loading only.

Akshay Patil
  • 239
  • 2
  • 12

1 Answers1

2

COPY command does not support preprocessing - you can't do it "at the time of loading "

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.

I think here the best solution would be importing data with spaces and then

update t set attr = rtim(attr);
Vao Tsun
  • 47,234
  • 13
  • 100
  • 132