Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hPMt1-0007zu-0N for pgsql-bugs@arkaria.postgresql.org; Sat, 11 May 2019 07:57:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hPMsz-0008RF-Ji for pgsql-bugs@arkaria.postgresql.org; Sat, 11 May 2019 07:57:37 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1hPJE0-0003Ef-8q for pgsql-bugs@lists.postgresql.org; Sat, 11 May 2019 04:03:04 +0000 Received: from impout007aa.msg.chrl.nc.charter.net ([47.43.20.31] helo=impout007.msg.chrl.nc.charter.net) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hPJDx-00053s-35 for pgsql-bugs@lists.postgresql.org; Sat, 11 May 2019 04:03:03 +0000 Received: from [192.168.1.2] ([47.132.226.193]) by cmsmtp with ESMTPA id PJDuhlQWDAWAqPJDuhLNiz; Sat, 11 May 2019 04:02:58 +0000 Authentication-Results: charter.net; none X-Authority-Analysis: v=2.3 cv=VfdDw2h9 c=1 sm=1 tr=0 a=UVxt8pgA054IHyNJLTVX1g==:117 a=UVxt8pgA054IHyNJLTVX1g==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=r77TgQKjGQsHNAKrUKIA:9 a=C6mgOIWBtKoe3RlNQ04A:9 a=QEXdDO2ut3YA:10 a=pqDPihL8BdIA:10 a=tJsXVqsz4oGMXm3FtMQA:9 a=8ZOFDIcGHtVpcMkf:21 a=_W_S_7VecoQA:10 a=3O8iSk74Gn3WYMLngV0A:9 a=qLHUaOcJTVYA:10 a=1LvsVVXEYnEP-TNTRwMA:9 a=m-Z_27IZkzAA:10 Subject: PostgreSQL 9.3.5 substring(text from pattern for escape) bug References: <08036370-e3d3-3a28-ab2a-da13db8be65e@charter.net> To: pgsql-bugs@lists.postgresql.org From: Robert Schreiber X-Forwarded-Message-Id: <08036370-e3d3-3a28-ab2a-da13db8be65e@charter.net> Message-ID: <5bb27a41-350d-37bf-901e-9d26f5592dd0@charter.net> Date: Sat, 11 May 2019 00:02:57 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <08036370-e3d3-3a28-ab2a-da13db8be65e@charter.net> Content-Type: multipart/mixed; boundary="------------57A03B002E898909A839885B" Content-Language: en-US X-CMAE-Envelope: MS4wfI2OCv4DQYovOSwtQKMOqHqsmdGFIDJ8TvhkZiJNeeF2RgM6lrGlFHEczlNVPK2BTywQ38WJHnVNrG8LVdL2vC9Wc+5QRHKUKOc6VBiaXF5PWvBHnV6m Ck/FBwZ5dYtNzMbf7Dx1HY5wwJaqQ4ILc4hVwlvz8mY79tB/Zvu9ebZJlL8XZ/wTqiOkwGOCINc+ng== List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------57A03B002E898909A839885B Content-Type: multipart/alternative; boundary="------------729FF3DE8F687358C7CF7B35" --------------729FF3DE8F687358C7CF7B35 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit I believe I have come across a bug in the substring(text from pattern for escape) function. What I am attempting to do is take a string like 'QMy NameQ' , strip off leading/and/or/trailing Qs and return 'My Name'. The substring() call that I have coded is substring(xxx from 'Q?#"%#"Q?' FOR '#') My understand of this is: Q?     -- matches 0 or 1 occurrences of Q (the leading one, if present) #"     -- starts data collection %    -- matches any number of characters #"   -- ends data collection Q?  -- matches 0 or 1 occurrences of Q (the trialing one, if present) What appears to be happening is that the _Q? on the tail_ is being matched, but _the Q is also being included in the collected data.__ _ The attached PSQL test.sql file creates a table, populates it with 7 test cases with my expected results, and then executes substring() against it. There is an attached test_output.txt file is the PSQL output that illustrates the problem. The column "Error" is true when the actual value disagrees with what I expected. Robert Schreiber 410-392-9553 PostgreSQL 9.3.5, compiled by Visual C++ build 1600, 64-bit Running under Windows 10 64-bit. --------------729FF3DE8F687358C7CF7B35 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit I believe I have come across a bug in the substring(text from pattern for escape) function.

What I am attempting to do is take a string like 'QMy NameQ' , strip off leading/and/or/trailing Qs and return 'My Name'.

The substring() call that I have coded is substring(xxx from 'Q?#"%#"Q?' FOR '#')

My understand of this is:
Q?     -- matches 0 or 1 occurrences of Q (the leading one, if present)
#"     -- starts data collection
%    -- matches any number of characters
#"   -- ends data collection
Q?  -- matches 0 or 1 occurrences of Q (the trialing one, if present)

What appears to be happening is that the Q? on the tail is being matched, but the Q is also being included in the collected data.

The attached PSQL test.sql file creates a table, populates it with 7 test cases with my expected results, and then executes substring() against it.

There is an attached test_output.txt file is the PSQL output that illustrates the problem. The column "Error" is true when the actual value disagrees with what I expected.

Robert Schreiber
410-392-9553

PostgreSQL 9.3.5, compiled by Visual C++ build 1600, 64-bit
Running under Windows 10 64-bit.
--------------729FF3DE8F687358C7CF7B35-- --------------57A03B002E898909A839885B Content-Type: text/plain; charset=UTF-8; name="test.sql" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="test.sql" XHNldCBPTl9FUlJPUl9TVE9QIDENCg0KZHJvcCB0YWJsZSBpZiBleGlzdHMgdGVzdF90YWJs ZSBjYXNjYWRlOw0KDQpzZWxlY3QgdmVyc2lvbigpOw0KDQpjcmVhdGUgdGVtcG9yYXJ5IHRh YmxlIHRlc3RfdGFibGUNCigNCiAgICB4eHggdmFyY2hhcigzMiksDQogICAgZXhwZWN0ZWQg dmFyY2hhcigzMikNCik7DQoNCmluc2VydCBpbnRvIHRlc3RfdGFibGUgdmFsdWVzICgnTXkg USBOYW1lJywgICAgICAnTXkgUSBOYW1lJyApOzsNCmluc2VydCBpbnRvIHRlc3RfdGFibGUg dmFsdWVzICgnUU15IFEgTmFtZScsICAgICAnTXkgUSBOYW1lJyApOzsNCmluc2VydCBpbnRv IHRlc3RfdGFibGUgdmFsdWVzICgnTXkgUSBOYW1lUScsICAgICAnTXkgUSBOYW1lJyApOzsN Cmluc2VydCBpbnRvIHRlc3RfdGFibGUgdmFsdWVzICgnUU15IFEgTmFtZVEnLCAgICAnTXkg USBOYW1lJyApOzsNCg0KaW5zZXJ0IGludG8gdGVzdF90YWJsZSB2YWx1ZXMgKCdRUU15IFEg TmFtZScsICAgICdRTXkgUSBOYW1lJyApOzsNCmluc2VydCBpbnRvIHRlc3RfdGFibGUgdmFs dWVzICgnTXkgUSBOYW1lUVEnLCAgICAnTXkgUSBOYW1lUScgKTs7DQppbnNlcnQgaW50byB0 ZXN0X3RhYmxlIHZhbHVlcyAoJ1FRTXkgUSBOYW1lUVEnLCAgJ1FNeSBRIE5hbWVRJyApOzsN Cg0KLS0gUmV0dXJuIHNyaW5nIHh4eCB3aXRoIGZpcnN0IGFuZCBsYXN0ICJRIiByZW1vdmVk Li4uDQpjcmVhdGUgdGVtcG9yYXJ5IHZpZXcgdGVzdF92aWV3IGFzDQpzZWxlY3QgeHh4LCBl eHBlY3RlZCwgc3Vic3RyaW5nKHh4eCBmcm9tICdRPyMiJSMiUT8nIEZPUiAnIycpIGFzIGFj dHVhbCBmcm9tIHRlc3RfdGFibGU7DQoNCnNlbGVjdCB4eHgsZXhwZWN0ZWQsYWN0dWFsLChh Y3R1YWwgPD4gZXhwZWN0ZWQpIGFzIGVycm9yIGZyb20gdGVzdF92aWV3Ow0K --------------57A03B002E898909A839885B Content-Type: text/plain; charset=UTF-8; name="test_output.txt" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="test_output.txt" XHNldCBPTl9FUlJPUl9TVE9QIDENCg0KZHJvcCB0YWJsZSBpZiBleGlzdHMgdGVzdF90YWJs ZSBjYXNjYWRlOw0KcHNxb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