mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Allow COPY FROM to filter data using WHERE conditions
Extends the COPY FROM command with a WHERE condition, which allows doing various types of filtering while importing the data (random sampling, condition on a data column, etc.). Until now such filtering required either preprocessing of the input data, or importing all data and then filtering in the database. COPY FROM ... WHERE is an easy-to-use and low-overhead alternative for most simple cases. Author: Surafel Temesgen Reviewed-by: Tomas Vondra, Masahiko Sawada, Lim Myungkyu Discussion: https://www.postgresql.org/message-id/flat/CALAY4q_DdpWDuB5-Zyi-oTtO2uSk8pmy+dupiRe3AvAc++1imA@mail.gmail.com
This commit is contained in:
@ -25,6 +25,7 @@ PostgreSQL documentation
|
||||
COPY <replaceable class="parameter">table_name</replaceable> [ ( <replaceable class="parameter">column_name</replaceable> [, ...] ) ]
|
||||
FROM { '<replaceable class="parameter">filename</replaceable>' | PROGRAM '<replaceable class="parameter">command</replaceable>' | STDIN }
|
||||
[ [ WITH ] ( <replaceable class="parameter">option</replaceable> [, ...] ) ]
|
||||
[ WHERE <replaceable class="parameter">condition</replaceable> ]
|
||||
|
||||
COPY { <replaceable class="parameter">table_name</replaceable> [ ( <replaceable class="parameter">column_name</replaceable> [, ...] ) ] | ( <replaceable class="parameter">query</replaceable> ) }
|
||||
TO { '<replaceable class="parameter">filename</replaceable>' | PROGRAM '<replaceable class="parameter">command</replaceable>' | STDOUT }
|
||||
@ -353,6 +354,32 @@ COPY { <replaceable class="parameter">table_name</replaceable> [ ( <replaceable
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><literal>WHERE</literal></term>
|
||||
<listitem>
|
||||
<para>
|
||||
The optional <literal>WHERE</literal> clause has the general form
|
||||
<synopsis>
|
||||
WHERE <replaceable class="parameter">condition</replaceable>
|
||||
</synopsis>
|
||||
where <replaceable class="parameter">condition</replaceable> is
|
||||
any expression that evaluates to a result of type
|
||||
<type>boolean</type>. Any row that does not satisfy this
|
||||
condition will not be inserted to the table. A row satisfies the
|
||||
condition if it returns true when the actual row values are
|
||||
substituted for any variable references.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Currently, subqueries are not allowed in <literal>WHERE</literal>
|
||||
expressions, and the evaluation does not see any changes made by the
|
||||
<command>COPY</command> itself (this matters when the expression
|
||||
contains calls to <literal>VOLATILE</literal> functions).
|
||||
</para>
|
||||
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
|
Reference in New Issue
Block a user