Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coy81-0004k7-3K for pgsql-bugs@arkaria.postgresql.org; Fri, 17 Mar 2017 20:05:37 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1coy7z-00053q-SW for pgsql-bugs@arkaria.postgresql.org; Fri, 17 Mar 2017 20:05:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1coy7I-0003mM-Jb for pgsql-bugs@postgresql.org; Fri, 17 Mar 2017 20:04:52 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1coy7E-00082b-Bd for pgsql-bugs@postgresql.org; Fri, 17 Mar 2017 20:04:52 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v2HK4jJW028170; Fri, 17 Mar 2017 16:04:45 -0400 From: Tom Lane To: "David G. Johnston" cc: Alex Malek , "pgsql-bugs@postgresql.org" Subject: Re: BUG #14512: Backslashes in LIKE In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Fri, 17 Mar 2017 11:25:26 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <28168.1489781085.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 17 Mar 2017 16:04:45 -0400 Message-ID: <28169.1489781085@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org "David G. Johnston" writes: > On Fri, Mar 17, 2017 at 11:16 AM, Alex Malek wrote: >> Given the current behavior the same query will work or raise on error >> based on context. > Recently discussed here: > https://www.postgresql.org/message-id/flat/20170124172505.1431.56735%40wr= igleys.postgresql.org#20170124172505.1431.56735@wrigleys.postgresql.org > In short - preventing a "fails-to-fail" scenario here doesn't seem worthy > of the effort and run-time cost doing so would entail. BTW, looking again at the patch I suggested in https://www.postgresql.org/message-id/10287.1485286334%40sss.pgh.pa.us it strikes me that the check logic was unnecessarily stupid. What we need to check is that there's not an odd number of backslashes at the end of the pattern. Since we know that backend encodings are ASCII-safe, the test logic could be changed to scan backwards, something like p +=3D plen; nbackslash =3D 0; while (plen-- > 0) { if (*(--p) =3D=3D '\\') nbackslash++; else break; } if (nbackslash & 1) ereport(ERROR, ...); For patterns of practical interest this would be of small and nearly constant cost. Maybe it is worth doing, especially since we've now had two independent complaints about it. regards, tom lane --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs