CSV reader: is it possible to disable trim?

Jens Thiele <[email protected]> Sat, 16 May 2026 23:11:07 +0200
Newsgroups gmane.lisp.scheme.gauche
Message-ID <[email protected]>
Hi,

by default the CSV reader in text.csv trims whitespace. Is it possible
to disable this? (yes, CSV is a mess).

I didn't know there is a RFC for it. Reading:
https://www.rfc-editor.org/rfc/rfc4180
"
Within the header and each record, there may be one or more
fields, separated by commas.  Each line should contain the same
number of fields throughout the file.  Spaces are considered part
of a field and should not be ignored.
"

which "conflicts" with text.csv:
"Usually, the whitespaces around the field are ignored."

PS: regarding the CSV mess - quoting the COPY man page from PostgreSQL:
"
Note

Many programs produce strange and occasionally perverse CSV files,
so the file format is more a convention than a standard. Thus you
might encounter some files that cannot be imported using this
mechanism, and COPY might produce files that other programs cannot
process.
"

$ psql
karme=> select * from csvtest;
 id |              name               | dummy 
----+---------------------------------+-------
  1 |  text surrounded by whitespace  |    42
  2 |  whitespace in front            |    42
  3 | whitespace afterwards           |    42

karme=> copy csvtest to stdout with csv;
1, text surrounded by whitespace ,42
2, whitespace in front,42
3,whitespace afterwards ,42

possible workaround:

karme=> copy csvtest to stdout with csv force quote name;
1," text surrounded by whitespace ",42
2," whitespace in front",42
3,"whitespace afterwards ",42