Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions
От | jian he |
---|---|
Тема | Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions |
Дата | |
Msg-id | CACJufxE_aO5FtBGwhDym-Fwe7k8oJY7a8jcYDx77=t3maPvG0g@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions (Corey Huinker <corey.huinker@gmail.com>) |
Ответы |
Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions
|
Список | pgsql-hackers |
On Mon, Aug 4, 2025 at 1:09 PM Corey Huinker <corey.huinker@gmail.com> wrote: >> >> 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...) > > > I'm fairly certain that the committers won't like us special-casing the internal cast functions, as we would have to maintainthese special cases as new core types are added, and it still bypasses the defined cast function for user-definedtypes, which could have similar issues similar to the rounding issue. > It's not special-casing the internal cast functions. It's how the cast being evaluated. There are two ways: CoerceViaIO, FuncExpr. generally if there is a pg_cast entry, postgres will use FuncExpr. but to safely cast evaluation (DEFAULT ON CONVERSION ERROR) we can not use FuncExpr in some cases. Because the FuncExpr associate function is not error safe. So in v4, we try to use CoerceViaIO to evaluate the case, but it turns out CoerceViaIO results are not the same as FuncExpr. one of the example is: select ('11.1'::numeric::int); In the end, it seems we need to make all these functions in the below query error safe. select castsource::regtype, casttarget::regtype, castfunc, castcontext,castmethod, pp.prosrc, pp.proname from pg_cast pc join pg_proc pp on pp.oid = pc.castfunc and pc.castfunc > 0 order by castsource::regtype; It's a lot of work, but seems doable, after playing around with it. I don't think we need to change the pg_cast catalog entry, we just need to make these function (pg_cast.castmethod) errors safe.
В списке pgsql-hackers по дате отправления: