1999-07-22 17:09:15 +02:00
|
|
|
<!--
|
2004-04-21 02:34:18 +02:00
|
|
|
$PostgreSQL: pgsql/doc/src/sgml/ref/copy.sgml,v 1.57 2004/04/21 00:34:18 momjian Exp $
|
2001-12-08 04:24:40 +01:00
|
|
|
PostgreSQL documentation
|
1999-07-22 17:09:15 +02:00
|
|
|
-->
|
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<refentry id="SQL-COPY">
|
|
|
|
<refmeta>
|
2001-05-27 11:59:30 +02:00
|
|
|
<refentrytitle id="sql-copy-title">COPY</refentrytitle>
|
1999-07-06 19:16:42 +02:00
|
|
|
<refmiscinfo>SQL - Language Statements</refmiscinfo>
|
|
|
|
</refmeta>
|
2003-04-15 15:25:08 +02:00
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<refnamediv>
|
2003-04-15 15:25:08 +02:00
|
|
|
<refname>COPY</refname>
|
2003-09-22 02:16:58 +02:00
|
|
|
<refpurpose>copy data between a file and a table</refpurpose>
|
1998-12-29 03:24:47 +01:00
|
|
|
</refnamediv>
|
2003-04-15 15:25:08 +02:00
|
|
|
|
2003-08-31 19:32:24 +02:00
|
|
|
<indexterm zone="sql-copy">
|
|
|
|
<primary>COPY</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<refsynopsisdiv>
|
2003-04-15 15:25:08 +02:00
|
|
|
<synopsis>
|
2003-09-22 02:16:58 +02:00
|
|
|
COPY <replaceable class="parameter">tablename</replaceable> [ ( <replaceable class="parameter">column</replaceable> [, ...] ) ]
|
2003-04-15 15:25:08 +02:00
|
|
|
FROM { '<replaceable class="parameter">filename</replaceable>' | STDIN }
|
2002-06-20 18:00:44 +02:00
|
|
|
[ [ WITH ]
|
|
|
|
[ BINARY ]
|
|
|
|
[ OIDS ]
|
|
|
|
[ DELIMITER [ AS ] '<replaceable class="parameter">delimiter</replaceable>' ]
|
2004-04-19 19:22:31 +02:00
|
|
|
[ NULL [ AS ] '<replaceable class="parameter">null string</replaceable>' ]
|
|
|
|
[ CSV [ QUOTE [ AS ] '<replaceable class="parameter">quote</replaceable>' ]
|
|
|
|
[ ESCAPE [ AS ] '<replaceable class="parameter">escape</replaceable>' ]
|
2004-04-21 02:34:18 +02:00
|
|
|
[ FORCE NOT NULL <replaceable class="parameter">column</replaceable> [, ...] ]
|
2003-04-15 15:25:08 +02:00
|
|
|
|
2003-09-22 02:16:58 +02:00
|
|
|
COPY <replaceable class="parameter">tablename</replaceable> [ ( <replaceable class="parameter">column</replaceable> [, ...] ) ]
|
2003-04-15 15:25:08 +02:00
|
|
|
TO { '<replaceable class="parameter">filename</replaceable>' | STDOUT }
|
2002-06-20 18:00:44 +02:00
|
|
|
[ [ WITH ]
|
|
|
|
[ BINARY ]
|
|
|
|
[ OIDS ]
|
|
|
|
[ DELIMITER [ AS ] '<replaceable class="parameter">delimiter</replaceable>' ]
|
2004-04-19 19:22:31 +02:00
|
|
|
[ NULL [ AS ] '<replaceable class="parameter">null string</replaceable>' ]
|
|
|
|
[ CSV [ QUOTE [ AS ] '<replaceable class="parameter">quote</replaceable>' ]
|
|
|
|
[ ESCAPE [ AS ] '<replaceable class="parameter">escape</replaceable>' ]
|
2004-04-21 02:34:18 +02:00
|
|
|
[ FORCE QUOTE <replaceable class="parameter">column</replaceable> [, ...] ]
|
2003-04-15 15:25:08 +02:00
|
|
|
</synopsis>
|
1999-07-06 19:16:42 +02:00
|
|
|
</refsynopsisdiv>
|
1998-05-13 07:34:00 +02:00
|
|
|
|
2003-04-15 15:25:08 +02:00
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
|
|
|
|
1998-12-29 03:24:47 +01:00
|
|
|
<para>
|
1998-09-16 16:43:12 +02:00
|
|
|
<command>COPY</command> moves data between
|
2002-06-20 18:00:44 +02:00
|
|
|
<productname>PostgreSQL</productname> tables and standard file-system
|
2002-08-04 07:09:36 +02:00
|
|
|
files. <command>COPY TO</command> copies the contents of a table
|
2002-06-20 18:00:44 +02:00
|
|
|
<emphasis>to</> a file, while <command>COPY FROM</command> copies
|
|
|
|
data <emphasis>from</> a file to a table (appending the data to
|
|
|
|
whatever is in the table already).
|
2001-01-03 21:04:10 +01:00
|
|
|
</para>
|
|
|
|
|
2002-07-30 18:55:06 +02:00
|
|
|
<para>
|
|
|
|
If a list of columns is specified, <command>COPY</command> will
|
2002-08-02 20:15:10 +02:00
|
|
|
only copy the data in the specified columns to or from the file.
|
2002-08-04 07:09:36 +02:00
|
|
|
If there are any columns in the table that are not in the column list,
|
2002-08-02 20:15:10 +02:00
|
|
|
<command>COPY FROM</command> will insert the default values for
|
|
|
|
those columns.
|
2002-07-18 06:43:51 +02:00
|
|
|
</para>
|
|
|
|
|
2001-01-03 21:04:10 +01:00
|
|
|
<para>
|
2002-06-20 18:00:44 +02:00
|
|
|
<command>COPY</command> with a file name instructs the
|
2003-04-15 15:25:08 +02:00
|
|
|
<productname>PostgreSQL</productname> server to directly read from
|
|
|
|
or write to a file. The file must be accessible to the server and
|
|
|
|
the name must be specified from the viewpoint of the server. When
|
|
|
|
<literal>STDIN</literal> or <literal>STDOUT</literal> is
|
This patch implements holdable cursors, following the proposal
(materialization into a tuple store) discussed on pgsql-hackers earlier.
I've updated the documentation and the regression tests.
Notes on the implementation:
- I needed to change the tuple store API slightly -- it assumes that it
won't be used to hold data across transaction boundaries, so the temp
files that it uses for on-disk storage are automatically reclaimed at
end-of-transaction. I added a flag to tuplestore_begin_heap() to control
this behavior. Is changing the tuple store API in this fashion OK?
- in order to store executor results in a tuple store, I added a new
CommandDest. This works well for the most part, with one exception: the
current DestFunction API doesn't provide enough information to allow the
Executor to store results into an arbitrary tuple store (where the
particular tuple store to use is chosen by the call site of
ExecutorRun). To workaround this, I've temporarily hacked up a solution
that works, but is not ideal: since the receiveTuple DestFunction is
passed the portal name, we can use that to lookup the Portal data
structure for the cursor and then use that to get at the tuple store the
Portal is using. This unnecessarily ties the Portal code with the
tupleReceiver code, but it works...
The proper fix for this is probably to change the DestFunction API --
Tom suggested passing the full QueryDesc to the receiveTuple function.
In that case, callers of ExecutorRun could "subclass" QueryDesc to add
any additional fields that their particular CommandDest needed to get
access to. This approach would work, but I'd like to think about it for
a little bit longer before deciding which route to go. In the mean time,
the code works fine, so I don't think a fix is urgent.
- (semi-related) I added a NO SCROLL keyword to DECLARE CURSOR, and
adjusted the behavior of SCROLL in accordance with the discussion on
-hackers.
- (unrelated) Cleaned up some SGML markup in sql.sgml, copy.sgml
Neil Conway
2003-03-27 17:51:29 +01:00
|
|
|
specified, data is transmitted via the connection between the
|
2003-04-15 15:25:08 +02:00
|
|
|
client and the server.
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Parameters</title>
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
2003-09-22 02:16:58 +02:00
|
|
|
<term><replaceable class="parameter">tablename</replaceable></term>
|
2003-04-15 15:25:08 +02:00
|
|
|
<listitem>
|
2001-01-03 21:04:10 +01:00
|
|
|
<para>
|
2003-09-30 03:56:11 +02:00
|
|
|
The name (optionally schema-qualified) of an existing table.
|
2003-04-15 15:25:08 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">column</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
An optional list of columns to be copied. If no column list is
|
|
|
|
specified, all columns will be used.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">filename</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The absolute path name of the input or output file.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>STDIN</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Specifies that input comes from the client application.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>STDOUT</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Specifies that output goes to the client application.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>BINARY</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-05-08 00:23:27 +02:00
|
|
|
Causes all data to be stored or read in binary format rather
|
2003-04-15 15:25:08 +02:00
|
|
|
than as text. You cannot specify the <option>DELIMITER</option>
|
|
|
|
or <option>NULL</option> options in binary mode.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>OIDS</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Specifies copying the OID for each row. (An error is raised if
|
|
|
|
<literal>OIDS</literal> is specified for a table that does not
|
|
|
|
have OIDs.)
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">delimiter</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The single character that separates columns within each row
|
2004-04-19 19:22:31 +02:00
|
|
|
(line) of the file. The default is a tab character in text mode,
|
|
|
|
a comma in <literal>CSV</> mode.
|
2003-04-15 15:25:08 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">null string</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The string that represents a null value. The default is
|
2004-04-19 19:22:31 +02:00
|
|
|
<literal>\N</literal> (backslash-N) in text mode, and a empty
|
|
|
|
value with no quotes in <literal>CSV</> mode. You might prefer an
|
|
|
|
empty string even in text mode for cases where you don't want to
|
|
|
|
distinguish nulls from empty strings.
|
2001-01-03 21:04:10 +01:00
|
|
|
</para>
|
1999-07-06 19:16:42 +02:00
|
|
|
|
2003-04-15 15:25:08 +02:00
|
|
|
<note>
|
|
|
|
<para>
|
2004-04-19 19:22:31 +02:00
|
|
|
When using <command>COPY FROM</command>, any data item that matches
|
2003-04-15 15:25:08 +02:00
|
|
|
this string will be stored as a null value, so you should make
|
|
|
|
sure that you use the same string as you used with
|
|
|
|
<command>COPY TO</command>.
|
|
|
|
</para>
|
|
|
|
</note>
|
2004-04-19 19:22:31 +02:00
|
|
|
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>CSV</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2004-04-21 02:34:18 +02:00
|
|
|
Enables Comma Separated Variable (<literal>CSV</>) mode. (Also
|
|
|
|
called Comma Separated Value). It sets the default
|
|
|
|
<literal>DELIMITER</> to comma, and <literal>QUOTE</> and
|
|
|
|
<literal>ESCAPE</> values to double-quote.
|
2004-04-19 19:22:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">quote</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Specifies the quotation character in <literal>CSV</> mode.
|
|
|
|
The default is double-quote.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><replaceable class="parameter">escape</replaceable></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2004-04-21 02:34:18 +02:00
|
|
|
Specifies the character that should appear before a
|
|
|
|
<literal>QUOTE</> data character value in <literal>CSV</> mode.
|
|
|
|
The default is the <literal>QUOTE</> value (usually double-quote).
|
2004-04-19 19:22:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2004-04-21 02:34:18 +02:00
|
|
|
<term><literal>FORCE QUOTE</></term>
|
2004-04-19 19:22:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2004-04-21 02:34:18 +02:00
|
|
|
In <literal>CSV</> <command>COPY TO</> mode, forces quoting to be
|
|
|
|
used for all non-<literal>NULL</> values in each specified column.
|
|
|
|
<literal>NULL</> output is never quoted.
|
2004-04-19 19:22:31 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2004-04-21 02:34:18 +02:00
|
|
|
<term><literal>FORCE NOT NULL</></term>
|
2004-04-19 19:22:31 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2004-04-21 02:34:18 +02:00
|
|
|
In <literal>CSV</> <command>COPY FROM</> mode, process each
|
|
|
|
specified column as though it were quoted and hance not a
|
|
|
|
<literal>NULL</> value. For the default <literal>null string</> in
|
|
|
|
<literal>CSV</> mode (<literal>''</>), this causes a missing
|
|
|
|
values to be input as a zero-length strings.
|
2004-04-19 19:22:31 +02:00
|
|
|
</para>
|
2003-04-15 15:25:08 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2004-04-19 19:22:31 +02:00
|
|
|
|
2003-04-15 15:25:08 +02:00
|
|
|
</variablelist>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Notes</title>
|
|
|
|
|
2001-08-11 01:09:30 +02:00
|
|
|
<para>
|
This patch implements holdable cursors, following the proposal
(materialization into a tuple store) discussed on pgsql-hackers earlier.
I've updated the documentation and the regression tests.
Notes on the implementation:
- I needed to change the tuple store API slightly -- it assumes that it
won't be used to hold data across transaction boundaries, so the temp
files that it uses for on-disk storage are automatically reclaimed at
end-of-transaction. I added a flag to tuplestore_begin_heap() to control
this behavior. Is changing the tuple store API in this fashion OK?
- in order to store executor results in a tuple store, I added a new
CommandDest. This works well for the most part, with one exception: the
current DestFunction API doesn't provide enough information to allow the
Executor to store results into an arbitrary tuple store (where the
particular tuple store to use is chosen by the call site of
ExecutorRun). To workaround this, I've temporarily hacked up a solution
that works, but is not ideal: since the receiveTuple DestFunction is
passed the portal name, we can use that to lookup the Portal data
structure for the cursor and then use that to get at the tuple store the
Portal is using. This unnecessarily ties the Portal code with the
tupleReceiver code, but it works...
The proper fix for this is probably to change the DestFunction API --
Tom suggested passing the full QueryDesc to the receiveTuple function.
In that case, callers of ExecutorRun could "subclass" QueryDesc to add
any additional fields that their particular CommandDest needed to get
access to. This approach would work, but I'd like to think about it for
a little bit longer before deciding which route to go. In the mean time,
the code works fine, so I don't think a fix is urgent.
- (semi-related) I added a NO SCROLL keyword to DECLARE CURSOR, and
adjusted the behavior of SCROLL in accordance with the discussion on
-hackers.
- (unrelated) Cleaned up some SGML markup in sql.sgml, copy.sgml
Neil Conway
2003-03-27 17:51:29 +01:00
|
|
|
<command>COPY</command> can only be used with plain tables, not
|
|
|
|
with views.
|
2001-08-11 01:09:30 +02:00
|
|
|
</para>
|
|
|
|
|
1998-12-29 03:24:47 +01:00
|
|
|
<para>
|
2003-05-08 00:23:27 +02:00
|
|
|
The <literal>BINARY</literal> key word causes all data to be
|
2000-04-19 01:43:24 +02:00
|
|
|
stored/read as binary format rather than as text. It is
|
2003-05-08 00:23:27 +02:00
|
|
|
somewhat faster than the normal text mode, but a binary-format
|
|
|
|
file is less portable across machine architectures and
|
|
|
|
<productname>PostgreSQL</productname> versions.
|
1998-12-29 03:24:47 +01:00
|
|
|
</para>
|
1999-07-22 17:09:15 +02:00
|
|
|
|
|
|
|
<para>
|
2003-05-08 00:23:27 +02:00
|
|
|
You must have select privilege on the table
|
2003-04-15 15:25:08 +02:00
|
|
|
whose values are read by <command>COPY TO</command>, and
|
2003-05-08 00:23:27 +02:00
|
|
|
insert privilege on the table into which values
|
|
|
|
are inserted by <command>COPY FROM</command>.
|
1999-07-22 17:09:15 +02:00
|
|
|
</para>
|
2001-01-03 21:04:10 +01:00
|
|
|
|
1999-07-22 17:09:15 +02:00
|
|
|
<para>
|
2001-01-03 21:04:10 +01:00
|
|
|
Files named in a <command>COPY</command> command are read or written
|
2003-04-15 15:25:08 +02:00
|
|
|
directly by the server, not by the client application. Therefore,
|
2001-01-03 21:04:10 +01:00
|
|
|
they must reside on or be accessible to the database server machine,
|
2002-06-20 18:00:44 +02:00
|
|
|
not the client. They must be accessible to and readable or writable
|
2003-09-11 23:42:20 +02:00
|
|
|
by the <productname>PostgreSQL</productname> user (the user ID the
|
2002-06-20 18:00:44 +02:00
|
|
|
server runs as), not the client. <command>COPY</command> naming a
|
|
|
|
file is only allowed to database superusers, since it allows reading
|
2003-04-15 15:25:08 +02:00
|
|
|
or writing any file that the server has privileges to access.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Do not confuse <command>COPY</command> with the
|
|
|
|
<application>psql</application> instruction
|
|
|
|
<command>\copy</command>. <command>\copy</command> invokes
|
|
|
|
<command>COPY FROM STDIN</command> or <command>COPY TO
|
|
|
|
STDOUT</command>, and then fetches/stores the data in a file
|
|
|
|
accessible to the <application>psql</application> client. Thus,
|
|
|
|
file accessibility and access rights depend on the client rather
|
|
|
|
than the server when <command>\copy</command> is used.
|
1999-07-22 17:09:15 +02:00
|
|
|
</para>
|
2001-01-03 21:04:10 +01:00
|
|
|
|
1999-07-22 17:09:15 +02:00
|
|
|
<para>
|
2002-03-22 20:20:45 +01:00
|
|
|
It is recommended that the file name used in <command>COPY</command>
|
2002-06-20 18:00:44 +02:00
|
|
|
always be specified as an absolute path. This is enforced by the
|
2003-04-15 15:25:08 +02:00
|
|
|
server in the case of <command>COPY TO</command>, but for
|
2002-06-20 18:00:44 +02:00
|
|
|
<command>COPY FROM</command> you do have the option of reading from
|
|
|
|
a file specified by a relative path. The path will be interpreted
|
2003-04-15 15:25:08 +02:00
|
|
|
relative to the working directory of the server process (somewhere below
|
|
|
|
the data directory), not the client's working directory.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
<command>COPY FROM</command> will invoke any triggers and check
|
|
|
|
constraints on the destination table. However, it will not invoke rules.
|
|
|
|
</para>
|
|
|
|
|
2004-04-19 19:22:31 +02:00
|
|
|
<para>
|
|
|
|
<command>COPY</command> input and output is affected by
|
|
|
|
<varname>DateStyle </varname>. For portability with other
|
|
|
|
<productname>PostgreSQL</productname> installations which might use
|
|
|
|
non-default <varname>DateStyle</varname> settings,
|
|
|
|
<varname>DateStyle</varname> should be set to <literal>ISO</> before
|
|
|
|
using <command>COPY</>. In <literal>CSV</> mode, use <literal>ISO</>
|
|
|
|
or a <varname>DateStyle</varname> setting appropriate for the
|
|
|
|
external application.
|
|
|
|
</para>
|
|
|
|
|
2003-04-15 15:25:08 +02:00
|
|
|
<para>
|
|
|
|
<command>COPY</command> stops operation at the first error. This
|
|
|
|
should not lead to problems in the event of a <command>COPY
|
|
|
|
TO</command>, but the target table will already have received
|
|
|
|
earlier rows in a <command>COPY FROM</command>. These rows will not
|
|
|
|
be visible or accessible, but they still occupy disk space. This may
|
|
|
|
amount to a considerable amount of wasted disk space if the failure
|
|
|
|
happened well into a large copy operation. You may wish to invoke
|
|
|
|
<command>VACUUM</command> to recover the wasted space.
|
1999-07-22 17:09:15 +02:00
|
|
|
</para>
|
1998-05-13 07:34:00 +02:00
|
|
|
</refsect1>
|
1998-12-29 03:24:47 +01:00
|
|
|
|
2003-04-15 15:25:08 +02:00
|
|
|
<refsect1>
|
1998-09-16 16:43:12 +02:00
|
|
|
<title>File Formats</title>
|
2003-04-15 15:25:08 +02:00
|
|
|
|
1998-05-13 07:34:00 +02:00
|
|
|
<refsect2>
|
1998-09-16 16:43:12 +02:00
|
|
|
<title>Text Format</title>
|
2003-04-15 15:25:08 +02:00
|
|
|
|
1998-05-13 07:34:00 +02:00
|
|
|
<para>
|
2003-04-15 15:25:08 +02:00
|
|
|
When <command>COPY</command> is used without the <literal>BINARY</literal> option,
|
2004-04-19 19:22:31 +02:00
|
|
|
the data read or written is a text file with one line per table row,
|
|
|
|
unless <literal>CSV</> mode is used.
|
2003-04-15 15:25:08 +02:00
|
|
|
Columns in a row are separated by the delimiter character.
|
|
|
|
The column values themselves are strings generated by the
|
2002-02-12 22:25:41 +01:00
|
|
|
output function, or acceptable to the input function, of each
|
2003-10-06 04:38:53 +02:00
|
|
|
attribute's data type. The specified null string is used in
|
2003-04-15 15:25:08 +02:00
|
|
|
place of columns that are null.
|
2002-08-02 20:15:10 +02:00
|
|
|
<command>COPY FROM</command> will raise an error if any line of the
|
|
|
|
input file contains more or fewer columns than are expected.
|
2003-04-15 15:25:08 +02:00
|
|
|
If <literal>OIDS</literal> is specified, the OID is read or written as the first column,
|
|
|
|
preceding the user data columns.
|
1998-05-13 07:34:00 +02:00
|
|
|
</para>
|
2003-04-15 15:25:08 +02:00
|
|
|
|
2002-02-12 22:25:41 +01:00
|
|
|
<para>
|
|
|
|
End of data can be represented by a single line containing just
|
|
|
|
backslash-period (<literal>\.</>). An end-of-data marker is
|
2003-04-15 15:25:08 +02:00
|
|
|
not necessary when reading from a file, since the end of file
|
2003-05-08 00:23:27 +02:00
|
|
|
serves perfectly well; it is needed only when copying data to or from
|
|
|
|
client applications using pre-3.0 client protocol.
|
2002-02-12 22:25:41 +01:00
|
|
|
</para>
|
2003-04-15 15:25:08 +02:00
|
|
|
|
2002-02-12 22:25:41 +01:00
|
|
|
<para>
|
|
|
|
Backslash characters (<literal>\</>) may be used in the
|
2002-06-20 18:00:44 +02:00
|
|
|
<command>COPY</command> data to quote data characters that might
|
|
|
|
otherwise be taken as row or column delimiters. In particular, the
|
|
|
|
following characters <emphasis>must</> be preceded by a backslash if
|
2003-04-15 15:25:08 +02:00
|
|
|
they appear as part of a column value: backslash itself,
|
2003-04-19 21:55:37 +02:00
|
|
|
newline, carriage return, and the current delimiter character.
|
2001-01-03 21:04:10 +01:00
|
|
|
</para>
|
2003-04-15 15:25:08 +02:00
|
|
|
|
2003-10-06 04:38:53 +02:00
|
|
|
<para>
|
|
|
|
The specified null string is sent by <command>COPY TO</command> without
|
|
|
|
adding any backslashes; conversely, <command>COPY FROM</command> matches
|
|
|
|
the input against the null string before removing backslashes. Therefore,
|
|
|
|
a null string such as <literal>\N</literal> cannot be confused with
|
|
|
|
the actual data value <literal>\N</literal> (which would be represented
|
|
|
|
as <literal>\\N</literal>).
|
|
|
|
</para>
|
|
|
|
|
2001-01-03 21:04:10 +01:00
|
|
|
<para>
|
2002-02-12 22:25:41 +01:00
|
|
|
The following special backslash sequences are recognized by
|
|
|
|
<command>COPY FROM</command>:
|
|
|
|
|
|
|
|
<informaltable>
|
|
|
|
<tgroup cols="2">
|
|
|
|
<thead>
|
|
|
|
<row>
|
|
|
|
<entry>Sequence</entry>
|
|
|
|
<entry>Represents</entry>
|
|
|
|
</row>
|
|
|
|
</thead>
|
|
|
|
|
|
|
|
<tbody>
|
|
|
|
<row>
|
|
|
|
<entry><literal>\b</></entry>
|
|
|
|
<entry>Backspace (ASCII 8)</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><literal>\f</></entry>
|
|
|
|
<entry>Form feed (ASCII 12)</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><literal>\n</></entry>
|
|
|
|
<entry>Newline (ASCII 10)</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><literal>\r</></entry>
|
|
|
|
<entry>Carriage return (ASCII 13)</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><literal>\t</></entry>
|
|
|
|
<entry>Tab (ASCII 9)</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><literal>\v</></entry>
|
|
|
|
<entry>Vertical tab (ASCII 11)</entry>
|
|
|
|
</row>
|
|
|
|
<row>
|
|
|
|
<entry><literal>\</><replaceable>digits</></entry>
|
|
|
|
<entry>Backslash followed by one to three octal digits specifies
|
|
|
|
the character with that numeric code</entry>
|
|
|
|
</row>
|
|
|
|
</tbody>
|
|
|
|
</tgroup>
|
|
|
|
</informaltable>
|
|
|
|
|
|
|
|
Presently, <command>COPY TO</command> will never emit an octal-digits
|
|
|
|
backslash sequence, but it does use the other sequences listed above
|
|
|
|
for those control characters.
|
1998-05-13 07:34:00 +02:00
|
|
|
</para>
|
2003-04-15 15:25:08 +02:00
|
|
|
|
1998-05-13 07:34:00 +02:00
|
|
|
<para>
|
2003-10-06 04:38:53 +02:00
|
|
|
Any other backslashed character that is not mentioned in the above table
|
|
|
|
will be taken to represent itself. However, beware of adding backslashes
|
|
|
|
unnecessarily, since that might accidentally produce a string matching the
|
|
|
|
end-of-data marker (<literal>\.</>) or the null string (<literal>\N</> by
|
|
|
|
default). These strings will be recognized before any other backslash
|
|
|
|
processing is done.
|
1998-05-13 07:34:00 +02:00
|
|
|
</para>
|
2003-04-15 15:25:08 +02:00
|
|
|
|
1998-05-13 07:34:00 +02:00
|
|
|
<para>
|
2002-02-12 22:25:41 +01:00
|
|
|
It is strongly recommended that applications generating COPY data convert
|
|
|
|
data newlines and carriage returns to the <literal>\n</> and
|
2003-04-15 15:25:08 +02:00
|
|
|
<literal>\r</> sequences respectively. At present it is
|
2003-04-19 21:55:37 +02:00
|
|
|
possible to represent a data carriage return by a backslash and carriage
|
|
|
|
return, and to represent a data newline by a backslash and newline.
|
|
|
|
However, these representations might not be accepted in future releases.
|
2003-05-08 00:23:27 +02:00
|
|
|
They are also highly vulnerable to corruption if the COPY file is
|
|
|
|
transferred across different machines (for example, from Unix to Windows
|
|
|
|
or vice versa).
|
2002-02-12 22:25:41 +01:00
|
|
|
</para>
|
2003-04-15 15:25:08 +02:00
|
|
|
|
2002-02-12 22:25:41 +01:00
|
|
|
<para>
|
2003-04-19 21:55:37 +02:00
|
|
|
<command>COPY TO</command> will terminate each row with a Unix-style
|
2003-09-30 03:56:11 +02:00
|
|
|
newline (<quote><literal>\n</></>). Servers running on MS Windows instead
|
|
|
|
output carriage return/newline (<quote><literal>\r\n</></>), but only for
|
|
|
|
<command>COPY</> to a server file; for consistency across platforms,
|
|
|
|
<command>COPY TO STDOUT</> always sends <quote><literal>\n</></>
|
|
|
|
regardless of server platform.
|
2003-04-20 03:52:55 +02:00
|
|
|
<command>COPY FROM</command> can handle lines ending with newlines,
|
2003-09-30 03:56:11 +02:00
|
|
|
carriage returns, or carriage return/newlines. To reduce the risk of
|
|
|
|
error due to un-backslashed newlines or carriage returns that were
|
|
|
|
meant as data, <command>COPY FROM</command> will complain if the line
|
|
|
|
endings in the input are not all alike.
|
1998-05-13 07:34:00 +02:00
|
|
|
</para>
|
|
|
|
</refsect2>
|
1999-07-22 17:09:15 +02:00
|
|
|
|
2004-04-19 19:22:31 +02:00
|
|
|
<refsect2>
|
|
|
|
<title>CSV Format</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
This format is used for importing and exporting the Comma
|
|
|
|
Separated Variable (<literal>CSV</>) file format used by many other
|
|
|
|
programs, such as spreadsheets. Instead of the escaping used by
|
|
|
|
<productname>PostgreSQL</productname>'s standard text mode, it
|
|
|
|
produces and recognises the common CSV escaping mechanism.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The values in each record are separated by the <literal>DELIMITER</>
|
|
|
|
character. If the value contains the delimiter character, the
|
|
|
|
<literal>QUOTE</> character, the <literal>NULL</> string, a carriage
|
|
|
|
return, or line feed character, then the whole value is prefixed and
|
|
|
|
suffixed by the <literal>QUOTE</> character, and any occurrence
|
|
|
|
within the value of a <literal>QUOTE</> character or the
|
|
|
|
<literal>ESCAPE</> character is preceded by the escape character.
|
2004-04-21 02:34:18 +02:00
|
|
|
You can also use <literal>FORCE QUOTE</> to force quotes when outputting
|
2004-04-19 19:22:31 +02:00
|
|
|
non-<literal>NULL</> values in specific columns.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
In general, the <literal>CSV</> format has no way to distinguish a
|
|
|
|
<literal>NULL</> from an empty string.
|
|
|
|
<productname>PostgreSQL</productname>'s COPY handles this by
|
|
|
|
quoting. A <literal>NULL</> is output as the <literal>NULL</> string
|
|
|
|
and is not quoted, while a data value matching the <literal>NULL</> string
|
|
|
|
is quoted. Therefore, using the default settings, a <literal>NULL</> is
|
|
|
|
written as an unquoted empty string, while an empty string is
|
|
|
|
written with double quotes (<literal>""</>). Reading values follows
|
2004-04-21 02:34:18 +02:00
|
|
|
similar rules. You can use <literal>FORCE NOT NULL</> to prevent <literal>NULL</>
|
2004-04-19 19:22:31 +02:00
|
|
|
input comparisons for specific columns.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
CSV mode will both recognize and produce CSV files with quoted
|
|
|
|
values containing embedded carriage returns and line feeds. Thus
|
|
|
|
the files are not strictly one line per table row like text-mode
|
|
|
|
files.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
Many programs produce strange and occasionally perverse CSV files,
|
|
|
|
so the file format is more a convention than a standard. Thus you
|
|
|
|
might encounter some files that cannot be imported using this
|
|
|
|
mechanism, and <command>COPY</> might produce files that other
|
|
|
|
programs can not process.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
|
|
|
|
</refsect2>
|
|
|
|
|
1998-05-13 07:34:00 +02:00
|
|
|
<refsect2>
|
1998-09-16 16:43:12 +02:00
|
|
|
<title>Binary Format</title>
|
2003-04-15 15:25:08 +02:00
|
|
|
|
1998-05-13 07:34:00 +02:00
|
|
|
<para>
|
2001-01-03 21:04:10 +01:00
|
|
|
The file format used for <command>COPY BINARY</command> changed in
|
2003-09-11 23:42:20 +02:00
|
|
|
<productname>PostgreSQL</productname> 7.4. The new format consists
|
2003-04-15 15:25:08 +02:00
|
|
|
of a file header, zero or more tuples containing the row data, and
|
2003-08-17 06:33:02 +02:00
|
|
|
a file trailer. Headers and data are now in network byte order.
|
1998-05-13 07:34:00 +02:00
|
|
|
</para>
|
2001-01-03 21:04:10 +01:00
|
|
|
|
|
|
|
<refsect3>
|
2003-04-15 15:25:08 +02:00
|
|
|
<title>File Header</title>
|
|
|
|
|
2001-01-03 21:04:10 +01:00
|
|
|
<para>
|
2003-05-08 00:23:27 +02:00
|
|
|
The file header consists of 15 bytes of fixed fields, followed
|
2001-01-03 21:04:10 +01:00
|
|
|
by a variable-length header extension area. The fixed fields are:
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>Signature</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-05-08 00:23:27 +02:00
|
|
|
11-byte sequence <literal>PGCOPY\n\377\r\n\0</> --- note that the zero byte
|
2001-01-03 21:04:10 +01:00
|
|
|
is a required part of the signature. (The signature is designed to allow
|
|
|
|
easy identification of files that have been munged by a non-8-bit-clean
|
2003-04-19 21:55:37 +02:00
|
|
|
transfer. This signature will be changed by end-of-line-translation
|
2003-04-15 15:25:08 +02:00
|
|
|
filters, dropped zero bytes, dropped high bits, or parity changes.)
|
2001-01-03 21:04:10 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term>Flags field</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-05-08 00:23:27 +02:00
|
|
|
32-bit integer bit mask to denote important aspects of the file format. Bits
|
|
|
|
are numbered from 0 (<acronym>LSB</>) to 31 (<acronym>MSB</>). Note that
|
|
|
|
this field is stored in network byte order (most significant byte first),
|
|
|
|
as are all the integer fields used in the file format. Bits
|
2002-06-20 18:00:44 +02:00
|
|
|
16-31 are reserved to denote critical file format issues; a reader
|
|
|
|
should abort if it finds an unexpected bit set in this range. Bits 0-15
|
|
|
|
are reserved to signal backwards-compatible format issues; a reader
|
|
|
|
should simply ignore any unexpected bits set in this range. Currently
|
|
|
|
only one flag bit is defined, and the rest must be zero:
|
2001-01-03 21:04:10 +01:00
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term>Bit 16</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-04-15 15:25:08 +02:00
|
|
|
if 1, OIDs are included in the data; if 0, not
|
2001-01-03 21:04:10 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term>Header extension area length</term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2003-04-15 15:25:08 +02:00
|
|
|
32-bit integer, length in bytes of remainder of header, not including self.
|
|
|
|
Currently, this is zero, and the first tuple follows
|
2001-01-03 21:04:10 +01:00
|
|
|
immediately. Future changes to the format might allow additional data
|
|
|
|
to be present in the header. A reader should silently skip over any header
|
|
|
|
extension data it does not know what to do with.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The header extension area is envisioned to contain a sequence of
|
|
|
|
self-identifying chunks. The flags field is not intended to tell readers
|
|
|
|
what is in the extension area. Specific design of header extension contents
|
|
|
|
is left for a later release.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
This design allows for both backwards-compatible header additions (add
|
|
|
|
header extension chunks, or set low-order flag bits) and
|
|
|
|
non-backwards-compatible changes (set high-order flag bits to signal such
|
|
|
|
changes, and add supporting data to the extension area if needed).
|
|
|
|
</para>
|
|
|
|
</refsect3>
|
|
|
|
|
|
|
|
<refsect3>
|
2003-04-15 15:25:08 +02:00
|
|
|
<title>Tuples</title>
|
2001-01-03 21:04:10 +01:00
|
|
|
<para>
|
2003-04-15 15:25:08 +02:00
|
|
|
Each tuple begins with a 16-bit integer count of the number of fields in the
|
2003-05-08 00:23:27 +02:00
|
|
|
tuple. (Presently, all tuples in a table will have the same count, but that
|
|
|
|
might not always be true.) Then, repeated for each field in the tuple, there
|
|
|
|
is a 32-bit length word followed by that many bytes of field data. (The
|
|
|
|
length word does not include itself, and can be zero.) As a special case,
|
|
|
|
-1 indicates a NULL field value. No value bytes follow in the NULL case.
|
2001-01-03 21:04:10 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2003-05-08 00:23:27 +02:00
|
|
|
There is no alignment padding or any other extra data between fields.
|
2001-01-03 21:04:10 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2003-05-08 00:23:27 +02:00
|
|
|
Presently, all data values in a <command>COPY BINARY</command> file are
|
|
|
|
assumed to be in binary format (format code one). It is anticipated that a
|
|
|
|
future extension may add a header field that allows per-column format codes
|
|
|
|
to be specified.
|
2001-01-03 21:04:10 +01:00
|
|
|
</para>
|
|
|
|
|
2003-08-17 06:33:02 +02:00
|
|
|
<para>
|
|
|
|
To determine the appropriate binary format for the actual tuple data you
|
2003-09-11 23:42:20 +02:00
|
|
|
should consult the <productname>PostgreSQL</productname> source, in
|
2003-08-17 06:33:02 +02:00
|
|
|
particular the <function>*send</> and <function>*recv</> functions for
|
2003-09-30 03:56:11 +02:00
|
|
|
each column's data type (typically these functions are found in the
|
|
|
|
<filename>src/backend/utils/adt/</filename> directory of the source
|
|
|
|
distribution).
|
2003-08-17 06:33:02 +02:00
|
|
|
</para>
|
|
|
|
|
2001-01-03 21:04:10 +01:00
|
|
|
<para>
|
2003-04-15 15:25:08 +02:00
|
|
|
If OIDs are included in the file, the OID field immediately follows the
|
2001-01-03 21:04:10 +01:00
|
|
|
field-count word. It is a normal field except that it's not included
|
2003-05-08 00:23:27 +02:00
|
|
|
in the field-count. In particular it has a length word --- this will allow
|
2003-04-15 15:25:08 +02:00
|
|
|
handling of 4-byte vs. 8-byte OIDs without too much pain, and will allow
|
|
|
|
OIDs to be shown as null if that ever proves desirable.
|
2001-01-03 21:04:10 +01:00
|
|
|
</para>
|
|
|
|
</refsect3>
|
|
|
|
|
|
|
|
<refsect3>
|
2003-04-15 15:25:08 +02:00
|
|
|
<title>File Trailer</title>
|
|
|
|
|
2001-01-03 21:04:10 +01:00
|
|
|
<para>
|
2003-05-08 00:23:27 +02:00
|
|
|
The file trailer consists of a 16-bit integer word containing -1. This
|
|
|
|
is easily distinguished from a tuple's field-count word.
|
2001-01-03 21:04:10 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
A reader should report an error if a field-count word is neither -1
|
|
|
|
nor the expected number of columns. This provides an extra
|
|
|
|
check against somehow getting out of sync with the data.
|
|
|
|
</para>
|
|
|
|
</refsect3>
|
1998-05-13 07:34:00 +02:00
|
|
|
</refsect2>
|
|
|
|
</refsect1>
|
|
|
|
|
2003-04-15 15:25:08 +02:00
|
|
|
<refsect1>
|
|
|
|
<title>Examples</title>
|
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<para>
|
2003-04-15 15:25:08 +02:00
|
|
|
The following example copies a table to the client
|
|
|
|
using the vertical bar (<literal>|</literal>) as the field delimiter:
|
|
|
|
<programlisting>
|
|
|
|
COPY country TO STDOUT WITH DELIMITER '|';
|
|
|
|
</programlisting>
|
1999-07-06 19:16:42 +02:00
|
|
|
</para>
|
2003-04-15 15:25:08 +02:00
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<para>
|
2003-04-15 15:25:08 +02:00
|
|
|
To copy data from a file into the <literal>country</> table:
|
|
|
|
<programlisting>
|
1998-09-16 16:43:12 +02:00
|
|
|
COPY country FROM '/usr1/proj/bray/sql/country_data';
|
2003-04-15 15:25:08 +02:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
|
1999-07-06 19:16:42 +02:00
|
|
|
<para>
|
2002-06-20 18:00:44 +02:00
|
|
|
Here is a sample of data suitable for copying into a table from
|
2003-05-08 00:23:27 +02:00
|
|
|
<literal>STDIN</literal>:
|
2003-04-15 15:25:08 +02:00
|
|
|
<programlisting>
|
2001-01-03 21:04:10 +01:00
|
|
|
AF AFGHANISTAN
|
|
|
|
AL ALBANIA
|
|
|
|
DZ ALGERIA
|
|
|
|
ZM ZAMBIA
|
|
|
|
ZW ZIMBABWE
|
2003-04-15 15:25:08 +02:00
|
|
|
</programlisting>
|
|
|
|
Note that the white space on each line is actually a tab character.
|
2001-01-03 21:04:10 +01:00
|
|
|
</para>
|
2003-04-15 15:25:08 +02:00
|
|
|
|
2003-05-08 00:23:27 +02:00
|
|
|
<para>
|
2003-05-09 23:19:50 +02:00
|
|
|
The following is the same data, output in binary format.
|
|
|
|
The data is shown after filtering through the
|
2003-04-15 15:25:08 +02:00
|
|
|
Unix utility <command>od -c</command>. The table has three columns;
|
|
|
|
the first has type <type>char(2)</type>, the second has type <type>text</type>,
|
|
|
|
and the third has type <type>integer</type>. All the rows have a null value
|
|
|
|
in the third column.
|
|
|
|
<programlisting>
|
2003-05-09 23:19:50 +02:00
|
|
|
0000000 P G C O P Y \n 377 \r \n \0 \0 \0 \0 \0 \0
|
|
|
|
0000020 \0 \0 \0 \0 003 \0 \0 \0 002 A F \0 \0 \0 013 A
|
|
|
|
0000040 F G H A N I S T A N 377 377 377 377 \0 003
|
|
|
|
0000060 \0 \0 \0 002 A L \0 \0 \0 007 A L B A N I
|
|
|
|
0000100 A 377 377 377 377 \0 003 \0 \0 \0 002 D Z \0 \0 \0
|
|
|
|
0000120 007 A L G E R I A 377 377 377 377 \0 003 \0 \0
|
|
|
|
0000140 \0 002 Z M \0 \0 \0 006 Z A M B I A 377 377
|
|
|
|
0000160 377 377 \0 003 \0 \0 \0 002 Z W \0 \0 \0 \b Z I
|
|
|
|
0000200 M B A B W E 377 377 377 377 377 377
|
2003-04-15 15:25:08 +02:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
1998-05-13 07:34:00 +02:00
|
|
|
</refsect1>
|
|
|
|
|
2003-04-15 15:25:08 +02:00
|
|
|
<refsect1>
|
|
|
|
<title>Compatibility</title>
|
1998-05-13 07:34:00 +02:00
|
|
|
|
2003-04-15 15:25:08 +02:00
|
|
|
<para>
|
|
|
|
There is no <command>COPY</command> statement in the SQL standard.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2003-12-14 00:59:07 +01:00
|
|
|
The following syntax was used before <productname>PostgreSQL</>
|
|
|
|
version 7.3 and is still supported:
|
2003-04-15 15:25:08 +02:00
|
|
|
|
|
|
|
<synopsis>
|
2003-09-22 02:16:58 +02:00
|
|
|
COPY [ BINARY ] <replaceable class="parameter">tablename</replaceable> [ WITH OIDS ]
|
2003-04-15 15:25:08 +02:00
|
|
|
FROM { '<replaceable class="parameter">filename</replaceable>' | STDIN }
|
|
|
|
[ [USING] DELIMITERS '<replaceable class="parameter">delimiter</replaceable>' ]
|
|
|
|
[ WITH NULL AS '<replaceable class="parameter">null string</replaceable>' ]
|
|
|
|
|
2003-09-22 02:16:58 +02:00
|
|
|
COPY [ BINARY ] <replaceable class="parameter">tablename</replaceable> [ WITH OIDS ]
|
2003-04-15 15:25:08 +02:00
|
|
|
TO { '<replaceable class="parameter">filename</replaceable>' | STDOUT }
|
|
|
|
[ [USING] DELIMITERS '<replaceable class="parameter">delimiter</replaceable>' ]
|
|
|
|
[ WITH NULL AS '<replaceable class="parameter">null string</replaceable>' ]
|
|
|
|
</synopsis>
|
|
|
|
</para>
|
1998-05-13 07:34:00 +02:00
|
|
|
</refsect1>
|
1999-07-06 19:16:42 +02:00
|
|
|
</refentry>
|
1998-05-13 07:34:00 +02:00
|
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
1999-07-06 19:16:42 +02:00
|
|
|
sgml-omittag:nil
|
1998-05-13 07:34:00 +02:00
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
sgml-parent-document:nil
|
|
|
|
sgml-default-dtd-file:"../reference.ced"
|
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:"/usr/lib/sgml/catalog"
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
-->
|