Re: Reject unsupported COPY FROM targets before analyzing WHERE clause

From: ZizhuanLiu X-MAN <44973863(at)qq(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, tgl <tgl(at)sss(dot)pgh(dot)pa(dot)us>, 我自己的邮箱 <44973863(at)qq(dot)com>
Subject: Re: Reject unsupported COPY FROM targets before analyzing WHERE clause
Date: 2026-07-14 15:49:34
Message-ID: tencent_CAB31AA7E0B9DA50689927AABED52CA3A909@qq.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>Hi Kyotaro-san,
>
>Thank you very much for the comments.
>
>I still think the unsupported-target check should happen first, because that is the main problem. If a user spends time fixing a WHERE clause error, then the command to fails again with “cannot copy to xxx”, the user may feel frustrated.
>
>But I am convinced by your point about making this consistent with COPY TO. So let’s use this patch to fix the “not waiting for input” problem first. I will try to work on the unsupported-target-check ordering for v20, considering COPY TO and COPY FROM together.
>
>PFA v2. The patch is much simpler now. It only moves the unsupported-target check to BeginCopyFrom(), so the check happens before waiting for input.
>
>Best regards,
>--
>Chao Li (Evan)
>HighGo Software Co., Ltd.
>https://www.highgo.com/

Hi, everyone

Thanks a lot for the patch and detailed comments.

In most scenarios, after constructing the `CopyFromState` within `BeginCopyFrom()`,
we immediately pass it into `CopyFrom()` and invoke the function. By moving the relevant
validation checks from `CopyFrom()` into `BeginCopyFrom()`, we can deliver error feedback much earlier.

This way, validation will be performed in advance before waiting for input sources
({ 'filename' | PROGRAM 'command' | STDIN }) to be ready, so that errors can be
reported to the client side in a timelier manner.

Besides, `file_fdw.c` also stores the return value of `BeginCopyFrom()` inside its callback parameters,
so it will equally benefit from this earlier validation.

This patch looks good to me.

regards,
--
ZizhuanLiu (X-MAN) 
44973863(at)qq(dot)com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-07-14 15:54:07 Re: document the dangers of granting TRIGGER or REFERENCES
Previous Message Thom Brown 2026-07-14 15:44:27 Re: SQL/JSON json_table plan clause