Subject: [Proposal] Adding TRIM_SPACE option to COPY
Hi,
I'd like to propose adding a new option, TRIM_SPACE, to the COPY command.
Other data warehouse systems such as Snowflake provide similar functionality (TRIM_SPACE) to improve robustness when loading CSV data. PostgreSQL does not currently have such an option, although it would be consistent with other user-friendly features already present in COPY (e.g., FORCE_NULL, FORCE_NOT_NULL, ON_ERROR).
Proposed feature ---------------- Add a boolean option:
TRIM_SPACE = true | false (default: false)
When enabled, COPY FROM with FORMAT text or csv will trim leading and trailing ASCII whitespace from each column value before NULL processing and type conversion. This is applied only to FORMAT text and csv.(not binary)
Example usage:
COPY mytable FROM '/tmp/data.csv' WITH (FORMAT csv, HEADER true, TRIM_SPACE true);
This would transform(trim leading and trailing ASCII whitespace): " AAA ", " BBB", "CCC "