| From: | Sugamoto Shinya <shinya34892(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers(at)postgresql(dot)org |
| Subject: | [PATCH] Add hints for invalid binary encoding names in encode/decode functions |
| Date: | 2025-11-08 06:25:42 |
| Message-ID: | CAAe3y+99sfPv8UDF1VM-rC1i5HBdqxUh=2HrbJJFm2+i=1OwOw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
When users pass an invalid encoding name to the built-in functions
`encode()` or `decode()`, PostgreSQL currently reports only:
ERROR: unrecognized encoding: "xxx"
This patch adds an error hint listing the valid encoding names,
so users can immediately see the supported options.
Example:
SELECT encode('\x01'::bytea, 'invalid');
ERROR: unrecognized encoding: "invalid"
HINT: Valid binary encodings are: "hex", "base64", "base64url",
"escape".
This change applies to both `binary_encode()` and `binary_decode()` in
`encode.c`,
and adds regression tests under `src/test/regress/sql/strings.sql`.
Although this is a small change, let me share a few considerations behind
it:
- I extracted the valid encodings from the hint messages and used a format
specifier like
`Valid binary encodings are: %s`, so that we avoid scattering those fixed
strings
across translation files.
- I briefly considered adding a small helper function to build the hint
string,
but decided against it since keeping the codebase simple felt preferable,
and
new binary encodings are not added very often.
I’d be happy to hear any opinions or suggestions.
Patch attached.
Best regards,
Shinya Sugamoto
| Attachment | Content-Type | Size |
|---|---|---|
| 0001-Added-error-hints-for-invalid-binary-encoding-names-.patch | application/octet-stream | 2.9 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | cca5507 | 2025-11-08 07:59:02 | Use bsearch() instead of a manual binary search in syscache.c |
| Previous Message | 河田達也 | 2025-11-08 05:12:35 | [PATCH] Fix text in comment of copyto.c |