Home Explore Blog CI



postgresql

5th chunk of `doc/src/sgml/ref/copy.sgml`
6a09b965355c3ad55992cb493f69c27eb1be3c7d96b910260000000100000fa0
  <term><literal>HEADER</literal></term>
    <listitem>
     <para>
      Specifies that the file contains a header line with the names of each
      column in the file.  On output, the first line contains the column
      names from the table.  On input, the first line is discarded when this
      option is set to <literal>true</literal> (or equivalent Boolean value).
      If this option is set to <literal>MATCH</literal>, the number and names
      of the columns in the header line must match the actual column names of
      the table, in order;  otherwise an error is raised.
      This option is not allowed when using <literal>binary</literal> format.
      The <literal>MATCH</literal> option is only valid for <command>COPY
      FROM</command> commands.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>QUOTE</literal></term>
    <listitem>
     <para>
      Specifies the quoting character to be used when a data value is quoted.
      The default is double-quote.
      This must be a single one-byte character.
      This option is allowed only when using <literal>CSV</literal> format.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>ESCAPE</literal></term>
    <listitem>
     <para>
      Specifies the character that should appear before a
      data character that matches the <literal>QUOTE</literal> value.
      The default is the same as the <literal>QUOTE</literal> value (so that
      the quoting character is doubled if it appears in the data).
      This must be a single one-byte character.
      This option is allowed only when using <literal>CSV</literal> format.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>FORCE_QUOTE</literal></term>
    <listitem>
     <para>
      Forces quoting to be
      used for all non-<literal>NULL</literal> values in each specified column.
      <literal>NULL</literal> output is never quoted. If <literal>*</literal> is specified,
      non-<literal>NULL</literal> values will be quoted in all columns.
      This option is allowed only in <command>COPY TO</command>, and only when
      using <literal>CSV</literal> format.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>FORCE_NOT_NULL</literal></term>
    <listitem>
     <para>
      Do not match the specified columns' values against the null string.
      In the default case where the null string is empty, this means that
      empty values will be read as zero-length strings rather than nulls,
      even when they are not quoted.
      If <literal>*</literal> is specified, the option will be applied to all columns.
      This option is allowed only in <command>COPY FROM</command>, and only when
      using <literal>CSV</literal> format.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>FORCE_NULL</literal></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</literal>. In the default case where the null string is empty,
      this converts a quoted empty string into NULL.
      If <literal>*</literal> is specified, the option will be applied to all columns.
      This option is allowed only in <command>COPY FROM</command>, and only when
      using <literal>CSV</literal> format.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>ON_ERROR</literal></term>
    <listitem>
     <para>
      Specifies how to behave when encountering an error converting a column's
      input value into its data type.
      An <replaceable class="parameter">error_action</replaceable> value of
      <literal>stop</literal> means fail the command, while
      <literal>ignore</literal> means discard the input row and continue with the next one.
      The default is <literal>stop</literal>.
     </para>
  

Title: COPY Command Parameters: HEADER, QUOTE, ESCAPE, FORCE_QUOTE, FORCE_NOT_NULL, FORCE_NULL, ON_ERROR
Summary
This section details additional parameters for the COPY command, including handling header lines (HEADER), specifying quote characters (QUOTE), defining escape characters (ESCAPE), forcing quoting for non-NULL values (FORCE_QUOTE), preventing certain columns from being interpreted as NULL (FORCE_NOT_NULL), forcing certain columns to be interpreted as NULL (FORCE_NULL), and specifying how to handle errors during data type conversion (ON_ERROR).