Open silviucm opened 6 years ago
I think there is very little appetite for adding any new API to encoding/csv.
The problem seems to be differentiating between a NULL value vs. an empty string for string database types. RFC4180 doesn't seem to have any rules regarding this. How about this proposal instead:
Any fields that have quoted empty strings in a record will be considered empty strings when read in csv.Reader. For example the record:
a,"",b
returns ["a", "", "b"]
Any fields that are unquoted empty strings in a record will be considered nil when read in csv.Reader. For example, the record:
a,,b
returns ["a", nil, "b"]
And vice versa for csv.Writer.
As briefly mentioned inside certain csv.Writer comments, there are frequent use cases, particularly with Postgres bulk copy to / from, where it is useful to differentiate between unquoted and quoted empty strings.
In particular, for csv.Reader, by the time Read() returns a slice of strings, it is too late to know whether a certain empty string is a quoted empty string or an unquoted one.
My particular use case deals with determining the nullability of an empty unquoted string, but - more generally - I just wanted to see if there is any appetite towards adding such column level introspection capabilities to the standard library csv.Reader and csv.Writer, without breaking compatibility.
For Reader, this would expose an additional surface perhaps similar to:
Regards, silviu