Skip to content

Commit 40bbc8c

Browse files
committed
Improve documentation for COPY ... ON_ERROR ...
Discussion: https://postgr.es/m/20240126112829.d420b28859fbe84379fdb7ad%40sraoss.co.jp Author: Yugo Nagata Reviewed-by: Masahiko Sawada, David G. Johnston, Atsushi Torikoshi
1 parent 18dd9d2 commit 40bbc8c

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

doc/src/sgml/ref/copy.sgml

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ COPY { <replaceable class="parameter">table_name</replaceable> [ ( <replaceable
9090
in the <structname>pg_stat_progress_copy</structname> view. See
9191
<xref linkend="copy-progress-reporting"/> for details.
9292
</para>
93+
94+
<para>
95+
By default, <command>COPY</command> will fail if it encounters an error
96+
during processing. For use cases where a best-effort attempt at loading
97+
the entire file is desired, the <literal>ON_ERROR</literal> clause can
98+
be used to specify some other behavior.
99+
</para>
93100
</refsect1>
94101

95102
<refsect1>
@@ -378,17 +385,20 @@ COPY { <replaceable class="parameter">table_name</replaceable> [ ( <replaceable
378385
<term><literal>ON_ERROR</literal></term>
379386
<listitem>
380387
<para>
381-
Specifies which <replaceable class="parameter">
382-
error_action</replaceable> to perform when there is malformed data in the input.
383-
Currently, only <literal>stop</literal> (default) and <literal>ignore</literal>
384-
values are supported.
385-
If the <literal>stop</literal> value is specified,
386-
<command>COPY</command> stops operation at the first error.
387-
If the <literal>ignore</literal> value is specified,
388-
<command>COPY</command> skips malformed data and continues copying data.
389-
The option is allowed only in <command>COPY FROM</command>.
390-
Only <literal>stop</literal> value is allowed when
391-
using <literal>binary</literal> format.
388+
Specifies how to behave when encountering an error converting a column's
389+
input value into its data type.
390+
An <replaceable class="parameter">error_action</replaceable> value of
391+
<literal>stop</literal> means fail the command, while
392+
<literal>ignore</literal> means discard the input row and continue with the next one.
393+
The default is <literal>stop</literal>.
394+
</para>
395+
<para>
396+
The <literal>ignore</literal> option is applicable only for <command>COPY FROM</command>
397+
when the <literal>FORMAT</literal> is <literal>text</literal> or <literal>csv</literal>.
398+
</para>
399+
<para>
400+
A <literal>NOTICE</literal> message containing the ignored row count is emitted at the end
401+
of the <command>COPY FROM</command> if at least one row was discarded.
392402
</para>
393403
</listitem>
394404
</varlistentry>
@@ -576,15 +586,13 @@ COPY <replaceable class="parameter">count</replaceable>
576586
</para>
577587

578588
<para>
579-
<command>COPY</command> stops operation at the first error when
580-
<literal>ON_ERROR</literal> is not specified. This
581-
should not lead to problems in the event of a <command>COPY
582-
TO</command>, but the target table will already have received
583-
earlier rows in a <command>COPY FROM</command>. These rows will not
584-
be visible or accessible, but they still occupy disk space. This might
585-
amount to a considerable amount of wasted disk space if the failure
586-
happened well into a large copy operation. You might wish to invoke
587-
<command>VACUUM</command> to recover the wasted space.
589+
The <command>COPY FROM</command> command physically inserts input rows
590+
into the table as it progresses. If the command fails, these rows are
591+
left in a deleted state; these rows will not be visible, but still
592+
occupy disk space. This might amount to considerable
593+
wasted disk space if the failure happened well into a large copy
594+
operation. <command>VACUUM</command> should be used to recover the
595+
wasted space.
588596
</para>
589597

590598
<para>

0 commit comments

Comments
 (0)