Thread: SQL COPY Command

SQL COPY Command

From
"Van Ingen, Lane"
Date:
Will this command APPEND TO or REPLACE data in an existing table ?
 
The documentation doesn't seem to indicate.

Re: SQL COPY Command

From
Tom Lane
Date:
"Van Ingen, Lane" <lvaningen@ESNCC.com> writes:
> Will this command APPEND TO or REPLACE data in an existing table ?
> The documentation doesn't seem to indicate.

The first paragraph on the COPY reference page is

COPY moves data between PostgreSQL tables and standard file-system
files. COPY TO copies the contents of a table to a file, while COPY FROM
copies data from a file to a table (appending the data to whatever is in
the table already).


            regards, tom lane

Re: SQL COPY Command

From
"Keith Worthington"
Date:
On Wed, 27 Apr 2005 10:56:09 -0400, Tom Lane wrote
> "Van Ingen, Lane" <lvaningen@ESNCC.com> writes:
> > Will this command APPEND TO or REPLACE data in an existing table ?
> > The documentation doesn't seem to indicate.
>
> The first paragraph on the COPY reference page is
>
> COPY moves data between PostgreSQL tables and standard file-system
> files. COPY TO copies the contents of a table to a file, while COPY FROM
> copies data from a file to a table (appending the data to whatever
> is in the table already).
>
>             regards, tom lane

Sheesh, how did I miss that?

Oh well,  Documentation talks the talk but testing walks the walk. ;-)

Kind Regards,
Keith

Re: SQL COPY Command

From
"Keith Worthington"
Date:
On Wed, 27 Apr 2005 10:43:58 -0400, Van Ingen, Lane wrote
> Will this command APPEND TO or REPLACE data in an existing table ?
>
> The documentation doesn't seem to indicate.
>

You appear to be correct.  I was not able to find the answer in the
documentation either.

Testing indicates that the data will be appended.  If a primary key is defined
on the table and any of the contents of the COPY violate that key then the
entire contents of the COPY are rejected.  During large copies this can result
in a lot of wasted space.

Kind Regards,
Keith