Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p0o57-0007FV-HW for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Dec 2022 18:14:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p0o56-0000pb-3d for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Dec 2022 18:14:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p0o55-0000mS-QL for pgsql-hackers@lists.postgresql.org; Thu, 01 Dec 2022 18:14:43 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p0o50-00064D-KA for pgsql-hackers@lists.postgresql.org; Thu, 01 Dec 2022 18:14:42 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 2B1IEZLj1677335; Thu, 1 Dec 2022 13:14:35 -0500 From: Tom Lane To: Andrew Dunstan cc: Corey Huinker , Nikita Glukhov , PostgreSQL Hackers Subject: Re: Error-safe user functions In-reply-to: <469338a3-da38-160f-23b9-813c261bc1d6@dunslane.net> References: <3bbbb0df-7382-bf87-9737-340ba096e034@postgrespro.ru> <3190059.1665164276@sss.pgh.pa.us> <57b7cc2e-1215-3f43-84e4-6d9f8ad575df@dunslane.net> <3049337.1669008405@sss.pgh.pa.us> <469338a3-da38-160f-23b9-813c261bc1d6@dunslane.net> Comments: In-reply-to Andrew Dunstan message dated "Thu, 01 Dec 2022 12:46:48 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1677333.1669918475.1@sss.pgh.pa.us> Date: Thu, 01 Dec 2022 13:14:35 -0500 Message-ID: <1677334.1669918475@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andrew Dunstan writes: > OK, here's a set of minimal patches based on Nikita's earlier work and > also some work by my colleague Amul Sul. It tries to follow Tom's > original outline at [1], and do as little else as possible. This is not really close at all to what I had in mind. The main objection is that we shouldn't be passing back a "char *" error string (though I observe that your 0003 and 0004 patches aren't even bothering to do that much). I think we want to pass back a fully populated ErrorData struct so that we can report everything the actual error would have done (notably, the SQLSTATE). That means that elog.h/.c has to be intimately involved in this. I liked Nikita's overall idea of introducing an "ereturn" macro, with the idea that where we have, say, ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("value \"%s\" is out of range for type %s", s, "integer"))); we would write ereturn(context, ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("value \"%s\" is out of range for type %s", s, "integer"))); return NULL; // or whatever is appropriate and the involvement with the contents of the context node would all be confined to some new code in elog.c. That would help prevent the #include-footprint-bloat that is otherwise going to ensue. (Maybe we could assume that ereturn's elevel must be ERROR, and save a little notation. I'm not very wedded to "ereturn" as the new macro name either, though it's not awful.) Also, as I said before, the absolute first priority has to be documentation explaining what function authors are supposed to do differently than before. I'd be willing to have a go at this myself, except that Corey said he was working on it, so I don't want to step on his toes. regards, tom lane