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.94.2) (envelope-from ) id 1uiwCT-000Q1i-Jw for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Aug 2025 14:30:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uiwCS-001ikZ-8d for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Aug 2025 14:30:04 +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.94.2) (envelope-from ) id 1uiwCR-001ikQ-VP for pgsql-hackers@lists.postgresql.org; Mon, 04 Aug 2025 14:30:03 +0000 Received: from mail-vs1-xe2f.google.com ([2607:f8b0:4864:20::e2f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uiwCP-000iLC-13 for pgsql-hackers@lists.postgresql.org; Mon, 04 Aug 2025 14:30:03 +0000 Received: by mail-vs1-xe2f.google.com with SMTP id ada2fe7eead31-4fec0d6fe30so329026137.0 for ; Mon, 04 Aug 2025 07:30:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1754317799; x=1754922599; 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=Pon2mwmMxIdSFM1DMDD7HE3EzcclV4vhP/bIrOIHHqE=; b=Rj9eDIfPhAiyZh90SV8nBCZL8IDlA5KETtQUe0BfFYxB7FEccs+ctHzrAXGNCTHbBQ Q2quhQwm3P9uaDA1kOejcB83Cos9void4RTjnP6ceaQ6vvBhc34+KSk1Cp/16igMMf5m L3PcA+jAeWiPMU7L4345gDTOXVWJejEEnlv+kXou0vRuhE30dG2CNXRl8G/3QIEZDJKD FWc6xSc7WbK08uIUL8z3YtF06259i57DkRDYHYbfX7xol+jQF1s3PIKHZfc9OS682Oub evirGlMmPvJwLNuT+c9bLa+AGkelBjDClSt0V4mETR+WoPhPk+tZ473i1n+5fcLews9S jrjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754317799; x=1754922599; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Pon2mwmMxIdSFM1DMDD7HE3EzcclV4vhP/bIrOIHHqE=; b=R9mZOucj8bNLxZFBrXo/Xo61eEWBfpLDd5VV6TB/IkIkFveNoVaW6mssD8prf92uTk xauKC5cOoGlmYNx/kzzBgOsFPsri18zfIVmsVf0IOyOdqh3q/QXcr7kYhR3UQH1a0VHA ElWrBgxqN3WaGZTkUdOes3VeSDG3znHoOEB2eNFNQh3A8RJsAjigr6ifxkCGlr8oJzBa yCLb23js79aJXUBaAQgM2yjuGZQrNlXkIk19KmWfP4sFW4a4gK2gXQ3qONHQWx7KRadu CnMlPnecQmUsYDLLE44xsrEevKufQxxxDBPE96bt8Ckii+rIgZ+teKYuzBPk7tn4SJQf g4kw== X-Forwarded-Encrypted: i=1; AJvYcCV2GYR0HKZ9mbtbGu6qdgrBF0NIeRwdfWs92SmUFBxDyLMfgoq9g7+1Pw8v3Dmml1+OjW80yIzrvoc+rZpX@lists.postgresql.org X-Gm-Message-State: AOJu0Yzc6NIJI7yB335CUmn4Gmq+Odv84an1S/vMEV8tvgtJNq4WHWi1 Vvhgh7+B6bLqmdOCwqRQIWCokXCju3sMyk9OEwa6w2AAOuxNIYqCDFZy/fsxW1We8HXJi5tZpwj pn//WEHkLCk9/sjHwz82OXEwEQ81ZSf4= X-Gm-Gg: ASbGncvYhptr1sLJsuc4Jl0v3BdsR7TU8ys1YnRiodCOCiD2DabQ9rwhGGuLpwluReJ NQyBT+PZlAjSH8amv8Two3qR789YQvjmKt19O6wMCPKoZVpSGJtAYItCw2hxFoA+cFfe/qEgG8+ PCp6P+lDrVPdBR56RUS6PRLYv4+7oYxMeycJnHyQCwTUNibQOF2WBXcCdrN6uAT6LGn2QEjaph7 EQOKT+ST2X5HVtume2RCU4CcHEGqm8+71yA7Emf8V4NtNXod+ae+51Y2LiB X-Google-Smtp-Source: AGHT+IEfoqtAdGNXkd3FweiikzZ/G1+1+fPOAGPJs9NzqWlOi+B9gWjvRnLfsqrHfl6WmhRTh9B+Ux4zYVZY3U0nhoA= X-Received: by 2002:a05:6102:6895:b0:4e2:df8d:dfeb with SMTP id ada2fe7eead31-4fdc1f3889cmr3200468137.6.1754317798663; Mon, 04 Aug 2025 07:29:58 -0700 (PDT) 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: Mon, 4 Aug 2025 22:29:22 +0800 X-Gm-Features: Ac12FXwCC4ZHYrEV9EtHQgpE1Sk0hQmwE7qCuo03gXEJLIPGAr3sxP6s75VvGjU 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, Aug 4, 2025 at 1:09=E2=80=AFPM Corey Huinker 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 i= nternal cast functions, as we would have to maintain these special cases as= new core types are added, and it still bypasses the defined cast function = for user-defined types, which could have similar issues similar to the roun= ding 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 s= afely cast evaluation (DEFAULT ON CONVERSION ERROR) we can not use FuncExpr in so= me 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 =3D 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.