On Sun, Oct 11, 2026 at 12:37 AM Fujii Masao <[email protected]> wrote:
> Codex reported that commit d8ce0050a6c causes the following INSERT to fail,
> and I confirmed it. Is this a bug?

Thanks for the report.  Yes, it is a bug.

A COALESCE's typmod is derived from its arguments, so dropping the
NULL constant changes it from -1 to that of varchar(20).  The index
expression is simplified twice (in the relcache, then in
infer_arbiter_indexes), while the ON CONFLICT expression is simplified
once, so only the latter gets the RelabelType added by d8ce0050a, and
the two no longer match.

The attached patch preserves the typmod for a partially reduced
COALESCE or CASE as well.

While at it, I noticed that an all-null COALESCE is reduced to a null
constant with typmod -1, which can cause the same failure.  That code
dates back to 2005, but before v19 it only affects the typmod the
expression exposes.  The patch fixes it too.

I plan to back-patch this to v19 only, after rc1.

- Richard

Attachment: v1-0001-Preserve-typmod-when-partially-reducing-CASE-and-.patch
Description: Binary data

Reply via email to