commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lars Bruun-Hansen (Jira)" <>
Subject [jira] [Created] (CSV-254) POSTGRESQL_CSV cannot parse correctly (null vs zero-length string)
Date Wed, 30 Oct 2019 19:26:00 GMT
Lars Bruun-Hansen created CSV-254:

             Summary: POSTGRESQL_CSV cannot parse correctly (null vs zero-length string)
                 Key: CSV-254
             Project: Commons CSV
          Issue Type: Bug
            Reporter: Lars Bruun-Hansen

 PostgresSQL by default creates CSV files which uses absent value for database NULL values.
Consider the following test in PostgresSQL:
	col1   varchar(10),
	col2   int,
	col3   varchar(10)
INSERT INTO mytab VALUES ('AA', 33, null);
INSERT INTO mytab VALUES ('AA', null, '');
INSERT INTO mytab VALUES (null, 33, 'CC');
and then exporting it to CSV:
\copy mytab TO STDOUT WITH csv
will produce CSV output as follows:
which the library currently will parse as follows using the current {{POSTGRESQL_CSV}} format:
Row no 2 is incorrect when comparing to the actual database table contents.
h2. The fix

Therefore the declaration of {{POSTGRESQL_CSV}} must be changed to:
public static final CSVFormat POSTGRESQL_CSV = DEFAULT
            .withAbsentMeansNull(true)   // added
(this depends on [PR51|])

 With the above the parser will give the following result instead: 
which is the expected result.

This message was sent by Atlassian Jira

View raw message