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.94.2) (envelope-from ) id 1tDROD-000ioR-JU for pgsql-bugs@arkaria.postgresql.org; Tue, 19 Nov 2024 16:47:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tDROC-00Elhj-3b for pgsql-bugs@arkaria.postgresql.org; Tue, 19 Nov 2024 16:47:44 +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.94.2) (envelope-from ) id 1tDROB-00Elhb-Qf for pgsql-bugs@lists.postgresql.org; Tue, 19 Nov 2024 16:47:43 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tDRO9-002j64-CZ for pgsql-bugs@lists.postgresql.org; Tue, 19 Nov 2024 16:47: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 4AJGleI93778529; Tue, 19 Nov 2024 11:47:40 -0500 From: Tom Lane To: "David G. Johnston" cc: Chris BSomething , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18715: replace() function silently fails if 3rd argument is null In-reply-to: References: <18715-7035b5d78571887e@postgresql.org> Comments: In-reply-to "David G. Johnston" message dated "Tue, 19 Nov 2024 08:30:18 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <3778527.1732034860.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Tue, 19 Nov 2024 11:47:40 -0500 Message-ID: <3778528.1732034860@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Tue, Nov 19, 2024 at 8:08 AM Chris BSomething > wrote: >> Nowhere (that I can see) does any documentation "define" that replace >> returns null on null input to arg 3. Nor is it obvious that any "strict" >> application of any principle should have it return null. > Fair, I keep forgetting that we don't document the "strict" property of a > function definition. Absent that, I agree it's a documentation bug that we > don't adequately explain the strictness behavior of this function. I thought we documented somewhere that built-in functions are strict unless explicitly stated otherwise ... but I sure can't find that statement right now. > "Replacing text with null is problematic, but no problem arises if there is > nothing to be done." - while true I see little desire to make that > conditionalized behavior reality. IOW, you are correct, but it also isn't > likely to change. The current behavior benefits developers over users, but > we make up for it by spending time elsewhere. It's generally true in the SQL standard that functions yield null if any of their inputs are null. In some cases you could argue that a particular input might not be consulted given the values of the other inputs, but they've steered away from that sort of definitional and implementation complexity. And so have we. regards, tom lane