1
1
<!--
2
- $PostgreSQL: pgsql/doc/src/sgml/ref/copy.sgml,v 1.74 2006/04/22 03:03:11 momjian Exp $
2
+ $PostgreSQL: pgsql/doc/src/sgml/ref/copy.sgml,v 1.75 2006/08/30 23:34:20 tgl Exp $
3
3
PostgreSQL documentation
4
4
-->
5
5
@@ -33,7 +33,7 @@ COPY <replaceable class="parameter">tablename</replaceable> [ ( <replaceable cla
33
33
[ ESCAPE [ AS ] '<replaceable class="parameter">escape</replaceable>' ]
34
34
[ FORCE NOT NULL <replaceable class="parameter">column</replaceable> [, ...] ]
35
35
36
- COPY <replaceable class="parameter">tablename</replaceable> [ ( <replaceable class="parameter">column</replaceable> [, ...] ) ]
36
+ COPY{ <replaceable class="parameter">tablename</replaceable> [ ( <replaceable class="parameter">column</replaceable> [, ...] ) ] | ( <replaceable class="parameter">query</replaceable> ) }
37
37
TO { '<replaceable class="parameter">filename</replaceable>' | STDOUT }
38
38
[ [ WITH ]
39
39
[ BINARY ]
@@ -57,7 +57,8 @@ COPY <replaceable class="parameter">tablename</replaceable> [ ( <replaceable cla
57
57
files. <command>COPY TO</command> copies the contents of a table
58
58
<emphasis>to</> a file, while <command>COPY FROM</command> copies
59
59
data <emphasis>from</> a file to a table (appending the data to
60
- whatever is in the table already).
60
+ whatever is in the table already). <command>COPY TO</command>
61
+ can also copy the results of a <command>SELECT</> query.
61
62
</para>
62
63
63
64
<para>
@@ -97,7 +98,17 @@ COPY <replaceable class="parameter">tablename</replaceable> [ ( <replaceable cla
97
98
<listitem>
98
99
<para>
99
100
An optional list of columns to be copied. If no column list is
100
- specified, all columns will be used.
101
+ specified, all columns of the table will be copied.
102
+ </para>
103
+ </listitem>
104
+ </varlistentry>
105
+
106
+ <varlistentry>
107
+ <term><replaceable class="parameter">query</replaceable></term>
108
+ <listitem>
109
+ <para>
110
+ A <command>SELECT</> query whose results are to be copied.
111
+ Note that parentheses are required around the query.
101
112
</para>
102
113
</listitem>
103
114
</varlistentry>
@@ -148,7 +159,8 @@ COPY <replaceable class="parameter">tablename</replaceable> [ ( <replaceable cla
148
159
<para>
149
160
Specifies copying the OID for each row. (An error is raised if
150
161
<literal>OIDS</literal> is specified for a table that does not
151
- have OIDs.)
162
+ have OIDs, or in the case of copying a <replaceable
163
+ class="parameter">query</replaceable>.)
152
164
</para>
153
165
</listitem>
154
166
</varlistentry>
@@ -265,7 +277,7 @@ COPY <replaceable class="parameter">tablename</replaceable> [ ( <replaceable cla
265
277
COPY <replaceable class="parameter">count</replaceable>
266
278
</screen>
267
279
The <replaceable class="parameter">count</replaceable> is the number
268
- of rowsinserted into or copied from the table .
280
+ of rows copied.
269
281
</para>
270
282
</refsect1>
271
283
@@ -274,7 +286,8 @@ COPY <replaceable class="parameter">count</replaceable>
274
286
275
287
<para>
276
288
<command>COPY</command> can only be used with plain tables, not
277
- with views.
289
+ with views. However, you can write <literal>COPY (SELECT * FROM
290
+ <replaceable class="parameter">viewname</replaceable>) TO ...</literal>.
278
291
</para>
279
292
280
293
<para>
@@ -320,8 +333,8 @@ COPY <replaceable class="parameter">count</replaceable>
320
333
server in the case of <command>COPY TO</command>, but for
321
334
<command>COPY FROM</command> you do have the option of reading from
322
335
a file specified by a relative path. The path will be interpreted
323
- relative to the working directory of the server process (somewhere below
324
- the data directory), not the client's working directory.
336
+ relative to the working directory of the server process (normally
337
+ thecluster's data directory), not the client's working directory.
325
338
</para>
326
339
327
340
<para>
@@ -737,14 +750,9 @@ COPY country FROM '/usr1/proj/bray/sql/country_data';
737
750
</para>
738
751
739
752
<para>
740
- To copy into a file just the countries whose names start with 'A'
741
- using a temporary table which is automatically deleted:
753
+ To copy into a file just the countries whose names start with 'A':
742
754
<programlisting>
743
- BEGIN;
744
- CREATE TEMP TABLE a_list_countries AS
745
- SELECT * FROM country WHERE country_name LIKE 'A%';
746
- COPY a_list_countries TO '/usr1/proj/bray/sql/a_list_countries.copy';
747
- ROLLBACK;
755
+ COPY (SELECT * FROM country WHERE country_name LIKE 'A%') TO '/usr1/proj/bray/sql/a_list_countries.copy';
748
756
</programlisting>
749
757
</para>
750
758