Обсуждение: [PATCH] Add error hints for invalid COPY options
Hi,
This patch improves the user experience when working with COPY commands by
adding helpful error hints for invalid options.
Currently, when users make typos in COPY option names or values, they receive
a generic error message without guidance on what went wrong. This patch adds
two types of hints:
1. For invalid option names: suggests the closest matching valid option using
the ClosestMatch algorithm (e.g., "foramt" → "Perhaps you meant 'format'")
2. For invalid option values: lists all valid values when the set is small
(e.g., for format, on_error, log_verbosity options)
This follows the pattern already used elsewhere in PostgreSQL for providing
helpful error hints to users.
Additionally, this patch corrects a misleading comment for the
convert_selectively option. The comment stated it was "not-accessible-from-SQL",
but actualy it has been accessible from SQL due to PostgreSQL's generic option parser.
This patch improves the user experience when working with COPY commands by
adding helpful error hints for invalid options.
Currently, when users make typos in COPY option names or values, they receive
a generic error message without guidance on what went wrong. This patch adds
two types of hints:
1. For invalid option names: suggests the closest matching valid option using
the ClosestMatch algorithm (e.g., "foramt" → "Perhaps you meant 'format'")
2. For invalid option values: lists all valid values when the set is small
(e.g., for format, on_error, log_verbosity options)
This follows the pattern already used elsewhere in PostgreSQL for providing
helpful error hints to users.
Additionally, this patch corrects a misleading comment for the
convert_selectively option. The comment stated it was "not-accessible-from-SQL",
but actualy it has been accessible from SQL due to PostgreSQL's generic option parser.
The updated comment clarifies that while technically accessible, it's intended for
internal use and not recommended for end-user use due to potential data loss.
Best regards,
Best regards,
Вложения
Hi, On Sat, Nov 22, 2025 at 8:33 PM Sugamoto Shinya <shinya34892@gmail.com> wrote: > > Hi, > > This patch improves the user experience when working with COPY commands by > adding helpful error hints for invalid options. > > Currently, when users make typos in COPY option names or values, they receive > a generic error message without guidance on what went wrong. This patch adds > two types of hints: > > 1. For invalid option names: suggests the closest matching valid option using > the ClosestMatch algorithm (e.g., "foramt" → "Perhaps you meant 'format'") > > 2. For invalid option values: lists all valid values when the set is small > (e.g., for format, on_error, log_verbosity options) > > This follows the pattern already used elsewhere in PostgreSQL for providing > helpful error hints to users. Given we have 15 COPY options now, it sounds like a reasonable idea. One concern about the patch is that when adding a new COPY option, we could miss updating valid_copy_options list, resulting in providing a wrong suggestion. I think we can consider refactoring the COPY option handling so that we check the given option is a valid name or not by checking valid_copy_options array and then process the option value. > Additionally, this patch corrects a misleading comment for the > convert_selectively option. The comment stated it was "not-accessible-from-SQL", > but actualy it has been accessible from SQL due to PostgreSQL's generic option parser. > The updated comment clarifies that while technically accessible, it's intended for > internal use and not recommended for end-user use due to potential data loss. Hmm, I'm not sure the proposed comment improves the clarification. It's essentially non-accessible from SQL since we cannot provide a valid value for convert_selectively from SQL commands. Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com
On Mon, Nov 24, 2025 at 11:56:34AM -0800, Masahiko Sawada wrote: > On Sat, Nov 22, 2025 at 8:33 PM Sugamoto Shinya <shinya34892@gmail.com> wrote: >> This follows the pattern already used elsewhere in PostgreSQL for providing >> helpful error hints to users. > > Given we have 15 COPY options now, it sounds like a reasonable idea. > > One concern about the patch is that when adding a new COPY option, we > could miss updating valid_copy_options list, resulting in providing a > wrong suggestion. I think we can consider refactoring the COPY option > handling so that we check the given option is a valid name or not by > checking valid_copy_options array and then process the option value. +1. Ideally, folks wouldn't need to update a separate list when adding new options. >> Additionally, this patch corrects a misleading comment for the >> convert_selectively option. The comment stated it was "not-accessible-from-SQL", >> but actualy it has been accessible from SQL due to PostgreSQL's generic option parser. >> The updated comment clarifies that while technically accessible, it's intended for >> internal use and not recommended for end-user use due to potential data loss. > > Hmm, I'm not sure the proposed comment improves the clarification. > It's essentially non-accessible from SQL since we cannot provide a > valid value for convert_selectively from SQL commands. Yeah, I'd leave it alone, at least for this patch. -- nathan