[PATCH] Add error hints for invalid COPY options

From: Sugamoto Shinya <shinya34892(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: [PATCH] Add error hints for invalid COPY options
Date: 2025-11-23 04:32:38
Message-ID: CAAe3y+816W-mRg=QH1fzdD7ouyhGv+FgREvfbhv4R8Tr1PU8kg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.
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,

Attachment Content-Type Size
0001-Add-error-hints-for-invalid-COPY-options.patch application/octet-stream 7.9 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2025-11-23 04:38:53 Re: Remove unused fields from BufferCacheNumaRec
Previous Message Chao Li 2025-11-23 04:27:08 Re: Remove unused fields from BufferCacheNumaRec