csvjdbc icon indicating copy to clipboard operation
csvjdbc copied to clipboard

Fixed-width input is always trimmed, regardless of trimValues setting

Open geert3 opened this issue 4 years ago • 2 comments

When reading a CSV with fixed width, white space is always trimmed. See CsvRawReader::parseFixedLine

values[i] = values[i].trim();

In my use-case, I have leading white space that should remain intact. I see several possible solutions:

  • only trim trailing white space for fixed-width input
  • trim white space only if 'trimValues' property is true (and perhaps make it true by default for fixed-width input)

geert3 avatar Mar 24 '21 09:03 geert3

A workaround is to use one's own reader and in there replace the first blank with a nonbreaking space: if (line.startsWith(" ")) line = "\u00a0" + line.substring(1)

geert3 avatar Mar 24 '21 09:03 geert3

Yes, there are some variations of text files that CsvJdbc does not read correctly.

An alternative is to set the following database connection properties so that the text file has a single column named LINE:

skipLeadingLines=1
suppressHeaders=true
headerline=LINE
separator=a_string_not_in_text_file

Then select the parts of each line you are interested in using SQL. For example:

select trim(substring(line, 1, 5)) as c1, trim(substring(line, 6, 8)) as c2 from fixed

simoc avatar Apr 26 '21 18:04 simoc