Re: [PATCH] Add error hints for invalid COPY options

From: Sugamoto Shinya <shinya34892(at)gmail(dot)com>
To: Nathan Bossart <nathandbossart(at)gmail(dot)com>
Cc: Kirill Reshke <reshkekirill(at)gmail(dot)com>, Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Add error hints for invalid COPY options
Date: 2026-02-06 12:53:31
Message-ID: CAAe3y+9VnQXv8beyhOiGxvykS0RwuH=o32+2RHHOWLFz9GvLVQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Dec 9, 2025 at 7:32 AM Nathan Bossart <nathandbossart(at)gmail(dot)com>
wrote:

> On Sun, Dec 07, 2025 at 11:32:28PM +0900, Sugamoto Shinya wrote:
> > Attached is the new patch. One possible discussion point is that I choose
> > FATAL over ERROR at src/backend/commands/copy.c#L816, since reaching that
> > point would indicate an implementation problem. Please let me know if
> > there is a better option.
>
> Since it indicates a coding error, I would probably choose something like
>
> Assert(false); /* should never happen */
>
> That seems to be a standard way to handle these situations.
>
> It's a little unfortunate that we are essentially validating the option
> twice, but the way this is structured should at least prevent folks from
> forgetting to add it in one place or another. One way to make this a
> little better could be to add an enum that validate_copy_option() returns
> (so that we don't have to repeat the strcmp()s). Or we could replace each
> strcmp() in ProcessCopyOptions()'s option extraction block with a function
> that does the strcmp() and also calls updateClosestMatch(). Then, by the
> time we reach the final "else", we've already done the work for the hint.
>
> --
> nathan
>

Hi, thank you for checking my patch.

I took Nathan's comment into consideration and made my patch much simpler by
putting the compare logic and the update of ClosestMatch into one place. It
allows
us to avoid having two separate for-loops to compare the specified options
and the list
of the available options. Also, it minimizes the necessary amount of
changes for making
error hints richer.

Here is my patch.

Regards

Attachment Content-Type Size
v5-0001-Improve-error-hints-for-invalid-COPY-options.patch application/octet-stream 14.3 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavlo Golub 2026-02-06 12:57:24 Re[2]: [PATCH] Add last_executed timestamp to pg_stat_statements
Previous Message Ashutosh Bapat 2026-02-06 12:52:00 local custom injection points do not work as expected