Closed metametadata closed 3 years ago
According to https://www.postgresql.org/docs/current/sql-copy.html you can use \N
(or other value with the NULL AS
clause) to differentiate between empty and null fields.
Yes, I'm using "NULL AS" as a workaround (\N
is for text format, not CSV). The drawback of this workaround is that the sentinel null string cannot be used in the CSV as a real value anymore.
OK, understood. But your example is mixed up, I think. According to the doc, an unquoted empty string is handled as NULL
, not a quoted one. So, what you would need is:
1,,3 ---> NULL
1,"",3 ---> ""
Is that correct?
Ah, yes, you're right.
I consider this for the 2.0 release. Could you please check the commit faac27111e5acd183b0c09471b24ea8b50f35f23 to see if it covers your requirements. I don't think that a per field setting is required, though.
Yes, looks like it will do the trick.
Implemented in version 2.
I need a way to enforce per-field quoting in order to generate CSV for PostgreSQL COPY statement because quoted empty string is treated as NULL, while totally empty field is treated as an empty string:
The current
CsvAppender
API doesn't support such behavior. Possible solutions:appendField
appendDelimitedField
alwaysDelimitText
field mutable so that the consumer can turn it off/on before appending the specific field