Re: CSV reader: is it possible to disable trim?
Shiro Kawai <[email protected]> Sat, 16 May 2026 18:47:53 -1000
| Newsgroups | gmane.lisp.scheme.gauche |
|---|---|
| Message-ID | <CALN0JNEyBtwobCOHY_sM2ZRd0iitJFsvV7a80W4NfAaRgNVXuw@mail.gmail.com> |
--===============8410292472218743933== Content-Type: multipart/alternative; boundary="000000000000bf0f350651fc2630" --000000000000bf0f350651fc2630 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable OK, you convinced me the current implementation is incorrect. I'll disable it or make it customizable, after pondering the compatibility implications. On Sat, May 16, 2026 at 11:11=E2=80=AFAM Jens Thiele <[email protected]> wrote= : > 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=3D> select * from csvtest; > id | name | dummy > ----+---------------------------------+------- > 1 | text surrounded by whitespace | 42 > 2 | whitespace in front | 42 > 3 | whitespace afterwards | 42 > > karme=3D> copy csvtest to stdout with csv; > 1, text surrounded by whitespace ,42 > 2, whitespace in front,42 > 3,whitespace afterwards ,42 > > possible workaround: > > karme=3D> copy csvtest to stdout with csv force quote name; > 1," text surrounded by whitespace ",42 > 2," whitespace in front",42 > 3,"whitespace afterwards ",42 > > > _______________________________________________ > Gauche-devel mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/gauche-devel > --000000000000bf0f350651fc2630 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-size:large">OK,= you convinced me the current implementation=C2=A0is incorrect.=C2=A0 =C2= =A0I'll disable=C2=A0it or make it customizable, after pondering the co= mpatibility implications.</div><div class=3D"gmail_default" style=3D"font-s= ize:large"><br></div><div class=3D"gmail_default" style=3D"font-size:large"= ><br></div></div><br><div class=3D"gmail_quote gmail_quote_container"><div = dir=3D"ltr" class=3D"gmail_attr">On Sat, May 16, 2026 at 11:11=E2=80=AFAM J= ens Thiele <<a href=3D"mailto:[email protected]">[email protected]</a>> wro= te:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px = 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br> <br> by default the CSV reader in text.csv trims whitespace. Is it possible<br> to disable this? (yes, CSV is a mess).<br> <br> I didn't know there is a RFC for it. Reading:<br> <a href=3D"https://www.rfc-editor.org/rfc/rfc4180" rel=3D"noreferrer" targe= t=3D"_blank">https://www.rfc-editor.org/rfc/rfc4180</a><br> "<br> Within the header and each record, there may be one or more<br> fields, separated by commas.=C2=A0 Each line should contain the same<br> number of fields throughout the file.=C2=A0 Spaces are considered part<br> of a field and should not be ignored.<br> "<br> <br> which "conflicts" with text.csv:<br> "Usually, the whitespaces around the field are ignored."<br> <br> PS: regarding the CSV mess - quoting the COPY man page from PostgreSQL:<br> "<br> Note<br> <br> Many programs produce strange and occasionally perverse CSV files,<br> so the file format is more a convention than a standard. Thus you<br> might encounter some files that cannot be imported using this<br> mechanism, and COPY might produce files that other programs cannot<br> process.<br> "<br> <br> $ psql<br> karme=3D> select * from csvtest;<br> =C2=A0id |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 name=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| dummy <br> ----+---------------------------------+-------<br> =C2=A0 1 |=C2=A0 text surrounded by whitespace=C2=A0 |=C2=A0 =C2=A0 42<br> =C2=A0 2 |=C2=A0 whitespace in front=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 |=C2=A0 =C2=A0 42<br> =C2=A0 3 | whitespace afterwards=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0|= =C2=A0 =C2=A0 42<br> <br> karme=3D> copy csvtest to stdout with csv;<br> 1, text surrounded by whitespace ,42<br> 2, whitespace in front,42<br> 3,whitespace afterwards ,42<br> <br> possible workaround:<br> <br> karme=3D> copy csvtest to stdout with csv force quote name;<br> 1," text surrounded by whitespace ",42<br> 2," whitespace in front",42<br> 3,"whitespace afterwards ",42<br> <br> <br> _______________________________________________<br> Gauche-devel mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank">Gau= [email protected]</a><br> <a href=3D"https://lists.sourceforge.net/lists/listinfo/gauche-devel" rel= =3D"noreferrer" target=3D"_blank">https://lists.sourceforge.net/lists/listi= nfo/gauche-devel</a><br> </blockquote></div> --000000000000bf0f350651fc2630-- --===============8410292472218743933== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --===============8410292472218743933== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Gauche-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/gauche-devel --===============8410292472218743933==--