Re: Add LIMIT option to COPY FROM - Mailing list pgsql-hackers

From David G. Johnston
Subject Re: Add LIMIT option to COPY FROM
Date
Msg-id CAKFQuwYmK0AXqW0R_tQW7vvNTkCj3TN3eZi8w1ECJEBdKuqktw@mail.gmail.com
Whole thread Raw
In response to Add LIMIT option to COPY FROM  (Shinya Kato <shinya11.kato@gmail.com>)
List pgsql-hackers
On Tuesday, February 3, 2026, Shinya Kato <shinya11.kato@gmail.com> wrote:
Hi hackers,

I'd like to propose adding a LIMIT option to COPY FROM, which limits
the number of rows to load.

With COPY TO, we can use the LIMIT clause in the query to restrict
output rows, but COPY FROM has no equivalent way to limit the number
of rows to load (except using the PROGRAM option with external tools
like head). This patch resolves that asymmetry.

Syntax example:
- COPY t FROM STDIN (LIMIT 100);

This feature is useful for:
- Loading only the first N rows from a huge CSV file to verify data or
table definitions before a full import

Would want it paired with offset for this use case.

Design:
- The LIMIT count applies after WHERE filtering and ON_ERROR skipping,
so it represents the actual number of rows inserted.

Not sure about that choice.  I’d go with pre-eval or implement both and default to pre-eval.

David J.

pgsql-hackers by date:

Previous
From: "Matheus Alcantara"
Date:
Subject: Show expression of virtual columns in error messages
Next
From: Andres Freund
Date:
Subject: Re: More speedups for tuple deformation