Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions

jian he <jian.universality@gmail.com>

From: jian he <jian.universality@gmail.com>
To: Kirill Reshke <reshkekirill@gmail.com>
Cc: Corey Huinker <corey.huinker@gmail.com>, Vik Fearing <vik@postgresfriends.org>, Isaac Morland <isaac.morland@gmail.com>, pgsql-hackers@lists.postgresql.org
Date: 2025-12-15T04:37:43Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Make cast functions to type money error safe

  2. Make cast function from circle to polygon error safe

  3. Make geometry cast functions error safe

  4. Make cast functions from jsonb error safe

  5. Make many cast functions error safe

  6. Add SQL/JSON query functions

  7. Add soft error handling to some expression nodes

Attachments

hi.

On Wed, Dec 10, 2025 at 9:32 PM Kirill Reshke <reshkekirill@gmail.com> wrote:
>
> Hi!
>
> Overall, I think this patch is doing a good thing. Also, are we
> holding it until the next SQL standard release, because sql/23 leaks
> this feature?
>
> Below are my 2c.
>
> 1)
> First of all, I would prefer the `Bumps catversion` comment in the
> commit msg of v15-0022.
>
ok.

> 2)
> In v15-0006, if dont understand when memory allocated by
> `result = (macaddr *) palloc0(sizeof(macaddr));` will be freed. Does
> it persist until the query ends? I tried to get OOM with a query that
> errors out macaddr8 casts repeatedly, but failed.
>

  if ((addr->d != 0xFF) || (addr->e != 0xFE))
- ereport(ERROR,
+ ereturn(fcinfo->context, (Datum) 0,
  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
  errmsg("macaddr8 data out of range to convert to macaddr"),
  errhint("Only addresses that have FF and FE as values in the "

the change is minor, changing ereport to ereturn.
The whole refactoring does not related to OOM errror,
OOM errors will behave exactly as they did previously.


> 3)
>  > * When error_safe set to true, we will evaluate the constant expression in a
>  > * error safe way. If the evaluation fails, return NULL instead of throwing
>  > * error.
>
> Somebody has to say it - s/error_safe set/error_safe is set/, also
> s/throwing error/throwing an error/
>
sure.

mainly rebase due to recent palloc_object, palloc_array conflict.


--
jian
https://www.enterprisedb.com/