From: | jian he <jian(dot)universality(at)gmail(dot)com> |
---|---|
To: | Corey Huinker <corey(dot)huinker(at)gmail(dot)com> |
Cc: | Vik Fearing <vik(at)postgresfriends(dot)org>, Isaac Morland <isaac(dot)morland(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions |
Date: | 2025-08-01 05:55:44 |
Message-ID: | CACJufxGw_OY7K3rfG4kDb902O2guhT-wgTjTJQ=pWeVWRTHpHQ@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Thu, Jul 31, 2025 at 3:15 AM Corey Huinker <corey(dot)huinker(at)gmail(dot)com> wrote:
>
>
> Question about this:
>
> +/*
> + * Push steps to evaluate a SafeTypeCastExpr and its various subsidiary expressions.
> + * We already handle CoerceViaIO, CoerceToDomain, and ArrayCoerceExpr error
> + * softly. However, FuncExpr (e.g., int84) cannot be made error-safe.
> + * In such cases, we wrap the source expression and target type information into
> + * a CoerceViaIO node instead.
> + */
>
> I'm not sure we _can_ just fall back to the CoerceViaIO if there is a defined cast from TypeA -> TypeB. I seem to recall there was some reason we couldn't do that, possibly to do with how it handled rounding, but I have no clear memory of it.
>
indeed.
select ('11.1'::numeric::int);
return 11, but '11.1' string can not coerce to int 11. So in this
case, we can not use CoerceViaIO.
so we need to handle numeric source types with fractional points with
special care.
currently, this applies only to numeric, float4, and float8.
(hope this is all the corner case we need to catch...)
select castsource::regtype, casttarget::regtype, castfunc::regproc, castcontext
from pg_cast pc
where castsource::regtype = ANY('{numeric, float4, float8}'::regtype[])
and castmethod = 'f';
only return 17 rows. one row is cast numreic to money, function numeric_cash.
numeric_cash seems more trickly to be error safe, because it will call
numeric_mul.
so I made these 16 function errors safe.
see v3-0001-make-some-numeric-cast-function-error-safe.patch
Attachment | Content-Type | Size |
---|---|---|
v3-0002-make-ArrayCoerceExpr-error-safe.patch | text/x-patch | 2.2 KB |
v3-0001-make-some-numeric-cast-function-error-safe.patch | text/x-patch | 6.8 KB |
v3-0003-CAST-expr-AS-newtype-DEFAULT-ON-ERROR.patch | text/x-patch | 57.5 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Chao Li | 2025-08-01 06:16:01 | When creating index, why pointing to old version of tuple |
Previous Message | Japin Li | 2025-08-01 05:53:33 | Re: log_min_messages per backend type |