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 1w56wj-002u9M-2e for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Mar 2026 18:57:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w56wi-008Xkf-16 for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Mar 2026 18:57:44 +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 1w56wi-008XkX-06 for pgsql-hackers@lists.postgresql.org; Tue, 24 Mar 2026 18:57:44 +0000 Received: from mail-dl1-x1232.google.com ([2607:f8b0:4864:20::1232]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w56wf-00000000vS0-2FUW for pgsql-hackers@lists.postgresql.org; Tue, 24 Mar 2026 18:57:43 +0000 Received: by mail-dl1-x1232.google.com with SMTP id a92af1059eb24-12776bebe9fso1226106c88.1 for ; Tue, 24 Mar 2026 11:57:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774378660; cv=none; d=google.com; s=arc-20240605; b=lLBf4DcsemlQDd2c294lN86HeV1wpdozhjZgMSM7Et2K8Kbv+UzGx9rC9X8DpeZmY8 ehqaASBLMhTEeSWTClyhqqj2vCkc6giaPdKBYYNNXkxoh87caDpJvq5QZg79eUVzwXBS 7yoQP4z76aVFZFKCoVXITvE5In1lHufnTOx8wSwANVAlFl9Fi7tHF8KsyC57HMP5uRnF fIxGg6jZ2T+SyED79oM5CXJGjyXsix2Ywd1Bt0KjLvnGoCZ9+vjSVgFSzCeW1THbgbW2 waoRIrzMfkPQgFhfB0n3Rk79gI7oXTAVY6v0rkRWZ/khFf67WLq7975RsedK/Yw3BY09 lR3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=zHUJhKlkW2RKdvmGDC9XYZkHzPyewcdTYblysDBGTTg=; fh=yDHh5iUkgvWDKYlp6pzTodp63HsrW+2AHb6n00zOA5Y=; b=Ze8uY6QdvSJr8QW3c9HyMen4hXKxs9yCTe4u9+Q1h75YWJLhQtJDagTZd+ymHRK4+x w5AQsBC2JQvTDifbvhfFFmvMZlRUXOTzCC2Np4VrP0emeGAxvOzNdpXhqN+h0F0X9qdk 1SmBPnQDMzj8LEkF/S74EUMOCAzJFaHzIo0tP7HE7n2A9vcjXZRq2zLvKP0ah1B0g41N QYQL6r45ysYQckBL6lpvRDYsktk7LxN7LtBDkmMGuohrvEeJRPDx/R7B7w1/l9+R7JPs BVzqAxlrlxQjbWYBvGl8k0BSEtwkWVJlJ212baIB51T3qHlSmyElwqvZ8Hj1QXvqWy72 4Dzw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774378660; x=1774983460; 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=zHUJhKlkW2RKdvmGDC9XYZkHzPyewcdTYblysDBGTTg=; b=polWNGCzKJzQqzMgoitFpQfz6fKJZAhd/eR8sWNUhmex8ES1XATIeJbwJMc1PA1Jj+ ziQ6Pw2+uF4lTsyczD3JBnF4ZpWQm3ZcmqEDQtwgbxXbiZ50r2WBR+o3ZuAgzKsDX01k +7WgK95oRLYhn7ViSfqkvtOj0zoVbITDOs8CfIKXQFTzGem+Je8iamyXP3AanBhAlSLH zG5GiXfqZpawHUzUT+vX7jmpP6guzDff5o3g7Sy3zR7Omh7I6g2yCO4ElH/FL/c9Z21J mLvr/K0BYlD/nM6PQwjEPgRtW/Qorv4/iQmdoIibKvfsiBZor8NChGLGuImDG9PXXESa 4r6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774378660; x=1774983460; 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=zHUJhKlkW2RKdvmGDC9XYZkHzPyewcdTYblysDBGTTg=; b=H6UtLTv8vTgDWP2HplDeCTxm0NKtP8A0Nnq7QfyKNIwJA8uxzL3DVNI5ilHPgplX0a gy634kFQMkJHCJ88dGW6JK2OE/Jixa2DLNtHuQHabdptj88/Y0U9zH33/b+BvChdG4lq LBCfGFgJjrhQobuxM3cxKRLBaPcR3eZVHpRT/+oezROCloSTdIRxcqM9AWc0cejnQCEK 0CEpalhlVQUFaC89Cauz6WqD0xqJqwQpyl8fF3/F+zUsGt6JeLcj8xTfZtuGH1/q3/nd zhg+bU/OZn4G9OM3yjSCk+WmjoASWBsWc9be2sRpoYs4V93WJ73GdGta34rw4Jd/Sr+R PaQQ== X-Forwarded-Encrypted: i=1; AJvYcCV8y7TjrMdWLAdZrhJDM7gVT9XVDK6mKbzESNQEobWd0Ak6JD32M4rmzFvIr12BCyPay4Yr+m7PVJD57KCA@lists.postgresql.org X-Gm-Message-State: AOJu0YwJDFxnpuKFXb7OvpB78LWd+bjj9mtPq+2xGlgVFyPavYIts2ji sSLqfrAhAYR2VD1DgDDl+k9QsnNgKfAOZAsFjHT8P+aNiJrQmQVhvb2rQz4Grq7snVDkvQql/u+ 9uhJiykse+GuhMwcX3YFSJ0tqRkjxpBw= X-Gm-Gg: ATEYQzxGXA/T8pFQSHqN9BONkh4NJpCG0j2KxW+uj3VSG/SkCvPJ2xctRmH6Vi7cdml 19QP8wSuBZhDtQ1Q2UWveezKjJWC/GY0tbnOsRselUcS36/03Lm0dQ0H/GzSdcu70m7dcO1f1P8 g/KC8mSfVrl7GKFnjs58Af7VDh3mRGeT2blpu8RNGK+lRjX4aZ6FFgyAVgkmTCckwlaVumjALay KWKQ9v1COd04xxwIok6oMQ1jND3wXmt+OtH1dQ9vYozQUfS+nL/d4GadXmc18V/z9qxvqwyowsu hl9ktXypA7CUmJx5fFEAlYhnwMBs7umUrtm8gwx2jH7IICOnXUMtE7qCCyD09bhayHBJMUE5Shk Qqy7+mxEemCq7dUR9V+WqUNv8 X-Received: by 2002:a05:7022:2394:b0:128:d34a:320f with SMTP id a92af1059eb24-12a96e548f2mr319873c88.12.1774378659547; Tue, 24 Mar 2026 11:57:39 -0700 (PDT) MIME-Version: 1.0 References: <5ae9578e-f25e-49c5-97ab-ad27bc2050b5@eisentraut.org> In-Reply-To: <5ae9578e-f25e-49c5-97ab-ad27bc2050b5@eisentraut.org> From: Corey Huinker Date: Tue, 24 Mar 2026 14:57:27 -0400 X-Gm-Features: AaiRm51e1FEI1pKXvICDFnB7fJWkmzNxRHSFbDuFrIT4TB0Fv84-adxNm9NqEyI Message-ID: Subject: Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions To: Peter Eisentraut Cc: jian he , Amul Sul , Kirill Reshke , Vik Fearing , Isaac Morland , pgsql-hackers@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000b30d0a064dc9b980" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b30d0a064dc9b980 Content-Type: text/plain; charset="UTF-8" > > In the comment for patch 0021 you write that the function casting type > circle to type polygon cannot be error safe, because it's a SQL > language function. I suggest to convert this to a C function and make > the required changes there. > > About the main feature patch: I'm not a fan of the CREATE CAST > ... WITH SAFE FUNCTION syntax. First, the CREATE CAST syntax is part > of the SQL standard. It would be weird if we needed a nonstandard > syntax to make two standard features work together. Second, we didn't > do this when we introduced error-safe type input functions. There is > a note on the CREATE TYPE man page that use of ereturn() is > encouraged, and then we left it to extension authors to do the right > thing. (And we should now put a similar note on the CREATE CAST man > page.) And third, requiring this would require a lot of churn in all > affected extensions, requiring new extension SQL files and forcing > upgrades. The changes you did in patch 0023 don't do this correctly, > for example. This leaves us in a tricky situation if we can't tell ahead of time if a cast function really can handle soft errors. We could just allow any and all (CAST ... ON ERROR) calls even if the casting function can't actually return soft errors. That's unfortunate, but it might be the simplest and best way forward given that the alternative is to raise an error at planner time guaranteeing a query failure when the values presented might not have triggered the conversion errors. > Tactical suggestion: Add an SQL-callable function, say, > pg_cast_conversion_succeeds(srcvalue, desttype) that checks whether > the cast would succeed. This would be similar to the > pg_input_is_valid() function that we added to test the type input > functions. (I did not call my proposal pg_cast_is_valid() because > that might indicate merely that a casting path exists.) With that, > the higher-level functionality can be constructed by hand (CASE WHEN > pg_cast_conversion_succeeds(...) THEN CAST(...) ELSE 'default value' > END). And then we can later work on building out the higher-level > functionality and make more cast functions error safe. You're describing the the "x IS CASTABLE AS y" syntax proposed in the same standards proposal document :) --000000000000b30d0a064dc9b980 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
In the comment for patch 0021 you = write that the function casting type
circle to type polygon cannot be error safe, because it's a SQL
language function.=C2=A0 I suggest to convert this to a C function and make=
the required changes there.


About the main feature patch: I'm not a fan of the CREATE CAST
... WITH SAFE FUNCTION syntax.=C2=A0 First, the CREATE CAST syntax is part<= br> of the SQL standard.=C2=A0 It would be weird if we needed a nonstandard
syntax to make two standard features work together.=C2=A0 Second, we didn&#= 39;t
do this when we introduced error-safe type input functions.=C2=A0 There is<= br> a note on the CREATE TYPE man page that use of ereturn() is
encouraged, and then we left it to extension authors to do the right
thing.=C2=A0 (And we should now put a similar note on the CREATE CAST man page.)=C2=A0 And third, requiring this would require a lot of churn in all<= br> affected extensions, requiring new extension SQL files and forcing
upgrades.=C2=A0 The changes you did in patch 0023 don't do this correct= ly,
for example.

This leaves us in a tricky sit= uation if we can't tell ahead of time if a cast function really can han= dle soft errors. We could just allow any and all=C2=A0(CAST ... ON ERROR) c= alls even if the casting function can't actually return soft errors. Th= at's unfortunate, but it might be the simplest and best way forward giv= en that the alternative is to raise an error at planner time guaranteeing a= query failure when the values presented might not have triggered the conve= rsion errors.
=C2=A0
Tactical suggestion: Add an SQL-callable function, say,
pg_cast_conversion_succeeds(srcvalue, desttype) that checks whether
the cast would succeed.=C2=A0 This would be similar to the
pg_input_is_valid() function that we added to test the type input
functions.=C2=A0 (I did not call my proposal pg_cast_is_valid() because
that might indicate merely that a casting path exists.)=C2=A0 With that, the higher-level functionality can be constructed by hand (CASE WHEN
pg_cast_conversion_succeeds(...) THEN CAST(...) ELSE 'default value'= ;
END).=C2=A0 And then we can later work on building out the higher-level
functionality and make more cast functions error safe.
You're describing the the "x IS CASTABLE AS y" sy= ntax proposed in the same standards proposal document :)=C2=A0
<= /div> --000000000000b30d0a064dc9b980--