如何在将数据从 CSV 文件加载到 Postgres Table 时删除尾随的白色 space?

How can I remove tailing white space while loading data from CSV file into an Postgres Table?

我想从 CSV 文件中删除尾随空格。

CSV 文件数据示例:(Delimitor=";")

X ;Y;Z

X1 ; Y1;Z1

X2;Y2; Z2

我会选择 SEDGREP 之类的东西,但文件很大,因此可能会因为预处理而影响性能.

我正在寻找一种仅在加载时删除这些空白的方法。

COPY 命令不支持预处理 - 你不能这样做 "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.

我认为最好的解决方案是导入带空格的数据,然后

update t set attr = rtim(attr);