Thread: COPY performance vs insert

COPY performance vs insert

From
PG Doc comments form
Date:
The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/12/populate.html
Description:

I think this could be clearer. In particular, performance of COPY vs INSERT
from a query (INSERT INTO ... SELECT FROM ...) or INSERT with a list of rows
(INSERT INTO ... VALUES (), (), (), ...)
Is there any performance benefit with COPY in those cases?

Re: COPY performance vs insert

From
Bruce Momjian
Date:
On Wed, Feb 12, 2020 at 09:25:05AM +0000, PG Doc comments form wrote:
> The following documentation comment has been logged on the website:
> 
> Page: https://www.postgresql.org/docs/12/populate.html
> Description:
> 
> I think this could be clearer. In particular, performance of COPY vs INSERT
> from a query (INSERT INTO ... SELECT FROM ...) or INSERT with a list of rows
> (INSERT INTO ... VALUES (), (), (), ...)
> Is there any performance benefit with COPY in those cases?

COPY input/outputs rows in bulk, so it is still faster to do COPY than
INSERT INTO ... SELECT FROM or INSERT INTO ... VALUES.  You can run
tests to prove it.

-- 
  Bruce Momjian  <bruce@momjian.us>        https://momjian.us
  EnterpriseDB                             https://enterprisedb.com

+ As you are, so once was I.  As I am, so you will be. +
+                      Ancient Roman grave inscription +