BUG #15908: Xpath operations fail

Поиск
Список
Период
Сортировка
Искать

BUG #15908: Xpath operations fail

От:
PG Bug reporting form <noreply@postgresql.org>
Дата:
The following bug has been logged on the website:

Bug reference:      15908
Logged by:          Rick Vincent
Email address:      rvincent@temenos.com
PostgreSQL version: 10.9
Operating system:   Windows
Description:        

Hi,

We are using xpath with PostreSQL version 10.9 and have run into a variety
of problems.  The following script highlights the bugs, the most important
of which is that it seems xpath operators >=, >, <=, < are not working
correctly.

DROP TABLE test CASCADE;

CREATE TABLE test
(
    recid integer NOT NULL,
    xmlrecord xml NOT NULL,
    CONSTRAINT test_pkey PRIMARY KEY (recid)
);

insert into test(recid, xmlrecord) 
values(1, XMLPARSE (DOCUMENT 'Manual12'));
insert into test(recid, xmlrecord) 
values(2, XMLPARSE (DOCUMENT 'Apropos12'));
insert into test(recid, xmlrecord) 
values(3, XMLPARSE (DOCUMENT 'Bprop13'));
insert into test(recid, xmlrecord) 
values(4, XMLPARSE (DOCUMENT 'Bprop14'));
insert into test(recid, xmlrecord) 
values(5, XMLPARSE (DOCUMENT 'Dprop1A'));
insert into test(recid, xmlrecord) 
values(6, XMLPARSE (DOCUMENT 'Eprop1D'));
insert into test(recid, xmlrecord) 
values(7, XMLPARSE (DOCUMENT 'Fprop1test'));

-- Correct
SELECT xpath('/row/c1', xmlrecord) as c1, xpath('/row/c2[@m=2 or not(@m)]',
t.xmlrecord) as row, xpath('/row/c2[@m=2 or not(@m)]/text() =
''2''',t.xmlrecord) VAL FROM test t;

--Incorrect, ASCII 'A', 'D', and 'test' > ASCII '2' or UT8 values as well.
SELECT xpath('/row/c1', xmlrecord) as c1, xpath('/row/c2[@m=2 or not(@m)]',
t.xmlrecord) as row, xpath('/row/c2[@m=2 or not(@m)]/text() >=
''2''',t.xmlrecord) VAL FROM test t;
-- {Manual}  | {1,"2"}    | {true}
-- {Apropos} | {1,"2"}    | {true}
-- {Apropos} | {1,"3"}    | {true}
-- {Apropos} | {1,"A"}    | {false}
-- {Apropos} | {1,"D"}    | {false}
-- {Apropos} | {1,"test"} | {false}

--Correct 
SELECT xpath('/row/c1', xmlrecord) as c1, xpath('/row/c2/text()',
t.xmlrecord) as c2, xpath('/row/c2/text() = ''A''',t.xmlrecord) VAL FROM
test t WHERE cast(xpath('/row/c2/text() = ''A''',t.xmlrecord) as VARCHAR) =
'{true}';
-- {Dprop} | {1,A} | {true}
SELECT xpath('/row/c1', xmlrecord) as c1, xpath('/row/c2', t.xmlrecord) as
c2, xpath('/row/c2[@m="2"]/text() = ''A''',t.xmlrecord) VAL FROM test t;

--Incorrect, no rows selected or returns false for all rows.
SELECT xpath('/row/c1', xmlrecord) as c1, xpath('/row/c2/text()',
t.xmlrecord) as c2, xpath('/row/c2/text() >= ''A''',t.xmlrecord) VAL FROM
test t WHERE cast(xpath('/row/c2/text() >= ''A''',t.xmlrecord) as VARCHAR) =
'{true}';
SELECT xpath('/row/c1', xmlrecord) as c1, xpath('/row/c2', t.xmlrecord) as
c2, xpath('/row/c2[@m=2]/text() >= ''A''',t.xmlrecord) VAL FROM test t;
SELECT xpath('/row/c1', xmlrecord) as c1, xpath('/row/c2', t.xmlrecord) as
c2, xpath('/row/c2[@m=2]/text() >= A',t.xmlrecord) VAL FROM test t;
SELECT xpath('/row/c1', xmlrecord) as c1, xpath('/row/c2', t.xmlrecord) as
c2, xpath('/row/c2[@m="2"]/text() >= ''A''',t.xmlrecord) VAL FROM test t;
-- same as above query but xmlexists returns always true
SELECT xpath('/row/c1', xmlrecord) as c1, xpath('/row/c2', t.xmlrecord) as
c2, xpath('/row/c2[@m="2"]/text() = ''A''',t.xmlrecord) VAL,
xmlexists('/row/c2[@m="2"]/text() = ''A''' PASSING t.xmlrecord) xmlex FROM
test t;

Re: BUG #15908: Xpath operations fail

От:
Daniel Gustafsson <daniel@yesql.se>
Дата:
> On 16 Jul 2019, at 13:55, PG Bug reporting form  wrote:

> --Incorrect, ASCII 'A', 'D', and 'test' > ASCII '2' or UT8 values as well.
> SELECT xpath('/row/c1', xmlrecord) as c1, xpath('/row/c2[@m=2 or not(@m)]',
> t.xmlrecord) as row, xpath('/row/c2[@m=2 or not(@m)]/text() >=
> ''2''',t.xmlrecord) VAL FROM test t;
> -- {Manual}  | {1,"2"}    | {true}
> -- {Apropos} | {1,"2"}    | {true}
> -- {Apropos} | {1,"3"}    | {true}
> -- {Apropos} | {1,"A"}    | {false}
> -- {Apropos} | {1,"D"}    | {false}
> -- {Apropos} | {1,"test"} | {false}

Far from being an exprt in this area, but AFAIK xpath() is evaluated as XPath
1.0 and according to the specification [1] only = and != comparison are defined:

   "When neither object to be compared is a node-set and the operator is <=, <,
    >= or >, then the objects are compared by converting both objects to
    numbers and comparing the numbers according to IEEE 754."

‘A', 'D' and ‘test’ are thus converted to floating point NaN’s.

cheers ./daniel

[1] https://www.w3.org/TR/1999/REC-xpath-19991116/#booleans

Re: BUG #15908: Xpath operations fail

От:
Daniel Gustafsson <daniel@yesql.se>
Дата:
> On 18 Jul 2019, at 11:48, Rick Vincent  wrote:

> Thanks.  It explains why ends-with doesn't work either.  I don't suppose XPath 2.0 version is supported or will be supported?

I haven’t heard of anyone working on that, and it seems unlikely to happen
within the near future as few, if any, libraries support XPath 2.0 (or later).

cheers ./daniel

RE: BUG #15908: Xpath operations fail

От:
Rick Vincent <rvincent@temenos.com>
Дата:
Hi Daniel,

Thanks for your reply.  I believe all of the major database vendors support it as we implement them all (Oracle, DB2, SQLServer)...or at least their operators >,>=, etc work with XMLExists and do text compares and don't convert any text to decimal.  Do you have an answer why XMLExists always seems to be returning true, ie. the last query I sent?

T24=# SELECT xpath('/row/c1', xmlrecord) as c1, xpath('/row/c2', t.xmlrecord) as c2, xpath('/row/c2[@m="2"]/text() = ''A''',t.xmlrecord) VAL, xmlexists('/row/c2[@m="2"]/text() = ''A''' PASSING t.xmlrecord) xmlex FROM test t;
         c1         |                  c2                  |   val   | xmlex
--------------------+--------------------------------------+---------+-------
 {Manual}  | {1,"2"}    | {false} | t
 {Apropos} | {1,"2"}    | {false} | t
 {Bprop}   | {1,"3"}    | {false} | t
 {Bprop}   | {1,"4"}    | {false} | t
 {Dprop}   | {1,"A"}    | {true}  | t
 {Eprop}   | {1,"D"}    | {false} | t
 {Fprop}   | {1,"test"} | {false} | t
(7 rows)

Big thanks,
Rick
-----Original Message-----
From: Daniel Gustafsson 
Sent: Thursday, July 18, 2019 3:06 PM
To: Rick Vincent 
Cc: Herve Aubert ; PostgreSQL mailing lists 
Subject: Re: BUG #15908: Xpath operations fail

> On 18 Jul 2019, at 11:48, Rick Vincent  wrote:

> Thanks.  It explains why ends-with doesn't work either.  I don't suppose XPath 2.0 version is supported or will be supported?

I haven’t heard of anyone working on that, and it seems unlikely to happen within the near future as few, if any, libraries support XPath 2.0 (or later).

cheers ./daniel

The information in this e-mail and any attachments is confidential and may be legally privileged. It is intended solely for the addressee or addressees. Any use or disclosure of the contents of this e-mail/attachments by a not intended recipient is unauthorized and may be unlawful. If you have received this e-mail in error please notify the sender. Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of TEMENOS. We recommend that you check this e-mail and any attachments against viruses. TEMENOS accepts no liability for any damage caused by any malicious code or virus transmitted by this e-mail.

Re: BUG #15908: Xpath operations fail

От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
Hi

čt 18. 7. 2019 v 15:06 odesílatel Daniel Gustafsson <daniel@yesql.se> napsal:
> On 18 Jul 2019, at 11:48, Rick Vincent <rvincent@temenos.com> wrote:

> Thanks.  It explains why ends-with doesn't work either.  I don't suppose XPath 2.0 version is supported or will be supported?

I haven’t heard of anyone working on that, and it seems unlikely to happen
within the near future as few, if any, libraries support XPath 2.0 (or later).

Only XPath 1.0 is supported by libxml2. And this library is in permanent feature freeze mode :-(. Unfortunately, there is not any other library with friendly licence available for C language.

Regards

Pavel 

cheers ./daniel

Re: BUG #15908: Xpath operations fail

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Pavel Stehule  writes:
> čt 18. 7. 2019 v 15:06 odesílatel Daniel Gustafsson 
> napsal:
>> I haven’t heard of anyone working on that, and it seems unlikely to happen
>> within the near future as few, if any, libraries support XPath 2.0 (or
>> later).

> Only XPath 1.0 is supported by libxml2. And this library is in permanent
> feature freeze mode :-(. Unfortunately, there is not any other library with
> friendly licence available for C language.

Not only that, but libxml2 is a rich source of security bugs.  I wish
we could get rid of that dependency altogether.  Unfortunately,
reimplementing our own xml and xpath functionality from scratch
seems like a large project :-(.  I don't think there's anybody
with sufficient time and interest to do it.

			regards, tom lane


Re: BUG #15908: Xpath operations fail

От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:


čt 18. 7. 2019 v 16:22 odesílatel Tom Lane <tgl@sss.pgh.pa.us> napsal:
Pavel Stehule <pavel.stehule@gmail.com> writes:
> čt 18. 7. 2019 v 15:06 odesílatel Daniel Gustafsson <daniel@yesql.se>
> napsal:
>> I haven’t heard of anyone working on that, and it seems unlikely to happen
>> within the near future as few, if any, libraries support XPath 2.0 (or
>> later).

> Only XPath 1.0 is supported by libxml2. And this library is in permanent
> feature freeze mode :-(. Unfortunately, there is not any other library with
> friendly licence available for C language.

Not only that, but libxml2 is a rich source of security bugs.  I wish
we could get rid of that dependency altogether.  Unfortunately,
reimplementing our own xml and xpath functionality from scratch
seems like a large project :-(.  I don't think there's anybody
with sufficient time and interest to do it.

Maybe some C++ or Java library with good licence can be ported to C for usage in Postgres.

But it is lot of work.

Pavel

                        regards, tom lane

RE: BUG #15908: Xpath operations fail

От:
Rick Vincent <rvincent@temenos.com>
Дата:

Hi all,

 

Thank you for your responses.

 

Best,

Rick

 

From: Pavel Stehule <pavel.stehule@gmail.com>
Sent: Thursday, July 18, 2019 4:27 PM
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Daniel Gustafsson <daniel@yesql.se>; Rick Vincent <rvincent@temenos.com>; Herve Aubert <haubert@temenos.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #15908: Xpath operations fail

 

 

 

čt 18. 7. 2019 v 16:22 odesílatel Tom Lane <tgl@sss.pgh.pa.us> napsal:

Pavel Stehule <pavel.stehule@gmail.com> writes:
> čt 18. 7. 2019 v 15:06 odesílatel Daniel Gustafsson <daniel@yesql.se>
> napsal:
>> I haven’t heard of anyone working on that, and it seems unlikely to happen
>> within the near future as few, if any, libraries support XPath 2.0 (or
>> later).

> Only XPath 1.0 is supported by libxml2. And this library is in permanent
> feature freeze mode :-(. Unfortunately, there is not any other library with
> friendly licence available for C language.

Not only that, but libxml2 is a rich source of security bugs.  I wish
we could get rid of that dependency altogether.  Unfortunately,
reimplementing our own xml and xpath functionality from scratch
seems like a large project :-(.  I don't think there's anybody
with sufficient time and interest to do it.

 

Maybe some C++ or Java library with good licence can be ported to C for usage in Postgres.

 

But it is lot of work.

 

Pavel


                        regards, tom lane


The information in this e-mail and any attachments is confidential and may be legally privileged. It is intended solely for the addressee or addressees. Any use or disclosure of the contents of this e-mail/attachments by a not intended recipient is unauthorized and may be unlawful. If you have received this e-mail in error please notify the sender. Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of TEMENOS. We recommend that you check this e-mail and any attachments against viruses. TEMENOS accepts no liability for any damage caused by any malicious code or virus transmitted by this e-mail.
FAQ