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 1vSoZt-006Boe-25 for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Dec 2025 03:39:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vSoZs-002ZI4-0T for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Dec 2025 03:39:52 +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 1vSoZr-002ZHn-2j for pgsql-hackers@lists.postgresql.org; Tue, 09 Dec 2025 03:39:52 +0000 Received: from mail-ua1-x929.google.com ([2607:f8b0:4864:20::929]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vSoZp-003y04-35 for pgsql-hackers@lists.postgresql.org; Tue, 09 Dec 2025 03:39:51 +0000 Received: by mail-ua1-x929.google.com with SMTP id a1e0cc1a2514c-9372634aca2so1534979241.2 for ; Mon, 08 Dec 2025 19:39:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765251588; x=1765856388; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=NM6gqaEhjkfY5awbAzvpNM4iMPMRgTvLix/f4SlD15U=; b=H7BASsUXbQ7NQiNgjx3V/kLeHLq09EjPz/9TxUCzqnogIhqh/wIEE/F37ISJvOVno4 7UL5l8Kwh2qJrwLWhfB7MraNVbKsXZXyKi5FHFq8ibE9OEcZJ4JkHxsfU7QNLYFDPS6k RMcIzC42CKlW8NhTyuQfdUSDRQ0m/govxJ/YmRACjQIkeFaX+Jth1PIuz8o0yXpzRAfD GfVXhNcNebl1o3IJcyirXHx+jeGkv1t0Okq8prieP61QWbJnG2an9s6AbaOITJGfkQW7 FDRFcxqPCi6MRJyBks5trSOS3UVq2AZMC6w6cszziWcTVPCDhSVNj8GffubFEdv3CmG8 OokQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765251588; x=1765856388; h=content-transfer-encoding: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=NM6gqaEhjkfY5awbAzvpNM4iMPMRgTvLix/f4SlD15U=; b=UmorRtaOV9V9m4M60Gb9I062Pw0ODEtT/hEFXQMvHJbB1+YT+a1BKe/Q0N5trnBWfB MyE8BLZ+lnCU6UmVz5MfBKi6VjnirBJ+qK36tOav8PUhdyTEKYujhLZeLVCTNIYM+21M XGc4wm4rKVwXtoXSc3oaFA2p89H7qiR6vOPwA9HVzAP42I5nhPwtRC023kpzC3nF7vBN CC1vlbRh3W+xXMCBp5XcrlgOS1bAj9x9fGLeZFHBfd8TH6tIC/paVkQp02jEG0v+71mY RRIJ9J0Y7uLVEh6jCSnNfyiA6UCBBAs5Tg3qHPWbwq7G0Y7RX6km3oGZ4HkQRoCXY4tz qrnQ== X-Forwarded-Encrypted: i=1; AJvYcCXCDQPyy6N/42wZH4XNUZDv8+JTyE50B9cxN+qAMvt5h2cBHwkkmBxAT6YI1admJEjt6PK2QFO89ZR4rO9q@lists.postgresql.org X-Gm-Message-State: AOJu0Ywt/jPQQv9OohdydDJRMlG81mFP8HmtT+Q76CeJ57ocsKf08l5A jimRCrmFEMzyODnh0YFIyaw2piAWUzcWNPZB5Zv7Qfvq+5L710YK7ow4fXhfDounL1tYhqZR5FL ct66DIXikOoZZ55dpgTDCCFy3fLDvC4Y= X-Gm-Gg: ASbGnct8X8VONY1UgRAJrfUQ39UIrFb9P3yVNH627xRYDu+RFMAXv06wUluQiIOgvgg JuRCIHslz/1tmkYo/J3dYlwT+Jhd1qCRKViav8woTo+zTpgZFlVoGDGNwHRc8+8PKGVqH2A62j6 phzVqqZfys2YoiAYHJYHhEk6Oh2eYML/1UMeTwhIn+4qHepf7DiQ28tbPt5+bs6G4F/J9nfISs6 MJv/lF/+UDwJvokhJr6iPNVQhn8m9bWZ/22b/5pUOaKo020rX6wkPm3VcnSzaEPfdhGFX8MkTHO 0fC3A/UzLa9DgmyQ7g/oZdvEVtyPpmFjAWMASiwvjg7dmLYwuhmBiwIqztN3ZBBeKTgmYZB/VgQ +DqwB4khQbZrXQKDXyNf+PzWOE8ArnpGFwmMGQyl+u6bK17XhL1hSOwNn7u39H8pSdBaYdiCF/B n7eqOFmUw= X-Google-Smtp-Source: AGHT+IHHM2Lz2WJP6xe6IvZx8RBo+vtLyw2+zygEIf7e/2wskGzC7klxJMyWpsxZiXzJ7kJ3giSCpw5FlNb60S2GF0Q= X-Received: by 2002:a05:6102:4bc7:b0:5db:d60a:6b24 with SMTP id ada2fe7eead31-5e52cbdc3a4mr2584009137.22.1765251588088; Mon, 08 Dec 2025 19:39:48 -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: jian he Date: Tue, 9 Dec 2025 11:39:11 +0800 X-Gm-Features: AQt7F2o5y06TsNqsJR3-Lit3CrntGwUkNm2u--nYJHFV00COeXjl-W8A9ATdNrE Message-ID: Subject: Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions To: Corey Huinker Cc: Vik Fearing , Isaac Morland , pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Dec 1, 2025 at 1:41=E2=80=AFPM Corey Huinker wrote: >> >> >> I'm fine with it. I can see having 'f' and 's' both mean cast functio= ns, but 's' means safe, but the extra boolean works too and we'll be fine w= ith 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 CA= ST 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. In v14, I have removed pg_cast.casterrorsafe, but for user-defined CREATE C= AST, castfunc can be built-in function or user-defined function, we do need a wa= y to distinguish if the cast function is error safe or not. I=E2=80=99ll incorporate pg_cast.casterrorsafe along with the implementatio= n of the user-defined CREATE CAST syntax into one patch. > 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 t= he DEFAULT clause altogether and fall back to being an ordinary CAST(). > >> integer and oid are binary coercible, but the following should fail. SELECT CAST(11 as oid DEFAULT 'a' ON CONVERSION ERROR); if you mean that skip + ExecInitExprRec((Expr *) stcstate->stcexpr->default_expr, + state, resv, resnull); For binary-coercible types, this approach seems fine. We=E2=80=99ve done so= mething similar in ExecInitExprRec for T_ArrayCoerceExpr. ``` if (elemstate->steps_len =3D=3D 1 && elemstate->steps[0].opcode =3D=3D EEOP_CASE_TESTVAL) { /* Trivial, so we need no per-element work at runtime *= / elemstate =3D NULL; } ``` in V14, I didn't do this part, I'll keep this in mind. -- jian https://www.enterprisedb.com/