From 3b5e03dca2afea7a2c12dbc8605175d0568b5555 Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Tue, 4 Mar 2014 17:31:59 -0500 Subject: Provide a FORCE NULL option to COPY in CSV mode. This forces an input field containing the quoted null string to be returned as a NULL. Without this option, only unquoted null strings behave this way. This helps where some CSV producers insist on quoting every field, whether or not it is needed. The option takes a list of fields, and only applies to those columns. There is an equivalent column-level option added to file_fdw. Ian Barwick, with some tweaking by Andrew Dunstan, reviewed by Payal Singh. --- doc/src/sgml/file-fdw.sgml | 21 ++++++++++++++++++--- doc/src/sgml/ref/copy.sgml | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 4 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/file-fdw.sgml b/doc/src/sgml/file-fdw.sgml index 9385b26d34d..d3b39aa120b 100644 --- a/doc/src/sgml/file-fdw.sgml +++ b/doc/src/sgml/file-fdw.sgml @@ -112,11 +112,11 @@ - Note that while COPY allows options such as OIDS and HEADER + Note that while COPY allows options such as OIDS and HEADER to be specified without a corresponding value, the foreign data wrapper - syntax requires a value to be present in all cases. To activate + syntax requires a value to be present in all cases. To activate COPY options normally supplied without a value, you can - instead pass the value TRUE. + instead pass the value TRUE. @@ -140,6 +140,21 @@ + + force_null + + + + This is a Boolean option. If true, it specifies that values of the + column which match the null string are returned as NULL + even if the value is quoted. Without this option, only unquoted + values matching the null string are returned as NULL. + This has the same effect as listing the column in + COPY's FORCE_NULL option. + + + + diff --git a/doc/src/sgml/ref/copy.sgml b/doc/src/sgml/ref/copy.sgml index 99f246af171..5be3514612e 100644 --- a/doc/src/sgml/ref/copy.sgml +++ b/doc/src/sgml/ref/copy.sgml @@ -42,6 +42,7 @@ COPY { table_name [ ( escape_character' FORCE_QUOTE { ( column_name [, ...] ) | * } FORCE_NOT_NULL ( column_name [, ...] ) + FORCE_NULL ( column_name [, ...] ) ENCODING 'encoding_name' @@ -328,6 +329,20 @@ COPY { table_name [ ( + + FORCE_NULL + + + Match the specified columns' values against the null string, even + if it has been quoted, and if a match is found set the value to + NULL. In the default case where the null string is empty, + this converts a quoted empty string into NULL. + This option is allowed only in COPY FROM, and only when + using CSV format. + + + + ENCODING @@ -637,7 +652,9 @@ COPY count string, while an empty string data value is written with double quotes (""). Reading values follows similar rules. You can use FORCE_NOT_NULL to prevent NULL input - comparisons for specific columns. + comparisons for specific columns. You can also use + FORCE_NULL to convert quoted null string data values to + NULL. -- cgit v1.2.3