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

From Florents Tselai
Subject Re: Add LIMIT option to COPY FROM
Date
Msg-id CA+v5N41wVFz4akXPxknCX6utxUwx35EJMu2WCYbaX5yF240LZQ@mail.gmail.com
Whole thread Raw
In response to Add LIMIT option to COPY FROM  (Shinya Kato <shinya11.kato@gmail.com>)
Responses Re: Add LIMIT option to COPY FROM
List pgsql-hackers


On Tue, Feb 3, 2026 at 3:49 PM 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);

I work with such scenarios a lot and I can't see why COPY should worry itself about such filtering.
IRL most of what goes into COPY'S STDIN  has already been filtered extensively,
like ... | head -n 100 | COPY t FROM STDIN

pgsql-hackers by date:

Previous
From: Aleksander Alekseev
Date:
Subject: Re: [PATCH] Refactor *_abbrev_convert() functions
Next
From: Andres Freund
Date:
Subject: Re: Remove freelist reference in buf_init.c