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 1p49lX-0002JY-P4 for pgsql-hackers@arkaria.postgresql.org; Sun, 11 Dec 2022 00:00:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p49lV-0007XH-Up for pgsql-hackers@arkaria.postgresql.org; Sun, 11 Dec 2022 00:00:21 +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 1p49lV-0007WZ-JW for pgsql-hackers@lists.postgresql.org; Sun, 11 Dec 2022 00:00:21 +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 1p49lT-00037q-Oo for pgsql-hackers@lists.postgresql.org; Sun, 11 Dec 2022 00:00:20 +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 2BB00Dd71545656; Sat, 10 Dec 2022 19:00:13 -0500 From: Tom Lane To: Andrew Dunstan cc: Andres Freund , Alexander Korotkov , Robert Haas , "David G. Johnston" , Corey Huinker , Alvaro Herrera , Joe Conway , Nikita Glukhov , PostgreSQL Hackers Subject: Re: Error-safe user functions In-reply-to: <2b1e7d56-6f37-bad9-9702-053ab55ecf60@dunslane.net> References: <4009543.1670422833@sss.pgh.pa.us> <6acddf68-7cb7-e9e7-a5a7-0abc87b3c55b@dunslane.net> <4111458.1670444176@sss.pgh.pa.us> <3211.1670452341@sss.pgh.pa.us> <20221207233518.sudtaxn6omtvpzvr@awork3.anarazel.de> <186288.1670517119@sss.pgh.pa.us> <20221208215836.3naznqmal2m32hzc@awork3.anarazel.de> <512551.1670540229@sss.pgh.pa.us> <20221209023351.l362yejerfoq3lfp@awork3.anarazel.de> <633426.1670554790@sss.pgh.pa.us> <01ff2051-806d-af2f-4f9e-793f7ba9a3f8@dunslane.net> <778369.1670598993@sss.pgh.pa.us> <5aaf7c66-9df9-21a9-1ff4-02c7848def52@dunslane.net> <3bac9841-fe07-713d-fa42-606c225567d6@dunslane.net> <1436686.1670701118@sss.pgh.pa.us> <2b1e7d56-6f37-bad9-9702-053ab55ecf60@dunslane.net> Comments: In-reply-to Andrew Dunstan message dated "Sat, 10 Dec 2022 18:11:35 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1545654.1670716813.1@sss.pgh.pa.us> Date: Sat, 10 Dec 2022 19:00:13 -0500 Message-ID: <1545655.1670716813@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andrew Dunstan writes: > On 2022-12-10 Sa 14:38, Tom Lane wrote: >> Seeing that SQL/JSON is one of the major drivers of this whole project, >> it seemed a little sad to me that jsonb couldn't manage to implement >> what is required. So I spent a bit of time poking at it. Attached >> is an extended version of your patch that also covers jsonb. > Many thanks for doing this, it looks good. Cool, thanks. Looking at my notes, there's one other loose end I forgot to mention: * Note: pg_unicode_to_server() will throw an error for a * conversion failure, rather than returning a failure * indication. That seems OK. We ought to do something about that, but I'm not sure how hard we ought to work at it. Perhaps it's sufficient to make a variant of pg_unicode_to_server that just returns true/false instead of failing, and add a JsonParseErrorType for "untranslatable character" to let json_errdetail return a reasonably on-point message. We could imagine extending the ErrorSaveContext infrastructure into the encoding conversion modules, and maybe at some point that'll be worth doing, but in this particular context it doesn't seem like we'd be getting a very much better error message. The main thing that we would get from such an extension is a chance to capture the report from report_untranslatable_char. But what that adds is the ability to identify exactly which character couldn't be translated --- and in this use-case there's always just one. regards, tom lane