pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #15908: Xpath operations fail
8+ messages / 5 participants
[nested] [flat]

* BUG #15908: Xpath operations fail
@ 2019-07-16 11:55  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 8+ messages in thread

From: PG Bug reporting form @ 2019-07-16 11:55 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: rvincent@temenos.com

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 '<?xml
version="1.0"?><row><c1>Manual</c1><c2>1</c2><c2 m="2">2</c2></row>'));
insert into test(recid, xmlrecord) 
values(2, XMLPARSE (DOCUMENT '<?xml
version="1.0"?><row><c1>Apropos</c1><c2>1</c2><c2 m="2">2</c2></row>'));
insert into test(recid, xmlrecord) 
values(3, XMLPARSE (DOCUMENT '<?xml
version="1.0"?><row><c1>Bprop</c1><c2>1</c2><c2 m="2">3</c2></row>'));
insert into test(recid, xmlrecord) 
values(4, XMLPARSE (DOCUMENT '<?xml
version="1.0"?><row><c1>Bprop</c1><c2>1</c2><c2 m="2">4</c2></row>'));
insert into test(recid, xmlrecord) 
values(5, XMLPARSE (DOCUMENT '<?xml
version="1.0"?><row><c1>Dprop</c1><c2>1</c2><c2 m="2">A</c2></row>'));
insert into test(recid, xmlrecord) 
values(6, XMLPARSE (DOCUMENT '<?xml
version="1.0"?><row><c1>Eprop</c1><c2>1</c2><c2 m="2">D</c2></row>'));
insert into test(recid, xmlrecord) 
values(7, XMLPARSE (DOCUMENT '<?xml
version="1.0"?><row><c1>Fprop</c1><c2>1</c2><c2 m="2">test</c2></row>'));

-- 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;
-- {<c1>Manual</c1>}  | {<c2>1</c2>,"<c2 m=\"2\">2</c2>"}    | {true}
-- {<c1>Apropos</c1>} | {<c2>1</c2>,"<c2 m=\"2\">2</c2>"}    | {true}
-- {<c1>Apropos</c1>} | {<c2>1</c2>,"<c2 m=\"2\">3</c2>"}    | {true}
-- {<c1>Apropos</c1>} | {<c2>1</c2>,"<c2 m=\"2\">A</c2>"}    | {false}
-- {<c1>Apropos</c1>} | {<c2>1</c2>,"<c2 m=\"2\">D</c2>"}    | {false}
-- {<c1>Apropos</c1>} | {<c2>1</c2>,"<c2 m=\"2\">test</c2>"} | {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}';
-- {<c1>Dprop</c1>} | {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;



^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #15908: Xpath operations fail
@ 2019-07-17 15:40  Daniel Gustafsson <daniel@yesql.se>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 8+ messages in thread

From: Daniel Gustafsson @ 2019-07-17 15:40 UTC (permalink / raw)
  To: rvincent@temenos.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

> On 16 Jul 2019, at 13:55, PG Bug reporting form <noreply@postgresql.org> 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;
> -- {<c1>Manual</c1>}  | {<c2>1</c2>,"<c2 m=\"2\">2</c2>"}    | {true}
> -- {<c1>Apropos</c1>} | {<c2>1</c2>,"<c2 m=\"2\">2</c2>"}    | {true}
> -- {<c1>Apropos</c1>} | {<c2>1</c2>,"<c2 m=\"2\">3</c2>"}    | {true}
> -- {<c1>Apropos</c1>} | {<c2>1</c2>,"<c2 m=\"2\">A</c2>"}    | {false}
> -- {<c1>Apropos</c1>} | {<c2>1</c2>,"<c2 m=\"2\">D</c2>"}    | {false}
> -- {<c1>Apropos</c1>} | {<c2>1</c2>,"<c2 m=\"2\">test</c2>"} | {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




^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #15908: Xpath operations fail
@ 2019-07-18 13:06  Daniel Gustafsson <daniel@yesql.se>
  parent: Daniel Gustafsson <daniel@yesql.se>
  0 siblings, 2 replies; 8+ messages in thread

From: Daniel Gustafsson @ 2019-07-18 13:06 UTC (permalink / raw)
  To: Rick Vincent <rvincent@temenos.com>; +Cc: Herve Aubert <haubert@temenos.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

> 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).

cheers ./daniel




^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* RE: BUG #15908: Xpath operations fail
@ 2019-07-18 13:46  Rick Vincent <rvincent@temenos.com>
  parent: Daniel Gustafsson <daniel@yesql.se>
  1 sibling, 0 replies; 8+ messages in thread

From: Rick Vincent @ 2019-07-18 13:46 UTC (permalink / raw)
  To: Daniel Gustafsson <daniel@yesql.se>; +Cc: Herve Aubert <haubert@temenos.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

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
--------------------+--------------------------------------+---------+-------
 {<c1>Manual</c1>}  | {<c2>1</c2>,"<c2 m=\"2\">2</c2>"}    | {false} | t
 {<c1>Apropos</c1>} | {<c2>1</c2>,"<c2 m=\"2\">2</c2>"}    | {false} | t
 {<c1>Bprop</c1>}   | {<c2>1</c2>,"<c2 m=\"2\">3</c2>"}    | {false} | t
 {<c1>Bprop</c1>}   | {<c2>1</c2>,"<c2 m=\"2\">4</c2>"}    | {false} | t
 {<c1>Dprop</c1>}   | {<c2>1</c2>,"<c2 m=\"2\">A</c2>"}    | {true}  | t
 {<c1>Eprop</c1>}   | {<c2>1</c2>,"<c2 m=\"2\">D</c2>"}    | {false} | t
 {<c1>Fprop</c1>}   | {<c2>1</c2>,"<c2 m=\"2\">test</c2>"} | {false} | t
(7 rows)

Big thanks,
Rick
-----Original Message-----
From: Daniel Gustafsson <daniel@yesql.se>
Sent: Thursday, July 18, 2019 3:06 PM
To: Rick Vincent <rvincent@temenos.com>
Cc: Herve Aubert <haubert@temenos.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #15908: Xpath operations fail

> 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).

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.


^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #15908: Xpath operations fail
@ 2019-07-18 14:15  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Daniel Gustafsson <daniel@yesql.se>
  1 sibling, 1 reply; 8+ messages in thread

From: Pavel Stehule @ 2019-07-18 14:15 UTC (permalink / raw)
  To: Daniel Gustafsson <daniel@yesql.se>; +Cc: Rick Vincent <rvincent@temenos.com>; Herve Aubert <haubert@temenos.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

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
>
>

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #15908: Xpath operations fail
@ 2019-07-18 14:22  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Tom Lane @ 2019-07-18 14:22 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: Daniel Gustafsson <daniel@yesql.se>; Rick Vincent <rvincent@temenos.com>; Herve Aubert <haubert@temenos.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

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.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: BUG #15908: Xpath operations fail
@ 2019-07-18 14:27  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 8+ messages in thread

From: Pavel Stehule @ 2019-07-18 14:27 UTC (permalink / raw)
  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>

č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
>

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* RE: BUG #15908: Xpath operations fail
@ 2019-07-19 08:20  Rick Vincent <rvincent@temenos.com>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 0 replies; 8+ messages in thread

From: Rick Vincent @ 2019-07-19 08:20 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Daniel Gustafsson <daniel@yesql.se>; Herve Aubert <haubert@temenos.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

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<mailto:tgl@sss.pgh.pa.us>> napsal:
Pavel Stehule <pavel.stehule@gmail.com<mailto:pavel.stehule@gmail.com>> writes:
> čt 18. 7. 2019 v 15:06 odesílatel Daniel Gustafsson <daniel@yesql.se<mailto: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.


^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2019-07-19 08:20 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-07-16 11:55 BUG #15908: Xpath operations fail PG Bug reporting form <noreply@postgresql.org>
2019-07-17 15:40 ` Daniel Gustafsson <daniel@yesql.se>
2019-07-18 13:06   ` Daniel Gustafsson <daniel@yesql.se>
2019-07-18 13:46     ` Rick Vincent <rvincent@temenos.com>
2019-07-18 14:15     ` Pavel Stehule <pavel.stehule@gmail.com>
2019-07-18 14:22       ` Tom Lane <tgl@sss.pgh.pa.us>
2019-07-18 14:27         ` Pavel Stehule <pavel.stehule@gmail.com>
2019-07-19 08:20           ` Rick Vincent <rvincent@temenos.com>

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