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 1vKzXX-00FwLU-2k for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Nov 2025 13:45:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vKzXT-00ESQ6-01 for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Nov 2025 13:45:03 +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 1vKzXS-00ESPu-22 for pgsql-hackers@lists.postgresql.org; Mon, 17 Nov 2025 13:45:02 +0000 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vKzXQ-007diJ-24 for pgsql-hackers@lists.postgresql.org; Mon, 17 Nov 2025 13:45:01 +0000 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2956d816c10so45421525ad.1 for ; Mon, 17 Nov 2025 05:45:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1763387034; x=1763991834; 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=aW2vgaoN7UJ5a4Ul4uDGPNssJ7YeVgd899wK8UWXqqM=; b=KgraflDaKsama4fXhiWn50bDe4JFDM1p0gw07hRZr/aiBZIBQMC2onSP8ld+hDV4Of ECD/5sJUnfBQ12Uk+wlbXlVvJfXgtCYYEAizNydYb9++1UY0pQFEGLGAe9MEPPXTZI1t zE+C1f0WKIj44IeVo1Mm3jyDfa6VyCVVK8Wc2jqD4ZfypsBn0GBF63FkhG398S6GZ5Kc BlBFZwNinBXStfHDanLpEXxBvV2eNKTS9dd2rGWyEpvGf8BUYEAkDD+1x4zwvkZPDu6P SzHinAxHyYrYysVV0h5YpRCaEJGATJ4tzjMCY0p2ty5zGUB+vxsxR7zCkLxcv9EiEpsI rluw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763387034; x=1763991834; 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=aW2vgaoN7UJ5a4Ul4uDGPNssJ7YeVgd899wK8UWXqqM=; b=r/YAs/J+KOcb7/zLeCANeE3TpVdbAAsIFIOCtWcI5DP/dewEZaT7koDMyrGPPXK6h3 ZHdv+1yGHBw8o/YFlysj9rNajgVKBCiYZVKcDgZbKub2jdk9iPt4UhRrF4RG9+FJzlJa X/uY6wbA38cFIVNcSJatvwkIoeUyJuUwUQlJBBDV17/3bVFMZscyBZyuEduvEv2OsBPN 5oUKO0B1AE5swN0TvDfAp9QRzAlAM5jiLbVfWi/dTKh8FG615At7ymHU2LZI+3Upi1gI a+8RNQC9FCnDexeE+AWk6cqkXM/P1k4XGpUWc8HrUaqosdk65/CdW4d0dd8UZ6HGFAjC GmSQ== X-Forwarded-Encrypted: i=1; AJvYcCW3UpYPDzWHPsSbfmk/k8/P0TnDsIL2+QszLIVzhQ9cuHH/sVSMDsw3FQ5AupVg5Kp8YLt2afXUZz0YQaFm@lists.postgresql.org X-Gm-Message-State: AOJu0YzBBVc381j4c8YPaNWhd3BFIErAI3FR8tG8WlBTcA/MAFMJSuK0 VtLJQh4uxdtc2+tup2WOsor+OknHVJbf0bzRL9NBE29bpqEXu/Slw5z7pfPoRUF6HvU46QZFyi9 1DSCQTYXEcZe6r9P3aheuM/sPHURvJOs= X-Gm-Gg: ASbGncucRA2mNvf8XiPUE3mc9kYb1r48kulGzdcbWjmawGNp+Upp4wLoPFDnxywHSCz 0pqB8ffcGzwhyAHiE1/qbSe1WqcbxuL8foKL/UkdceB8esQrZsT21RxvCScIZd8Sq+gJ8eGQpXS IS6xGloK5pjvUwP/O9LV3vpNxvDqRC4h2HcpRXcIt3EFqHPA6rputZXkHCKao+E1eRXSzy/T8MT h2VUc0Sy7vg0MKQU7Tcotx511trL9ogJt9MxL/RHIiM+NpMc0gO4gY9RjsGb5HAS6kV1S8AVQ== X-Google-Smtp-Source: AGHT+IFJtiN+8247fO5E51RVNq8CQY1qPYzsI2H18TnBp/h2TLjOgb7llsJ700xNxjmpBYvbeBLZnMI2akt84nh9+Hg= X-Received: by 2002:a17:903:4b07:b0:298:603b:dc46 with SMTP id d9443c01a7336-2986a741ab9mr146467055ad.39.1763387034365; Mon, 17 Nov 2025 05:43: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: Mon, 17 Nov 2025 19:13:15 +0530 X-Gm-Features: AWmQ_bn2yC8XgmY5hw2xGl62u2FZrGM7B-ZADrVZ-ux4ywqw8HXGx-mFcVs_478 Message-ID: Subject: Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions To: jian he Cc: Corey Huinker , 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 Tue, Nov 11, 2025 at 8:37=E2=80=AFAM jian he wrote: > > On Thu, Nov 6, 2025 at 6:00=E2=80=AFAM Corey Huinker wrote: > > [...] > > Currently, patches v9-0001 through v9-0018 focus solely on refactoring > pg_cast.castfunc. I had a quick look but haven't finished the full review due to lack of time today. Here are a few initial comments: v10-0003: - NO_XML_SUPPORT(); + errsave(escontext, + errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("unsupported XML feature"), + errdetail("This functionality requires the server to be built with libxml support.")); return NULL; Can use ereturn() instead of errsave() followed by return NULL. -- 10-0004: +/* error safe version of textToQualifiedNameList */ +List * +textToQualifiedNameListSafe(text *textval, Node *escontext) If I am not mistaken, it looks like an exact copy of textToQualifiedNameList(). I think you can simply keep only textToQualifiedNameListSafe() and call that from textToQualifiedNameList() with a NULL value for escontext. This way, all errsave() or ereturn() calls will behave like ereport(). The same logic applies to RangeVarGetRelidExtendedSafe() and makeRangeVarFromNameListSafe. These can be called from RangeVarGetRelidExtended() and makeRangeVarFromNameList(), respectively. -- + { + errsave(escontext, + errcode(ERRCODE_INVALID_NAME), + errmsg("invalid name syntax")); + return NIL; + } I prefer ereturn() instead of errsave + return. -- v10-0017 for (i =3D 0; i < lengthof(messages); i++) if (messages[i].type =3D=3D type) - ereport(ERROR, + { + errsave(escontext, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg(messages[i].msg, sqltype))); + return; + } Here, I think, you can use ereturn() to return void. -- v10-0018 + if (unlikely(result =3D=3D 0.0) && val1 !=3D 0.0 && !isinf(val2)) + { + errsave(escontext, + errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), + errmsg("value out of range: underflow")); + + result =3D 0.0; + return result; + } Here, you can use ereturn() to return 0.0. Similar changes are needed at other places in the same patch. Regards, Amul