public inbox for [email protected]
help / color / mirror / Atom feedFrom: Kirill Reshke <[email protected]>
To: jian he <[email protected]>
Cc: Corey Huinker <[email protected]>
Cc: Vik Fearing <[email protected]>
Cc: Isaac Morland <[email protected]>
Cc: [email protected]
Subject: Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions
Date: Wed, 10 Dec 2025 18:32:06 +0500
Message-ID: <CALdSSPjd2fJHw8TrugumZSQwJ8VmSVn55OfQ+Wuogaq0ss=HGQ@mail.gmail.com> (raw)
In-Reply-To: <CACJufxFEzD3mqc+MDpgzvdt+4Azbn2pF6TWW=dSCqSK7OHoL6A@mail.gmail.com>
References: <CADkLM=fv1JfY4Ufa-jcwwNbjQixNViskQ8jZu3Tz_p656i_4hQ@mail.gmail.com>
<CAMsGm5dpfm2PHL8XZvC-JSd+UPkgx3rpReUA=G=4+rUCH+Ntcw@mail.gmail.com>
<CADkLM=eD_S8mGhPfu5+hXXvXgR0-cxGpGd9dgPzD+nCuO7HFaQ@mail.gmail.com>
<CACJufxHCMzrHOW=wRe8L30rMhB3sjwAv1LE928Fa7sxMu1Tx-g@mail.gmail.com>
<[email protected]>
<CACJufxGRAnwJzu7nMq4ZP=yqa1Sz=qR+mR1TmY0aCDjJoJRRtg@mail.gmail.com>
<[email protected]>
<CACJufxFy+DFpJ2e-czyCTAgSJXNFaQGWFKA4mjbW-LAMGc1YBA@mail.gmail.com>
<CADkLM=f1Jv81=s5Ckazx3zZq=M5KoBJMJkOZux_-L+gezODCEQ@mail.gmail.com>
<CACJufxGw_OY7K3rfG4kDb902O2guhT-wgTjTJQ=pWeVWRTHpHQ@mail.gmail.com>
<CADkLM=cFSg3+6Sk00dLAF7Q7jnrKBk6+N5gRxT5BCxRvaGtR-g@mail.gmail.com>
<CACJufxE_aO5FtBGwhDym-Fwe7k8oJY7a8jcYDx77=t3maPvG0g@mail.gmail.com>
<CADkLM=chahh6ddZFjLL6AUdqzL_Px0raTu-5Jzn2WN8yELtmJw@mail.gmail.com>
<CACJufxE053=bO3pDUpGba6Yz3VGpU_XCbg4HO6Rew5EJ7k7VnQ@mail.gmail.com>
<CACJufxF--5d=fmoRBHfqJE9Vy38dCURNKYOKKpujRCnoTEQ7nQ@mail.gmail.com>
<CACJufxHpMJn22Nu_wmG6eV_S8SAM6KM+GhMO7GuzVb=d9q5C4A@mail.gmail.com>
<CACJufxHM2e3DQmbRdDZvWyG3ZCLyOg6XFifvOz_TGy1tGw7NHw@mail.gmail.com>
<CADkLM=daTLuRcwzc6Egtwvh4XYgtABWuMBVnEznd-dXqmXfzUw@mail.gmail.com>
<CACJufxEcrrcaeFW+zYsjgb6r+ijzwszyxeHk3wxGY+3idiA2ZA@mail.gmail.com>
<CADkLM=ehavqENDBCcYQufPFKboV90+o_uFdhcrh=Ymq_TNqo=A@mail.gmail.com>
<CADkLM=ecTybe9Z9TSRD-NKZ=-V4DuGVRtXZGO6+F7=m3Gg9GGQ@mail.gmail.com>
<CACJufxH5OSeY0-qirksn8S2FUycxON-O=iwc0-Nne1MTAguGhQ@mail.gmail.com>
<CADkLM=eFasBpS1cqf67TpKGbKoUSy00FuT05Yz4RpXQBpqktuw@mail.gmail.com>
<CACJufxHrE0s7G0xg1frWo2+tFLTLaikKCObixH-4p9zMYKtHFw@mail.gmail.com>
<CACJufxFEzD3mqc+MDpgzvdt+4Azbn2pF6TWW=dSCqSK7OHoL6A@mail.gmail.com>
On Wed, 10 Dec 2025 at 13:58, jian he <[email protected]> wrote:
>
> On Tue, Dec 9, 2025 at 11:39 AM jian he <[email protected]> wrote:
> >
> > On Mon, Dec 1, 2025 at 1:41 PM Corey Huinker <[email protected]> wrote:
> > >>
> > > No, I meant implementing the syntax for being able to declare a custom CAST function as safe (or not). Basically adding the [SAFE] to
> > >
> > > CREATE CAST (source_type AS target_type)
> > > WITH [SAFE] FUNCTION function_name [ (argument_type [, ...]) ]
> > >
> > > I'm not tied to this syntax choice, but this one seemed the most obvious and least invasive.
> > >
>
> hi.
> please see the attached v15.
> the primary implementation of CAST DEFAULT is contained in V15-0021.
>
> changes compared to v14.
> 1. separate patch (v15-0017) for float error.
> -pg_noreturn extern void float_overflow_error(void);
> -pg_noreturn extern void float_underflow_error(void);
> -pg_noreturn extern void float_zero_divide_error(void);
> +extern void float_overflow_error(struct Node *escontext);
> +extern void float_underflow_error(struct Node *escontext);
> +extern void float_zero_divide_error(struct Node *escontext);
>
> 2. separate patch (v15-0018) for newly added float8 functions:
> float8_pl_safe
> float8_mi_safe
> float8_mul_safe
> float8_div_safe
> refactoring existing functions is too invasive, I choose not to.
>
> 3. refactor point_dt (v15-0019). This is necessary for making geometry data type
> error-safe, separate from the main patch (v15-0020). I hope to make it easier to
> review.
> -static inline float8 point_dt(Point *pt1, Point *pt2);
> +static inline float8 point_dt(Point *pt1, Point *pt2, Node *escontext);
>
> 4. skip compile DEFAULT expression (ExecInitExprRec) for binary coercion cast,
> as mentioned before. See ExecInitSafeTypeCastExpr.
>
> 5. Support user-defined type cast error-safe, see v15-0022.
> user-defined error-safe cast syntax:
> CREATE CAST (source_type AS target_type)
> WITH [SAFE] FUNCTION function_name [ (argument_type [, ...]) ]
> [ AS ASSIGNMENT | AS IMPLICIT ]
>
> this only adds a new keyword SAFE.
> This works for C and internal language functions only now.
> To make it really usable, I have made citext, hstore module castfunc error safe.
> A new column: pg_cast.casterrorsafe was added, this is needed for
> CREATE CAST WITH SAFE FUNCTION.
>
> +select CAST(ARRAY['a','g','b','h',null,'i'] AS hstore
> + DEFAULT NULL ON CONVERSION ERROR);
> + array
> +-------
> +
> +(1 row)
> +
>
> 6. slightly polished the doc.
>
>
> --
> jian
> https://www.enterprisedb.com/
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.
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.
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/
--
Best regards,
Kirill Reshke
view thread (75+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions
In-Reply-To: <CALdSSPjd2fJHw8TrugumZSQwJ8VmSVn55OfQ+Wuogaq0ss=HGQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox