Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vPwfc-002amz-31 for pgsql-hackers@arkaria.postgresql.org; Mon, 01 Dec 2025 05:41:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vPwfa-000Kcc-1P for pgsql-hackers@arkaria.postgresql.org; Mon, 01 Dec 2025 05:41:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vPwfa-000Kc6-0K for pgsql-hackers@lists.postgresql.org; Mon, 01 Dec 2025 05:41:54 +0000 Received: from mail-il1-x12a.google.com ([2607:f8b0:4864:20::12a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vPwfY-002S4z-1P for pgsql-hackers@lists.postgresql.org; Mon, 01 Dec 2025 05:41:54 +0000 Received: by mail-il1-x12a.google.com with SMTP id e9e14a558f8ab-43323851d03so15197785ab.0 for ; Sun, 30 Nov 2025 21:41:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764567710; x=1765172510; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=nD0RANgCNqLoFlIUaDU+ef9I+CyZOCr0bNZ1WpKh0t0=; b=Hw0YO8UjEswpVR41+ttsfQ6wv3ZvbovPzbULUt0lbxg1zCb2YKkxaQmL9mGsIGakV7 2mo+W9wBFh/xMm3FY1Aoby7FWrdEDKLhbbrj//QAQRfmaYALrwTzkdAGALHDp4VxbYZJ MANCNnXfPcF1FGyDRJQruaMkLEUo1Yt+FSo1CYAwBzf501rCq6TZk6kn4yAoie/I46Qt Y30CW8iKiekvujeg4v/CIm5w8MGeyMGrKOFoeqlcJ2HRFJCOCQ3Aa02Mkx9Gp95S/p+5 yRGdjFdy6k1awoKpMoj8e4gAph4s0vzbcUjOUj/0Axow45Kewqw59VCl1BCIZqiaCHL2 5jVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764567710; x=1765172510; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=nD0RANgCNqLoFlIUaDU+ef9I+CyZOCr0bNZ1WpKh0t0=; b=FbMEnrkdGsQ1grQxm+wfRKeoclkDmwpcLkk6FfpvgcvO5xw9eCLQk3/7qa91hUwKf2 HJdETKpgq4SqxcaaIJ9pXyhOVYCkcQaUpIBmtQJjduWEhGGfqqgjWHC8y79xb/C1vsvl bjHloEvG2PM+SmCQHxNQQuf7tntcCz2+LXBZPHRe3cacEF6+4ZSqvFng9ZKgI5dQo1Gg zA2OzcPAuMXu0YZktVUzlvPLJjYmVOwHYisgJHB2xcd7ORgQJttJYxq1IX/UpUeFdSd1 ejl3n91HMy3E6y/cntOaFnMtsn6qxy55Bt7QLnJVeoNRg6wHstbelzAl16RnJ5QLU9mg kpsg== X-Forwarded-Encrypted: i=1; AJvYcCUl9jfQtqaiuVRG6EPqGnnBGvlPezTav2huL+Yeh5H5iVr74ezpT6nBLtROeXMLxxxpbg0SQ+Hkge1C6X7K@lists.postgresql.org X-Gm-Message-State: AOJu0YybvfmaZbO337OnauSsuvsjm495tmno6SJW/XP1uYqv51AD0/30 0n2HVMkwKBbj2aZKzJsrLzodhhu+IHWg5iMYQ04mE1PINTvrAEfzJvGyOU568QNOVDrjBd2h+qJ IZrujcX5qR5WdFE7tXDFftz5/sKsjPEY= X-Gm-Gg: ASbGncvnXHEPlJloPF2BkIDR5hf0rLY1iKFzjh3OK7rnm6qKKOWKkafw5xj4DKYGR5B fQzrQxd1pb3DrVkTkoPrxzvrvH3dfliTKvuAZoyP3zA2wiJFNJ67hB4yxHp7N5Smc6KzXf+1MJS kg1Io1g37NoeVmHXqe+/euLCjaonLY/QIpLO7hP+uA4Jd4NvChBHOyZnKCcs1DPm3/iPpjNlxIk SUujXfzouSyMZTf3qhPTFK92d6Lg7Ue4NqFFH9IV2rb9okylixlWyVaUciXL4g842XmASmh7P6e QZ6p4JFO8G3QCUwLRSLvCbtlBl2pzwqT5cp104XwS4WMvqkowTwTg1eF+pTd X-Google-Smtp-Source: AGHT+IFdd37OgzQNxjvm1sD0uLORgbxul06/SZUN5rLjX0Orl4Rn3PVINKy59nKIg1cJBt9tKf1YWHQamFhcb/AaJEU= X-Received: by 2002:a92:c248:0:b0:434:96ea:ff55 with SMTP id e9e14a558f8ab-435b98ee9d9mr320097235ab.38.1764567710165; Sun, 30 Nov 2025 21:41:50 -0800 (PST) MIME-Version: 1.0 References: <04afcd1f-ed7d-4c0a-add1-50e3719ccbf9@postgresfriends.org> <762ae707-7fdc-43d8-a77a-3a10d12ce21d@postgresfriends.org> In-Reply-To: From: Corey Huinker Date: Sun, 30 Nov 2025 23:41:37 -0600 X-Gm-Features: AWmQ_bnn_Bz-hvl-LyRkj08uGEcFwodARPwW-8idNZVwvKAa90Jelse2Bcberrk Message-ID: Subject: Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions To: jian he Cc: Vik Fearing , Isaac Morland , pgsql-hackers@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000008bedfe0644dd6fec" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000008bedfe0644dd6fec Content-Type: text/plain; charset="UTF-8" > > >> I'm fine with it. I can see having 'f' and 's' both mean cast > functions, but 's' means safe, but the extra boolean works too and we'll be > fine with either method. > > > > > > I can work on this part if you don't have time. > > Do you mean change pg_cast.casterrorsafe from boolean to char? > 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. But this brings up an interesting point: if a cast is declared as WITHOUT FUNCTION aka COERCION_METHOD_BINARY, then the cast can never fail, and we should probably check for that because a cast that cannot fail can ignore the DEFAULT clause altogether and fall back to being an ordinary CAST(). > Currently pg_cast.casterrorsafe works just fine. > if the cast function is not applicable, the castfunc would be InvalidOid. > also the cast function is either error safe or not, I don't see a > usage case for the third value. > Agreed, it's fine. A committer may want a char with 's'/'u' values to keep all the options char types, but even if they do that's a very minor change. --0000000000008bedfe0644dd6fec Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
>> I'm fine with it. I c= an see having 'f' and 's' both mean cast functions, but = 9;s' means safe, but the extra boolean works too and we'll be fine = with either method.
>
>
> I can work on this part if you don't have time.

Do you mean change pg_cast.casterrorsafe from boolean to char?

No, I meant implementing the syntax for being = able=20 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_nam=
e [ (argument_type=
 [, ...]) ]
I'm not tied to this syntax choice, but this one = seemed the most obvious and least invasive.

But th= is brings up an interesting point: if a cast is declared as WITHOUT FUNCTIO= N aka COERCION_METHOD_BINARY, then the cast can never fail, and we should p= robably check for that because a cast that cannot fail can ignore the DEFAU= LT clause altogether and fall back to being an ordinary CAST().
=
=C2=A0
Currently pg_cast.casterrorsafe works just fine.
if the cast function is not applicable, the castfunc would be InvalidOid. also the cast function is either error safe or not, I don't see a
usage case for the third value.

Agreed, it's fine. A committer may want= a char with 's'/'u' values to keep all the options char ty= pes, but even if they do that's a very minor change.
--0000000000008bedfe0644dd6fec--