From: Robert Schreiber <bobschreiber@charter.net>
To: pgsql-bugs@lists.postgresql.org
Subject: PostgreSQL 9.3.5 substring(text from pattern for escape) bug
Date: Sat, 11 May 2019 00:02:57 -0400
Message-ID: <5bb27a41-350d-37bf-901e-9d26f5592dd0@charter.net> (raw)
In-Reply-To: <08036370-e3d3-3a28-ab2a-da13db8be65e@charter.net>
References: <08036370-e3d3-3a28-ab2a-da13db8be65e@charter.net>
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.
Attachments:test.sql (text/plain, 909B) download
\set ON_ERROR_STOP 1
drop table if exists test_table cascade;
select version();
create temporary table test_table
(
xxx varchar(32),
expected varchar(32)
);
insert into test_table values ('My Q Name', 'My Q Name' );;
insert into test_table values ('QMy Q Name', 'My Q Name' );;
insert into test_table values ('My Q NameQ', 'My Q Name' );;
insert into test_table values ('QMy Q NameQ', 'My Q Name' );;
insert into test_table values ('QQMy Q Name', 'QMy Q Name' );;
insert into test_table values ('My Q NameQQ', 'My Q NameQ' );;
insert into test_table values ('QQMy Q NameQQ', 'QMy Q NameQ' );;
-- Return sring xxx with first and last "Q" removed...
create temporary view test_view as
select xxx, expected, substring(xxx from 'Q?#"%#"Q?' FOR '#') as actual from test_table;
select xxx,expected,actual,(actual <> expected) as error from test_view;
test_output.txt (text/plain, 1.7K) download
\set ON_ERROR_STOP 1
drop table if exists test_table cascade;
psql:test.sql:3: NOTICE: drop cascades to view test_view
DROP TABLE
select version();
version
-------------------------------------------------------------
PostgreSQL 9.3.5, compiled by Visual C++ build 1600, 64-bit
(1 row)
create temporary table test_table
(
xxx varchar(32),
expected varchar(32)
);
CREATE TABLE
insert into test_table values ('My Q Name', 'My Q Name' );;
INSERT 0 1
insert into test_table values ('QMy Q Name', 'My Q Name' );;
INSERT 0 1
insert into test_table values ('My Q NameQ', 'My Q Name' );;
INSERT 0 1
insert into test_table values ('QMy Q NameQ', 'My Q Name' );;
INSERT 0 1
insert into test_table values ('QQMy Q Name', 'QMy Q Name' );;
INSERT 0 1
insert into test_table values ('My Q NameQQ', 'My Q NameQ' );;
INSERT 0 1
insert into test_table values ('QQMy Q NameQQ', 'QMy Q NameQ' );;
INSERT 0 1
-- Return sring xxx with first and last "Q" removed...
create temporary view test_view as
select xxx, expected, substring(xxx from 'Q?#"%#"Q?' FOR '#') as actual from test_table;
CREATE VIEW
select xxx,expected,actual,(actual <> expected) as error from test_view;
xxx | expected | actual | error
---------------+-------------+--------------+-------
My Q Name | My Q Name | My Q Name | f
QMy Q Name | My Q Name | My Q Name | f
My Q NameQ | My Q Name | My Q NameQ | t
QMy Q NameQ | My Q Name | My Q NameQ | t
QQMy Q Name | QMy Q Name | QMy Q Name | f
My Q NameQQ | My Q NameQ | My Q NameQQ | t
QQMy Q NameQQ | QMy Q NameQ | QMy Q NameQQ | t
(7 rows)
postgres=>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: bobschreiber@charter.net
Subject: Re: PostgreSQL 9.3.5 substring(text from pattern for escape) bug
In-Reply-To: <5bb27a41-350d-37bf-901e-9d26f5592dd0@charter.net>
References: <08036370-e3d3-3a28-ab2a-da13db8be65e@charter.net> <5bb27a41-350d-37bf-901e-9d26f5592dd0@charter.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox