Home Explore Blog CI



postgresql

1st chunk of `doc/src/sgml/file-fdw.sgml`
d6a153e8a11bb445bbe12e64d6fb85c4bdb63253e31a7b300000000100000fa4
<!-- doc/src/sgml/file-fdw.sgml -->

<sect1 id="file-fdw" xreflabel="file_fdw">
 <title>file_fdw &mdash; access data files in the server's file system</title>

 <indexterm zone="file-fdw">
  <primary>file_fdw</primary>
 </indexterm>

 <para>
  The <filename>file_fdw</filename> module provides the foreign-data wrapper
  <function>file_fdw</function>, which can be used to access data
  files in the server's file system, or to execute programs on the server
  and read their output.  The data file or program output must be in a format
  that can be read by <command>COPY FROM</command>;
  see <xref linkend="sql-copy"/> for details.
  Access to data files is currently read-only.
 </para>

 <para>
  A foreign table created using this wrapper can have the following options:
 </para>

 <variablelist>

  <varlistentry>
   <term><literal>filename</literal></term>

   <listitem>
    <para>
     Specifies the file to be read.  Relative paths are relative to the
     data directory.
     Either <literal>filename</literal> or <literal>program</literal> must be
     specified, but not both.
    </para>
   </listitem>
  </varlistentry>

  <varlistentry>
   <term><literal>program</literal></term>

   <listitem>
    <para>
     Specifies the command to be executed.  The standard output of this
     command will be read as though <command>COPY FROM PROGRAM</command> were used.
     Either <literal>program</literal> or <literal>filename</literal> must be
     specified, but not both.
    </para>
   </listitem>
  </varlistentry>

  <varlistentry>
   <term><literal>format</literal></term>

   <listitem>
    <para>
     Specifies the data format,
     the same as <command>COPY</command>'s <literal>FORMAT</literal> option.
    </para>
   </listitem>
  </varlistentry>

  <varlistentry>
   <term><literal>header</literal></term>

   <listitem>
    <para>
     Specifies whether the data has a header line,
     the same as <command>COPY</command>'s <literal>HEADER</literal> option.
    </para>
   </listitem>
  </varlistentry>

  <varlistentry>
   <term><literal>delimiter</literal></term>

   <listitem>
    <para>
     Specifies the data delimiter character,
     the same as <command>COPY</command>'s <literal>DELIMITER</literal> option.
    </para>
   </listitem>
  </varlistentry>

  <varlistentry>
   <term><literal>quote</literal></term>

   <listitem>
    <para>
     Specifies the data quote character,
     the same as <command>COPY</command>'s <literal>QUOTE</literal> option.
    </para>
   </listitem>
  </varlistentry>

  <varlistentry>
   <term><literal>escape</literal></term>

   <listitem>
    <para>
     Specifies the data escape character,
     the same as <command>COPY</command>'s <literal>ESCAPE</literal> option.
    </para>
   </listitem>
  </varlistentry>

  <varlistentry>
   <term><literal>null</literal></term>

   <listitem>
    <para>
     Specifies the data null string,
     the same as <command>COPY</command>'s <literal>NULL</literal> option.
    </para>
   </listitem>
  </varlistentry>

  <varlistentry>
   <term><literal>encoding</literal></term>

   <listitem>
    <para>
     Specifies the data encoding,
     the same as <command>COPY</command>'s <literal>ENCODING</literal> option.
    </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,
     the same as <command>COPY</command>'s <literal>ON_ERROR</literal> option.
    </para>
   </listitem>
  </varlistentry>

  <varlistentry>
   <term><literal>reject_limit</literal></term>

   <listitem>
    <para>
     Specifies the maximum number of errors tolerated while converting a column's
     input value to its data type, the same as <command>COPY</command>'s
    <literal>REJECT_LIMIT</literal> option.
    </para>
   </listitem>
  </varlistentry>

  <varlistentry>
   <term><literal>log_verbosity</literal></term>

Title: file_fdw - Accessing Data Files in the Server's File System
Summary
The file_fdw module provides a foreign-data wrapper for accessing data files or executing programs on the server's file system. It allows reading data in formats compatible with COPY FROM. Foreign tables created with this wrapper can have options like filename, program, format, header, delimiter, quote, escape, null, encoding, on_error, reject_limit, and log_verbosity to control how the data is read and interpreted.