Re: preptlist.c can insert unprocessed expression trees

Sami Imseih <samimseih@gmail.com>

From: Sami Imseih <samimseih@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@lists.postgresql.org
Date: 2025-01-29T21:14:01Z
Lists: pgsql-hackers
> to a varchar length-checking function and then to CoerceToDomain.
> Of course they really ought to look the same.

+1. I confirmed this as well with the supplied test case.

> In the attached 0001 patch I called it
> coerce_null_to_domain and put it in parse_coerce.c.

I do think the name of the function is a bit misleading.
coerce_null_to_domain could optionally coerce to a domain if
typid != baseTypeId, but not necessarily.

From what I can tell, the coerce_null_to_domain function will be
called anytime an implicit NULL is supplied to an INSERT or
UPDATE and the target column does not have a default;
so maybe it should be called coerce_implicit_null ?

> (The caller has
> to produce an input that's of the base type, after all.)  So it seems
> like that's not a convenience so much as an encouragement to incorrect
> coding.  I propose, for HEAD only, 0002 which removes that misfeature
> and requires callers to supply the info.

This makes sense.

check-world passed with both patches applied.

Regards,

Sami



Commits

  1. Require callers of coerce_to_domain() to supply base type/typmod.

  2. Handle default NULL insertion a little better.