diff options
author | Andrew Dunstan <andrew@dunslane.net> | 2014-03-04 17:31:59 -0500 |
---|---|---|
committer | Andrew Dunstan <andrew@dunslane.net> | 2014-03-04 17:31:59 -0500 |
commit | 3b5e03dca2afea7a2c12dbc8605175d0568b5555 (patch) | |
tree | 4fadb752688feee0a0c08273f0bbb857e5fce429 /doc/src | |
parent | e2a0fc5363e293d29053d0582a1009bc9fef0276 (diff) | |
download | postgresql-3b5e03dca2afea7a2c12dbc8605175d0568b5555.tar.gz postgresql-3b5e03dca2afea7a2c12dbc8605175d0568b5555.zip |
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.
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/file-fdw.sgml | 21 | ||||
-rw-r--r-- | doc/src/sgml/ref/copy.sgml | 19 |
2 files changed, 36 insertions, 4 deletions
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 @@ </variablelist> <para> - Note that while <command>COPY</> allows options such as OIDS and HEADER + Note that while <command>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 <command>COPY</> options normally supplied without a value, you can - instead pass the value TRUE. + instead pass the value TRUE. </para> <para> @@ -140,6 +140,21 @@ </listitem> </varlistentry> + <varlistentry> + <term><literal>force_null</literal></term> + + <listitem> + <para> + This is a Boolean option. If true, it specifies that values of the + column which match the null string are returned as <literal>NULL</> + even if the value is quoted. Without this option, only unquoted + values matching the null string are returned as <literal>NULL</>. + This has the same effect as listing the column in + <command>COPY</>'s <literal>FORCE_NULL</literal> option. + </para> + </listitem> + </varlistentry> + </variablelist> <para> 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 { <replaceable class="parameter">table_name</replaceable> [ ( <replaceable ESCAPE '<replaceable class="parameter">escape_character</replaceable>' FORCE_QUOTE { ( <replaceable class="parameter">column_name</replaceable> [, ...] ) | * } FORCE_NOT_NULL ( <replaceable class="parameter">column_name</replaceable> [, ...] ) + FORCE_NULL ( <replaceable class="parameter">column_name</replaceable> [, ...] ) ENCODING '<replaceable class="parameter">encoding_name</replaceable>' </synopsis> </refsynopsisdiv> @@ -329,6 +330,20 @@ COPY { <replaceable class="parameter">table_name</replaceable> [ ( <replaceable </varlistentry> <varlistentry> + <term><literal>FORCE_NULL</></term> + <listitem> + <para> + 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 + <literal>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 <command>COPY FROM</>, and only when + using <literal>CSV</> format. + </para> + </listitem> + </varlistentry> + + <varlistentry> <term><literal>ENCODING</></term> <listitem> <para> @@ -637,7 +652,9 @@ COPY <replaceable class="parameter">count</replaceable> string, while an empty string data value is written with double quotes (<literal>""</>). Reading values follows similar rules. You can use <literal>FORCE_NOT_NULL</> to prevent <literal>NULL</> input - comparisons for specific columns. + comparisons for specific columns. You can also use + <literal>FORCE_NULL</> to convert quoted null string data values to + <literal>NULL</>. </para> <para> |