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 1vbYLJ-007NCP-1W for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Jan 2026 06:08:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vbYLI-009TXL-11 for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Jan 2026 06:08:57 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vbYLI-009TXD-03 for pgsql-hackers@lists.postgresql.org; Fri, 02 Jan 2026 06:08:56 +0000 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vbYLH-003lln-1d for pgsql-hackers@lists.postgresql.org; Fri, 02 Jan 2026 06:08:55 +0000 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-34c565b888dso13120042a91.0 for ; Thu, 01 Jan 2026 22:08:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767334134; x=1767938934; 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=Wi0/e6AyzenpGUkLYqDtzElsqHcDPEtwy2XTCeKZvcc=; b=I3LXyt7uSUd7dYA3YXPxV6wP+xmeE2MW8mi96D/Rns4YhCToI2apz77wXiTa8n2p34 aTwiKn+KNISfiGxrNDY76R/ENmBtSlYyeUd4tobKUCoDGrcQT2gKTscD5wSFZAkEJleT 267C8hEPZIP00afHLERlIFqAUT40bndO5zRlzNLZw/yb6ekgVguL6ubkt339FJ2M5a9I SuMMo/O/KtUcIYhcD5Px0dlDiBP1C8ZCKBrjvZzrCaQqBlV+rccWi/TwjaNGxapxsfli j7da56gd8ftcLudWtnvzR1xQZjCuPDE2enM0Qi4JcbDZvLwOsfjJuykYGEDyojONrcWd mf/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767334134; x=1767938934; 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=Wi0/e6AyzenpGUkLYqDtzElsqHcDPEtwy2XTCeKZvcc=; b=n1w0FreD6QaFfc/+djepD88ew3Xy64zx5KqQGmeukFOJxwfkHC5odq9fGjSQbZX7kg bl1chAqObiAYMssYX8OubjYQZi31JVeELx/pu0LKoOFnARo5SKhwKmyE8m18WSvfnL0r p9lWMAmWxS3H+Z1PMkyLMYyXWH4OD4ZrpjscutU5uJcuDrM0JeWVTEcncCxUQtA4gNZV PqY+nt8P3DZC6FGgRyGD1FLoLIiNFtvN7fkSsS4scGjBMU0K2Kf1Ny+pYkzGro7ACSdx yG9Z1gwr5I3g4vB6r3MqBS8AJTdbCzCRyo8/482UYj3SCnAeMqFhx14/SIdYycVLWT+J Yh5A== X-Forwarded-Encrypted: i=1; AJvYcCW+OUqUmFwyEEJwQpoeDDdBd+WD4TNxgUNqB/QeKDu3I/QUnk4/kMv2/CCVeCBzQzxLk2Pgl0/oBIEDH9kp@lists.postgresql.org X-Gm-Message-State: AOJu0Yz61BxcEzKuUwYNgohTn7BzWhiTsiwGQ3GasMnegT8LBPHa7cGP mtIREboj1Y7zGjOfKmGFIUtX/2738cFbd4Uxv7h4kxIQSZZRrv8QI8pf57zA7FVoPibus8nat4Z ud/WsoNFXwhA2OgxHzNLoqYZuO3NobKU= X-Gm-Gg: AY/fxX5X9PbmsAQWvjEW12LfU4shdmeharrC4cOW5NrIdRd2XiLWGdZjwJ3aLRxRdvk 6T3GfCagftBVWWN2ty3OGEPMxdYBriRi+jDA9bNkMNvoqRk9OE/ciM4llBDyMgjmd7TOLoQUTYq Gyxw+Pxoah+U4Zt329wn3aFCGskxSbFsDT5sJ1VTFKwfZ0+TX0qe2gOMxzeUiUUzE2fECNi1sSK ZFklbV/jylbnNQJdF9dOO40WWzPOTY7DGzz1542sr5/quwXi2hpQaviJoC4RX8jaYq2mdxERrRy NvPg14ys X-Google-Smtp-Source: AGHT+IGzMiT+9vzpbkIOXUTJmGCENjZWC12CUGY37y7VEsfGJLGXCObTlQKac0C+1p72tZEBJya69n3AQkWgNt2osYg= X-Received: by 2002:a17:90b:5903:b0:33b:b020:597a with SMTP id 98e67ed59e1d1-34e91f74e3dmr34923889a91.0.1767334134018; Thu, 01 Jan 2026 22:08:54 -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: Amul Sul Date: Fri, 2 Jan 2026 11:38:16 +0530 X-Gm-Features: AQt7F2pU4UPdKM0AM9hNO5g7UTJZWlfUPjsr97nSgU92UjvyyqxhGYrF6iMo1Bc Message-ID: Subject: Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions To: jian he Cc: Kirill Reshke , Corey Huinker , Vik Fearing , Isaac Morland , pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, I am still thinking through a design that avoids having two different code paths for type casting. Can't we avoid adding a new SafeTypeCast structure by simply adding a raw_default variable (name could be simply default) to the existing TypeCast structure? If we do that, we would need to update transformTypeCast() and other places (like ExecInterpExpr()) to handle the raw_default. This approach would allow us to avoid the extra code required for a new node structure (e.g., T_SafeTypeCastExpr) and a separate EEOP_SAFETYPE_CAST step. Here are few other comments: vv16-0019: +float8_div_safe(const float8 val1, const float8 val2, struct Node *escontext) Patches show an inconsistent use of Node* and struct Note * for the escontext argument. I suggest standardising on Note * to maintain consistency throughout the code. -- v16-0020: @@ -839,7 +839,7 @@ box_distance(PG_FUNCTION_ARGS) box_cn(&a, box1); box_cn(&b, box2); - PG_RETURN_FLOAT8(point_dt(&a, &b)); + PG_RETURN_FLOAT8(point_dt(&a, &b, NULL)); I think user-callable functions that accept PG_FUNCTION_ARGS; should directly pass fcinfo->context instead of NULL. -- v16-0022: +Sometimes a type cast may fail; to avoid such fail case, an ON ERROR clause can be .. + default expression in ON ERROR clause. Shouldn't it be ON CONVERSION ERROR instead of ON ERROR ? -- + state->escontext = makeNode(ErrorSaveContext); + state->escontext->type = T_ErrorSaveContext; + state->escontext->error_occurred = false; + state->escontext->details_wanted = false; No need to assign values to the rest of the escontext members; makeNode(ErrorSaveContext) is sufficient. I also think ExecInitExprSafe() should receive escontext from the caller. Instead of passing an error_safe boolean to evaluate_expr, you can pass the escontext itself; this can then be passed down to ExecInitExprSafe, helping capture soft error information at a much higher level. In that way, you can simply call ExecInitExprSafe() from ExecInitExpr() and pass NULL for the escontext. This reduces code duplication, since most of the code is similar except for the aforementioned initialization lines. Regards, Amul