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 1nedH4-0002p2-RE for pgsql-bugs@arkaria.postgresql.org; Wed, 13 Apr 2022 13:43:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nedH3-0001ZS-HW for pgsql-bugs@arkaria.postgresql.org; Wed, 13 Apr 2022 13:43:09 +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 1nedH3-0001XE-8g for pgsql-bugs@lists.postgresql.org; Wed, 13 Apr 2022 13:43:09 +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 1nedH0-0000Fo-Vj for pgsql-bugs@lists.postgresql.org; Wed, 13 Apr 2022 13:43:08 +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 23DDh48n1089633; Wed, 13 Apr 2022 09:43:04 -0400 From: Tom Lane To: Julien Rouhaud cc: Susanne Holzgraefe , pgsql-bugs@lists.postgresql.org Subject: Re: replace() using NULL In-reply-to: References: <29A17362-1756-422E-9BD3-2CBE9F8C990F@web.de> Comments: In-reply-to Julien Rouhaud message dated "Wed, 13 Apr 2022 19:34:29 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1089631.1649857384.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 13 Apr 2022 09:43:04 -0400 Message-ID: <1089632.1649857384@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Julien Rouhaud writes: > On Wed, Apr 13, 2022 at 10:38:28AM +0200, Susanne Holzgraefe wrote: >> SELECT REPLACE('xyz=E2=80=98, 'a=E2=80=98, NULL); =3D> NULL > The function is declared as STRICT, which means that it won't be called = at all > and just returns NULL if any of its parameters is NULL. Right. The SQL standard doesn't seem to have a REPLACE function, so it's hard to settle this by appealing to the standard; but it's reasonable to suppose that if they did define it then it would be specified to work like the existing substring manipulation functions --- and those are all strict per spec. For example, the spec for SUBSTRING says d) If at least one of C, S, and L is the null value, then the result of the is the null value. and there is equivalent verbiage in every other subparagraph of SQL:2021 6.32 . >> Tested with Oracle, result is =E2=80=9Axyz=E2=80=98. > Maybe oracle supports such calls as it supports NULL bytes in strings (I > think), but postgres doesn't. Oracle is a very suspect reference when it comes to behaviors involving NULL, because they are not even a little bit spec-compliant there. My understanding is that they can't really represent a NULL string at all, and fake it as being an empty string ('') ... which of course yields that result in this case. regards, tom lane