Re: Add LIMIT option to COPY FROM

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Shinya Kato <shinya11(dot)kato(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Add LIMIT option to COPY FROM
Date: 2026-02-03 14:12:23
Message-ID: CAKFQuwYmK0AXqW0R_tQW7vvNTkCj3TN3eZi8w1ECJEBdKuqktw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tuesday, February 3, 2026, Shinya Kato <shinya11(dot)kato(at)gmail(dot)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.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2026-02-03 14:41:51 Re: More speedups for tuple deformation
Previous Message Matheus Alcantara 2026-02-03 14:06:47 Show expression of virtual columns in error messages