Re: possible bug in xpath function

Lists: pgsql-bugs
From: Andrey Kapliev <a(dot)kapliev(at)gmail(dot)com>
To: "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: possible bug in xpath function
Date: 2022-03-10 14:07:13
Message-ID: E8D6C9E4-19DD-494E-AB34-7177C33F4168@hxcore.ol
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:2.0cm 42.5pt 2.0cm 3.0cm;}
div.WordSection1
{page:WordSection1;}
--></style></head><body lang=RU link=blue vlink="#954F72" style='word-wrap:break-word'><div class=WordSection1><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><span lang=EN-US>Hi, </span><o:p></o:p></p><p class=MsoNormal><span lang=EN-US>Issue is described here </span><o:p></o:p></p><p class=MsoNormal><span lang=EN-US>https://stackoverflow.com/questions/71408524/get-list-of-nodenames-in-postgresql-xpath</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-US>&nbsp;</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-US>version:</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-US>&quot;PostgreSQL 14.1, compiled by Visual C++ build 1914, 64-bit&quot;</span><o:p></o:p></p><p class=MsoNormal>&nbsp;<o:p></o:p></p><p class=MsoNormal><span lang=EN-US>Request</span><o:p></o:p></p><p class=MsoNormal>&nbsp;<o:p></o:p></p><p class=MsoNormal><span lang=EN-US>SELECT xpath('name()', '&lt;name1&gt;&lt;name2&gt;test1&lt;/name2&gt;&lt;name3&gt;test2&lt;/name3&gt;&lt;/name1&gt;')::varchar;</span><o:p></o:p></p><p class=MsoNormal>&nbsp;<o:p></o:p></p><p class=MsoNormal><span lang=EN-US>returns an empty list, &nbsp;but is expected to return name of the element (as it does in 9.6 version).</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-US>&nbsp;</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-US>Same result occurs while calling</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-US>&nbsp;</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-US>SELECT xpath('name()', unnest(xpath('//*', '&lt;foo&gt;&lt;bar&gt;test&lt;/bar&gt;&lt;zar&gt;test1&lt;/zar&gt;&lt;/foo&gt;')));</span><o:p></o:p></p><p class=MsoNormal>&nbsp;<o:p></o:p></p><p class=MsoNormal><span lang=EN-US>It returns empty list.</span><o:p></o:p></p><p class=MsoNormal>&nbsp;<o:p></o:p></p><p class=MsoNormal><span lang=EN-US>Meanwhile request</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-US>&nbsp;</span><o:p></o:p></p><p class=MsoNormal>SELECT * FROM <o:p></o:p></p><p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XMLTABLE('//*' PASSING '&lt;foo&gt;&lt;bar&gt;test&lt;/bar&gt;&lt;zar&gt;test1&lt;/zar&gt;&lt;/foo&gt;'<o:p></o:p></p><p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; COLUMNS<o:p></o:p></p><p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name varchar PATH 'name()');<o:p></o:p></p><p class=MsoNormal>&nbsp;<o:p></o:p></p><p class=MsoNormal><span lang=EN-US>rightfully returns list of element names.</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-US>&nbsp;</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-US>It looks like XPATH name() function called from xpath() PostgreSQL function behave differently than when called from XMLTABLE() PATH</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-US>This behavior is different from that of 9.6 version where xpath correctly returns names of the nodes.</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-US>Same issue refers to local-name(), namespace-uri() &nbsp;XPath functions.</span><o:p></o:p></p><p class=MsoNormal>&nbsp;<o:p></o:p></p><p class=MsoNormal>&nbsp;<o:p></o:p></p><p class=MsoNormal><span lang=EN-US>Best regards,</span><o:p></o:p></p><p class=MsoNormal><span lang=EN-US>Andrey Kapliev</span><o:p></o:p></p><p class=MsoNormal>&nbsp;<o:p></o:p></p><p class=MsoNormal><o:p>&nbsp;</o:p></p></div></body></html>

Attachment Content-Type Size
unknown_filename text/html 4.6 KB

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andrey Kapliev <a(dot)kapliev(at)gmail(dot)com>
Cc: "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: possible bug in xpath function
Date: 2022-03-11 15:53:15
Message-ID: 877002.1647013995@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Andrey Kapliev <a(dot)kapliev(at)gmail(dot)com> writes:
> It looks like XPATH name() function called from xpath() PostgreSQL
> function behave differently than when called from XMLTABLE()
> PATH.

Your examples are by no means equivalent: in particular the XMLTABLE
example is using an absolute path //* while the xpath example
is implicitly using a relative path.

> This
> behavior is different from that of 9.6 version where xpath correctly
> returns names of the nodes.

I think this was an intentional change in v11. The 11.0 release
notes mention

* Correctly handle relative path expressions in xmltable(), xpath(), and
other XML-handling functions (Markus Winand)

Per the SQL standard, relative paths start from the document node of
the XML input document, not the root node as these functions
previously did.

regards, tom lane


From: Andrey Kapliev <a(dot)kapliev(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: possible bug in xpath function
Date: 2022-03-11 16:09:16
Message-ID: AM8PR04MB7380CC16C61DA2E9BC742FEBA70C9@AM8PR04MB7380.eurprd04.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Hi, I did not mensioned it but there is no difference in behavoir with relative and absolute paths. It throws error - invalid XPath statement in any case when I'm trying to use any of name(), local-name(), namespace-uri() functionse irrelative of path stated

Best regards,
Andrey

Get Outlook for Android<https://aka.ms/AAb9ysg>
________________________________
From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Sent: Friday, March 11, 2022 6:53:15 PM
To: Andrey Kapliev <a(dot)kapliev(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: possible bug in xpath function

Andrey Kapliev <a(dot)kapliev(at)gmail(dot)com> writes:
> It looks like XPATH name() function called from xpath() PostgreSQL
> function behave differently than when called from XMLTABLE()
> PATH.

Your examples are by no means equivalent: in particular the XMLTABLE
example is using an absolute path //* while the xpath example
is implicitly using a relative path.

> This
> behavior is different from that of 9.6 version where xpath correctly
> returns names of the nodes.

I think this was an intentional change in v11. The 11.0 release
notes mention

* Correctly handle relative path expressions in xmltable(), xpath(), and
other XML-handling functions (Markus Winand)

Per the SQL standard, relative paths start from the document node of
the XML input document, not the root node as these functions
previously did.

regards, tom lane