xpath differences between postgres 11.4 and 10.3

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

xpath differences between postgres 11.4 and 10.3

Felipe de Jesús Molina Bravo-2
Hi!!


I have an strange behavior between 11.4 and 10.3 with xpath function:

With pgsql 10.3 i have:
  select  xpath('@idc', '<p idc="4776" rc="Cuadro" idrg="5"/>' ) ;
  xpath  
  --------
  {4776}
  (1 fila)

and with pgsql 11.4:
  select  xpath('@idc', '<p idc="4776" rc="Cuadro" idrg="5"/>'::xml ) ;
   xpath
  -------
   {}
  (1 fila)

Now, if change the expression with "//":
select  xpath('//@idc', '<p idc="4776" rc="Cuadro" idrg="5"/>'::xml ) ;
 xpath  
--------
 {4776}
(1 fila)

In release notes for postgresql 11 say:

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

Despite this note I do not undertand why it behaves differently ... or maybe I do not understand the note well ... what do you think?

thanks in advance!

regards!

Reply | Threaded
Open this post in threaded view
|

xpath differences between postgres 11.4 and 10.3

David G Johnston
On Friday, July 5, 2019, Felipe de Jesús Molina Bravo <[hidden email]> wrote:
<p idc="4776" rc="Cuadro" idrg="5"/>'
  
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.

The absolute path to the 4776 in the document is:

/p::attribute[id]

In v10 relative pathing looks like (root element node):

/p<you-are-here>::attribute[id]

In v11 relative pathing looks like (document root node):

/<you-are-here>p::attribute[id]

You either need to specify your root element name in your xpath expression or, less precisely, use // to look for the attribute anywhere

David J.

Reply | Threaded
Open this post in threaded view
|

Re: xpath differences between postgres 11.4 and 10.3

Felipe de Jesús Molina Bravo-2
ok David I get it! now i undestand the note!!

very grateful with your answer

See you!!



El sáb., 6 jul. 2019 a las 2:29, David G. Johnston (<[hidden email]>) escribió:
On Friday, July 5, 2019, Felipe de Jesús Molina Bravo <[hidden email]> wrote:
<p idc="4776" rc="Cuadro" idrg="5"/>'
  
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.

The absolute path to the 4776 in the document is:

/p::attribute[id]

In v10 relative pathing looks like (root element node):

/p<you-are-here>::attribute[id]

In v11 relative pathing looks like (document root node):

/<you-are-here>p::attribute[id]

You either need to specify your root element name in your xpath expression or, less precisely, use // to look for the attribute anywhere

David J.